June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,15 @@
Function mandel(xi As Double, yi As Double)
maxiter = 256
x = 0
y = 0
For i = 1 To maxiter
If ((x * x) + (y * y)) > 4 Then Exit For
xt = xi + ((x * x) - (y * y))
y = yi + (2 * x * y)
x = xt
Next
mandel = i
End Function

View file

@ -0,0 +1,20 @@
1 REM MANDELBROT SET - TANDY COCO 3
2 POKE 65497,1
10 HSCREEN 2
20 HCLS
30 X1=319:Y1=191
40 I1=-1.0:I2=1.0:R1=-2:R2=1.0
50 S1=(R2-R1)/X1:S2=(I2-I1)/Y1
60 FOR Y=0 TO Y1
70 I3=I1+S2*Y
80 FOR X=0 TO X1
90 R3=R1+S1*X:Z1=R3:Z2=I3
100 FOR N=0 TO 30
110 A=Z1*Z1:B=Z2*Z2
120 IF A+B>4.0 GOTO 150
130 Z2=2*Z1*Z2+I3:Z1=A-B+R3
140 NEXT N
150 HSET(X,Y,N-16*INT(N/16))
160 NEXT X
170 NEXT Y
180 GOTO 180

View file

@ -2,32 +2,32 @@ fastgraphics
graphsize 384,384
refresh
kt=319 : m = 4.0
xmin=2.1 : xmax=-0.6 : ymin=-1.35 : ymax=1.35
dx=(xmax-xmin)/graphwidth : dy=(ymax-ymin)/graphheight
kt = 319 : m = 4.0
xmin = -2.1 : xmax = 0.6 : ymin = -1.35 : ymax = 1.35
dx = (xmax - xmin) / graphwidth : dy = (ymax - ymin) / graphheight
for x=0 to graphwidth
jx = xmin+x*dx
for y=0 to graphheight
jy = ymin+y*dy
for x = 0 to graphwidth
jx = xmin + x * dx
for y = 0 to graphheight
jy = ymin + y * dy
k = 0 : wx = 0.0 : wy = 0.0
do
tx = wx*wx-(wy*wy+jx)
ty = 2.0*wx*wy+jy
tx = wx * wx - wy * wy + jx
ty = 2.0 * wx * wy + jy
wx = tx
wy = ty
r = wx*wx+wy*wy
k = k+1
until r>m or k>kt
r = wx * wx + wy * wy
k = k + 1
until r > m or k > kt
if k>kt then
if k > kt then
color black
else
if k<16 then color k*8,k*8,128+k*4
if k>=16 and k<64 then color 128+k-16,128+k-16,192+k-16
if k>=64 then color kt-k,128+(kt-k)/2,kt-k
if k < 16 then color k * 8, k * 8, 128 + k * 4
if k >= 16 and k < 64 then color 128 + k - 16, 128 + k - 16, 192 + k - 16
if k >= 64 then color kt - k, 128 + (kt - k) / 2, kt - k
end if
plot x,y
plot x, y
next y
refresh
next x

View file

