Sunflower fractal: Difference between revisions
m
→{{header|Fōrmulæ}}
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
(12 intermediate revisions by 7 users not shown) | |||
Line 240:
{{out}}
[[Media:Sunflower cpp.svg]]
=={{header|FreeBASIC}}==
Line 270:
End
</syntaxhighlight>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sunflower_model}}
'''Solution'''
The method consists in drawing points on a spriral, an archimedean spiral, where two contiguous points are separated (in angle) by the golden angle.
Because the points tend to agglomerate in the center, they are smaller there.
[[File:Fōrmulæ - Sunflower model 01.png]]
[[File:Fōrmulæ - Sunflower model 02.png]]
[[File:Fōrmulæ - Sunflower model 03.png]]
'''Improvement'''
Last result is not natural. Florets in a sunflower are all equal size.
H. Vogel proposed to use a Fermat spiral, in such a case, the florets are equally spaced, and we can use now circles with the same size:
[[File:Fōrmulæ - Sunflower model 04.png]]
[[File:Fōrmulæ - Sunflower model 05.png]]
[[File:Fōrmulæ - Sunflower model 06.png]]
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
window 1, @"Sunflower Fractal", ( 0, 0, 400, 400 )
WindowSetBackgroundColor( 1, fn ColorBlack )
void local fn SunflowerFractal
NSUinteger seeds = 4000
double c, i, angle, x, y, r
pen 2.0, fn ColorWithRGB( 0.997, 0.838, 0.038, 1.0 )
c = ( sqr(5) + 1 ) / 2
for i = 0 to seeds
r = (i ^ c) / seeds
angle = 2 * pi * c * i
x = r * sin(angle) + 200
y = r * cos(angle) + 200
oval ( x, y, i / seeds * 5, i / seeds * 5 )
next
end fn
fn SunflowerFractal
HandleEvents
</syntaxhighlight>
[[file:Sunflower_Fractal.png]]
=={{header|Go}}==
Line 454 ⟶ 509:
{{trans|R}}
Run from REPL.
<syntaxhighlight lang="julia">using
function sunflowerplot()
Line 464 ⟶ 519:
for i in 2:length(r)
θ[i] = θ[i - 1] + 2π * ϕ
markersizes[i] = div(i, 500) +
end
x = r .* cos.(θ)
y = r .* sin.(θ)
ax = Axis(f[1, 1], backgroundcolor = :green)
scatter!(
hidespines!(ax)
hidedecorations!(ax)
return f
end
sunflowerplot()
</syntaxhighlight>
{{output}}
[[File:Sunflower-julia.png|center|thumb]]
=={{header|Liberty BASIC}}==
Line 968 ⟶ 1,032:
Output image: [https://github.com/trizen/rc/blob/master/img/sunflower-sidef.png Sunflower fractal]
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import gg
import gx
import math
Line 1,003 ⟶ 1,067:
{{trans|Go}}
{{libheader|DOME}}
<syntaxhighlight lang="
import "dome" for Window
Line 1,034 ⟶ 1,098:
}
}</syntaxhighlight>
=={{header|XPL0}}==
[[File:SunflowerXPL0.gif|200px|thumb|right]]
<syntaxhighlight lang "XPL0">
proc DrawCircle(X0, Y0, R, Color);
int X0, Y0, R, Color;
int X, Y, R2;
[R2:= R*R;
for Y:= -R to +R do
for X:= -R to +R do
if X*X + Y*Y <= R2 then
Point(X+X0, Y+Y0, Color);
];
def Seeds = 3000, Color = $0E; \yellow
def ScrW = 800, ScrH = 600;
def Phi = (sqrt(5.)+1.) / 2.; \golden ratio (1.618...)
def Pi = 3.14159265358979323846;
real R, Angle, X, Y;
int I;
[SetVid($103);
for I:= 0 to Seeds-1 do
[R:= Pow(float(I), Phi) / float(Seeds/2);
Angle:= 2. * Pi * Phi * float(I);
X:= R*Sin(Angle);
Y:= R*Cos(Angle);
DrawCircle(ScrW/2+fix(X), ScrH/2-fix(Y), I*7/Seeds, Color);
];
]</syntaxhighlight>
=={{header|Yabasic}}==
|