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

View file

@ -0,0 +1,3 @@
main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}

View file

@ -1,4 +1,4 @@
domain=. |.@|:@({.@[ + ] *~ j./&i.&>/@+.@(1j1 + ] %~ -~/@[))&>/
load'graph'
load 'viewmat'
viewmat mcf "0 @ domain (_2j_1 1j1) ; 0.01 NB. Complex interval and resolution

View file

@ -0,0 +1 @@
ImageTools:-Embed(Fractals[EscapeTime]:-Mandelbrot(500, -2.0-1.35*I, .7+1.35*I, output = layer1));

View file

@ -0,0 +1,44 @@
prologues:=3;
outputtemplate:="%j-%c.svg";
outputformat:="svg";
def mandelbrot(expr maxX, maxY) =
max_iteration := 500;
color col[];
for i := 0 upto max_iteration:
t := i / max_iteration;
col[i] = (t,t,t);
endfor;
for px := 0 upto maxX:
for py := 0 upto maxY:
xz := px * 3.5 / maxX - 2.5; % (-2.5,1)
yz := py * 2 / maxY - 1; % (-1,1)
x := 0;
y := 0;
iteration := 0;
forever: exitunless ((x*x + y*y < 4) and (iteration < max_iteration));
xtemp := x*x - y*y + xz;
y := 2*x*y + yz;
x := xtemp;
iteration := iteration + 1;
endfor;
draw (px,py) withpen pencircle withcolor col[iteration];
endfor;
endfor;
enddef;
beginfig(1);
mandelbrot(200, 150);
endfig;
end

View file

@ -0,0 +1 @@
mpost -numbersystem="double" mandelbrot.mp

View file

@ -0,0 +1,64 @@
// Following code is a zoomable Mandelbrot.
// Of course, you want to click on an interesting area
// with contrast and more colors to zoom in.
double x, y, zr, zi, zr2, zi2, cr, ci, n;
double zmx1, zmx2, zmy1, zmy2, f, di, dj;
double fn1, fn2, fn3, re, gr, bl, xt, yt, i, j;
void setup() {
size(500, 500);
di = 0;
dj = 0;
f = 10;
fn1 = random(20);
fn2 = random(20);
fn3 = random(20);
zmx1 = int(width / 4);
zmx2 = 2;
zmy1 = int(height / 4);
zmy2 = 2;
}
void draw() {
if (i <= width) i++;
x = (i + di)/ zmx1 - zmx2;
for ( j = 0; j <= height; j++) {
y = zmy2 - (j + dj) / zmy1;
zr = 0;
zi = 0;
zr2 = 0;
zi2 = 0;
cr = x;
ci = y;
n = 1;
while (n < 200 && (zr2 + zi2) < 4) {
zi2 = zi * zi;
zr2 = zr * zr;
zi = 2 * zi * zr + ci;
zr = zr2 - zi2 + cr;
n++;
}
re = (n * fn1) % 255;
gr = (n * fn2) % 255;
bl = (n * fn3) % 255;
stroke((float)re, (float)gr, (float)bl);
point((float)i, (float)j);
}
}
void mousePressed() {
background(200);
xt = mouseX;
yt = mouseY;
di = di + xt - float(width / 2);
dj = dj + yt - float(height / 2);
zmx1 = zmx1 * f;
zmx2 = zmx2 * (1 / f);
zmy1 = zmy1 * f;
zmy2 = zmy2 * (1 / f);
di = di * f;
dj = dj * f;
i = 0;
j = 0;
}

View file

@ -3,7 +3,7 @@ load "guilib.ring"
new qapp
{
win1 = new qwidget() {
setwindowtitle("drawing using qpainter")
setwindowtitle("Mandelbrot set")
setgeometry(100,100,500,500)
label1 = new qlabel(win1) {
setgeometry(10,10,400,400)

View file

@ -0,0 +1,43 @@
extern crate image;
extern crate num_complex;
use std::fs::File;
use num_complex::Complex;
fn main() {
let max_iterations = 256u16;
let img_side = 800u32;
let cxmin = -2f32;
let cxmax = 1f32;
let cymin = -1.5f32;
let cymax = 1.5f32;
let scalex = (cxmax - cxmin) / img_side as f32;
let scaley = (cymax - cymin) / img_side as f32;
// Create a new ImgBuf
let mut imgbuf = image::ImageBuffer::new(img_side, img_side);
// Calculate for each pixel
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
let cx = cxmin + x as f32 * scalex;
let cy = cymin + y as f32 * scaley;
let c = Complex::new(cx, cy);
let mut z = Complex::new(0f32, 0f32);
let mut i = 0;
for t in 0..max_iterations {
if z.norm() > 2.0 {
break;
}
z = z * z + c;
i = t;
}
*pixel = image::Luma([i as u8]);
}
// Save image
let fout = &mut File::create("fractal.png").unwrap();
image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();
}