@ -1,85 +1,44 @@
'Mandelbrot V4 for RunBasic
'Based on LibertyBasic solution
'copy the code and go to runbasic.com
'http://rosettacode.org/wiki/Mandelbrot_set#Liberty_BASIC
'May 2015
'
WindowWidth = 320 'RunBasic max size 800 x 600
WindowHeight = 320
'print zone -2 to 1 (X)
'print zone -1.5 to 1.5 (Y)
a = -1.5 'graph -1.5 to -0.75, first "loop"
b = -0.75 'adjust for max processor time (y0 for loop below)
'open "Mandelbrot Set" for graphics_nsb_nf as #w not used in RunBasic
graphic #w, WindowWidth, WindowHeight
'#w "trapclose [quit]" not used in RunBasic
'#w "down" not used in RunBasic
cls
'#w flush()
#w cls("black")
render #w
'#w flush()
input "OK, hit enter to continue"; guess
cls
[man_calc]
'3/screen size 3/800 = 0.00375 ** 3/790 = 0.0037974
'3/screen size (y) 3/600 = .005 ** 3/590 = 0.0050847
'3/215 = .0139 .0068 = 3/440
cc = 3/299
'
for x0 = -2 to 1 step cc
for y0 = a to b step cc
x = 0
y = 0
iteration = 0
maxIteration = 255
while ( ( x *x +y *y) <=4) and ( iteration <maxIteration)
xtemp =x *x -y *y +x0
y =2 *x *y +y0
x = xtemp
iteration = iteration + 1
wend
if iteration <>maxIteration then
c =iteration
else
c =0
end if
call pSet x0, y0, c
'scan why scan? (wait for user input) with RunBasic ?
next
next
'#w flush() 'what is flush? RunBasic uses the render command.
render #w
input "OK, hit enter to continue"; guess
cls
a = a + 0.75
b = b + 0.75
if b > 1.6 then goto[quit] else goto[man_calc]
sub pSet x, y, c
xScreen = 5+(x +2) /3 * 300 'need positive screen number
yScreen = 5+(y +1.5) /3 * 300 'and 5x5 boarder
if c =0 then
col$ ="red"
else
if c mod 2 =1 then col$ ="lightgray" else col$ ="white"
end if
#w "color "; col$
#w "set "; xScreen; " "; yScreen
end sub
[quit]
cls
render #w
print "All done, good bye."
end
1000 REM Mandelbrot Set Project
1010 REM Quite BASIC Math Project
1015 REM 'http://www.quitebasic.com/prj/math/mandelbrot/
1020 REM ------------------------
1030 CLS
1040 PRINT "This program plots a graphical representation of the famous Mandelbrot set. It takes a while to finish so have patience and don't have too high expectations; the graphics resolution is not very high on our canvas."
2000 REM Initialize the color palette
2010 GOSUB 3000
2020 REM L is the maximum iterations to try
2030 LET L = 100
2040 FOR I = 0 TO 100
2050 FOR J = 0 TO 100
2060 REM Map from pixel coordinates (I,J) to math (U,V)
2060 LET U = I / 50 - 1.5
2070 LET V = J / 50 - 1
2080 LET X = U
2090 LET Y = V
2100 LET N = 0
2110 REM Inner iteration loop starts here
2120 LET R = X * X
2130 LET Q = Y * Y
2140 IF R + Q > 4 OR N >= L THEN GOTO 2190
2150 LET Y = 2 * X * Y + V
2160 LET X = R - Q + U
2170 LET N = N + 1
2180 GOTO 2120
2190 REM Compute the color to plot
2200 IF N < 10 THEN LET C = "black" ELSE LET C = P[ROUND(8 * (N-10) / (L-10))]
2210 PLOT I, J, C
2220 NEXT J
2230 NEXT I
2240 END
3000 REM Subroutine -- Set up Palette
3010 ARRAY P
3020 LET P[0] = "black"
3030 LET P[1] = "magenta"
3040 LET P[2] = "blue"
3050 LET P[3] = "green"
3060 LET P[4] = "cyan"
3070 LET P[5] = "red"
3080 LET P[6] = "orange"
3090 LET P[7] = "yellow"
3090 LET P[8] = "white"
3100 RETURN

View file

@ -1,13 +1,90 @@
10 FOR X=-2 TO 2 STEP 0.1
20 FOR Y=-2 TO 2 STEP 0.1
30 LET XA=0
40 LET YA=0
50 LET ITER=0
60 LET XTEMP=XA*XA-YA*YA+X
70 LET YA=2*XA*YA+Y
80 LET XA=XTEMP
90 LET ITER=ITER+1
100 IF XA*XA+YA*YA<=4 AND ITER<200 THEN GOTO 60
110 IF ITER<200 THEN PLOT X*10+20,Y*10+20
120 NEXT Y
130 NEXT X
'Mandelbrot V4 for RunBasic
'Based on LibertyBasic solution
'copy the code and go to runbasic.com
'http://rosettacode.org/wiki/Mandelbrot_set#Liberty_BASIC
'May 2015 (updated 29 Apr 2018)
'
'Note - we only get so much processing time on the server, so the
'graph is computed in three or four pieces
'
WindowWidth = 320 'RunBasic max size 800 x 600
WindowHeight = 320
'print zone -2 to 1 (X)
'print zone -1.5 to 1.5 (Y)
a = -1.5 'graph -1.5 to -0.75, first "loop"
b = -0.75 'adjust for max processor time (y0 for loop below)
'open "Mandelbrot Set" for graphics_nsb_nf as #w not used in RunBasic
graphic #w, WindowWidth, WindowHeight
'#w "trapclose [quit]" not used in RunBasic
'#w "down" not used in RunBasic
cls
'#w flush()
#w cls("black")
render #w
'#w flush()
input "OK, hit enter to continue"; guess
cls
[man_calc]
'3/screen size 3/800 = 0.00375 ** 3/790 = 0.0037974
'3/screen size (y) 3/600 = .005 ** 3/590 = 0.0050847
'3/215 = .0139 .0068 = 3/440
cc = 3/299
'
for x0 = -2 to 1 step cc
for y0 = a to b step cc
x = 0
y = 0
iteration = 0
maxIteration = 255
while ( ( x *x +y *y) <=4) and ( iteration <maxIteration)
xtemp =x *x -y *y +x0
y =2 *x *y +y0
x = xtemp
iteration = iteration + 1
wend
if iteration <>maxIteration then
c =iteration
else
c =0
end if
call pSet x0, y0, c
'scan why scan? (wait for user input) with RunBasic ?
next
next
'#w flush() 'what is flush? RunBasic uses the render command.
render #w
input "OK, hit enter to continue"; guess
cls
a = a + 0.75
b = b + 0.75
if b > 1.6 then goto[quit] else goto[man_calc]
sub pSet x, y, c
xScreen = 5+(x +2) /3 * 300 'need positive screen number
yScreen = 5+(y +1.5) /3 * 300 'and 5x5 boarder
if c =0 then
col$ ="red"
else
if c mod 2 =1 then col$ ="lightgray" else col$ ="white"
end if
#w "color "; col$
#w "set "; xScreen; " "; yScreen
end sub
[quit]
'cls
print
print "This is a Mandelbrot Graph output from www.runbasic.com"
render #w
print "All done, good bye."
end

