Jump to content

Sunflower fractal: Difference between revisions

Added solution for Action!
m (→‎{{header|Phix}}: added syntax colouring and run online link)
(Added solution for Action!)
Line 24:
 
print(‘</svg>’)</lang>
 
=={{header|Action!}}==
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<lang Action!>INCLUDE "H6:REALMATH.ACT"
 
INT ARRAY SinTab=[
0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
147 150 154 158 161 165 168 171 175 178 181 184 187 190
193 196 199 202 204 207 210 212 215 217 219 222 224 226
228 230 232 234 236 237 239 241 242 243 245 246 247 248
249 250 251 252 253 254 254 255 255 255 256 256 256 256]
 
INT FUNC Sin(INT a)
WHILE a<0 DO a==+360 OD
WHILE a>360 DO a==-360 OD
IF a<=90 THEN
RETURN (SinTab(a))
ELSEIF a<=180 THEN
RETURN (SinTab(180-a))
ELSEIF a<=270 THEN
RETURN (-SinTab(a-180))
ELSE
RETURN (-SinTab(360-a))
FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC Circle(INT x0,y0,d)
BYTE MaxD=[13]
BYTE ARRAY Start=[0 1 2 4 6 9 12 16 20 25 30 36 42 49]
BYTE ARRAY MaxY=[0 0 1 1 2 2 3 3 4 4 5 5 6 6]
INT ARRAY CircleX=[
0 0 1 0 1 1 2 1 0 2 2 1 3 2 2 0 3 3 2 1
4 4 3 2 1 4 4 4 3 2 5 5 4 4 3 1 5 5 5 4 4 2
6 6 5 5 4 3 1 6 6 6 5 5 4 2]
 
INT i,ind,max
CARD x
BYTE dx,y
 
IF d>MAXD THEN d=MaxD FI
IF d<0 THEN d=0 FI
 
ind=Start(d)
max=MaxY(d)
FOR i=0 TO max
DO
dx=CircleX(ind)
y=y0-i
IF (y>=0) AND (y<=191) THEN
Plot(x0-dx,y) DrawTo(x0+dx,y)
FI
y=y0+i
IF (y>=0) AND (y<=191) THEN
Plot(x0-dx,y) DrawTo(x0+dx,y)
FI
ind==+1
OD
RETURN
 
PROC DrawFractal(CARD seeds INT x0,y0)
CARD i
REAL a,c,r,ir,tmp,tmp2,r256,rx,ry,rr,r360,c360,seeds2
INT ia,sc,x,y
 
IntToReal(256,r256)
ValR("1.618034",c) ;c=(sqrt(5)+1)/2
IntToReal(seeds/2,seeds2) ;seeds2=seeds/2
IntToReal(360,r360)
RealMult(r360,c,c360) ;c360=360*c
 
FOR i=0 TO seeds
DO
IntToReal(i,ir)
Power(ir,c,tmp)
RealDiv(tmp,seeds2,r) ;r=i^c/(seeds/2)
RealMult(c360,ir,a) ;a=360*c*i
 
WHILE RealGreaterOrEqual(a,r360)
DO
RealSub(a,r360,tmp)
RealAssign(tmp,a)
OD
 
ia=RealToInt(a)
sc=Sin(ia)
IntToRealForNeg(sc,tmp)
RealDiv(tmp,r256,tmp2)
RealMult(r,tmp2,rx)
x=Round(rx) ;x=r*sin(a)
sc=Cos(ia)
IntToRealForNeg(sc,tmp)
RealDiv(tmp,r256,tmp2)
RealMult(r,tmp2,ry)
y=Round(ry) ;y=r*cos(a)
 
Circle(x+x0,y+y0,10*i/seeds)
 
Poke(77,0) ;turn off the attract mode
OD
RETURN
 
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
Graphics(8+16)
Color=1
COLOR1=$12
COLOR2=$18
 
DrawFractal(1000,160,96)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sunflower_fractal.png Screenshot from Atari 8-bit computer]
 
=={{header|C}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.