View file

@ -1,29 +1,15 @@
GraphicsWindow.Show()
size = 500
half = 250
GraphicsWindow.Width = size * 1.5
GraphicsWindow.Height = size
GraphicsWindow.Title = "Mandelbrot"
For px = 1 To size * 1.5
x_0 = px/half - 2
For py = 1 To size
y_0 = py/half - 1
x = x_0
y = y_0
i = 0
While(c <= 2 AND i<100)
x_1 = Math.Power(x, 2) - Math.Power(y, 2) + x_0
y_1 = 2 * x * y + y_0
c = Math.Power(Math.Power(x_1, 2) + Math.Power(y_1, 2), 0.5)
x = x_1
y = y_1
i = i + 1
EndWhile
If i < 99 Then
GraphicsWindow.SetPixel(px, py, GraphicsWindow.GetColorFromRGB((255/25)*i, (255/25)*i, (255/5)*i))
Else
GraphicsWindow.SetPixel(px, py, "black")
EndIf
c=0
EndFor
EndFor
10 FOR I=0 TO 63
20 FOR J=43 TO 0 STEP -1
30 LET X=(I-52)/31
40 LET Y=(J-22)/31
50 LET XA=0
60 LET YA=0
70 LET ITER=0
80 LET XTEMP=XA*XA-YA*YA+X
90 LET YA=2*XA*YA+Y
100 LET XA=XTEMP
110 LET ITER=ITER+1
120 IF XA*XA+YA*YA<=4 AND ITER<200 THEN GOTO 80
130 IF ITER=200 THEN PLOT I, J
140 NEXT J
150 NEXT I

View file

@ -1,15 +1,29 @@
Function mandel(xi As Double, yi As Double)
maxiter = 256
x = 0
y = 0
For i = 1 To maxiter
If ((x * x) + (y * y)) > 4 Then Exit For
xt = xi + ((x * x) - (y * y))
y = yi + (2 * x * y)
x = xt
Next
mandel = i
End Function
GraphicsWindow.Show()
size = 500
half = 250
GraphicsWindow.Width = size * 1.5
GraphicsWindow.Height = size
GraphicsWindow.Title = "Mandelbrot"
For px = 1 To size * 1.5
x_0 = px/half - 2
For py = 1 To size
y_0 = py/half - 1
x = x_0
y = y_0
i = 0
While(c <= 2 AND i<100)
x_1 = Math.Power(x, 2) - Math.Power(y, 2) + x_0
y_1 = 2 * x * y + y_0
c = Math.Power(Math.Power(x_1, 2) + Math.Power(y_1, 2), 0.5)
x = x_1
y = y_1
i = i + 1
EndWhile
If i < 99 Then
GraphicsWindow.SetPixel(px, py, GraphicsWindow.GetColorFromRGB((255/25)*i, (255/25)*i, (255/5)*i))
Else
GraphicsWindow.SetPixel(px, py, "black")
EndIf
c=0
EndFor
EndFor