Sunflower fractal: Difference between revisions

Content added Content deleted
No edit summary
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 4: Line 4:
<br>
<br>
<br>
<br>

=={{header|C}}==
=={{header|C}}==
The colouring of the "fractal" is determined with every iteration to ensure that the resulting graphic looks similar to a real Sunflower, thus the parameter ''diskRatio'' determines the radius of the central disk as the maximum radius of the flower is known from the number of iterations. The scaling factor is currently hardcoded but can also be externalized. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
The colouring of the "fractal" is determined with every iteration to ensure that the resulting graphic looks similar to a real Sunflower, thus the parameter ''diskRatio'' determines the radius of the central disk as the maximum radius of the flower is known from the number of iterations. The scaling factor is currently hardcoded but can also be externalized. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
Line 361: Line 362:
print "</svg>\n";</lang>
print "</svg>\n";</lang>
See [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/sunflower.svg Phi-packing image] (SVG image)
See [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/sunflower.svg Phi-packing image] (SVG image)

=={{header|Perl 6}}==
{{works with|Rakudo|2018.06}}
This is not really a fractal. It is more accurately an example of a Fibonacci spiral or Phi-packing.

Or, to be completely accurate: It is a variation of a generative [[wp:Fermat's_spiral|Fermat's spiral]] using the Vogel model to implement phi-packing. See: [https://thatsmaths.com/2014/06/05/sunflowers-and-fibonacci-models-of-efficiency/ https://thatsmaths.com/2014/06/05/sunflowers-and-fibonacci-models-of-efficiency]

<lang perl6>use SVG;

my $seeds = 3000;
my @center = 300, 300;
my $scale = 5;

constant \φ = (3 - 5.sqrt) / 2;

my @c = map {
my ($x, $y) = ($scale * .sqrt) «*« |cis($_ * φ * τ).reals »+« @center;
[ $x.round(.01), $y.round(.01), (.sqrt * $scale / 100).round(.1) ]
}, 1 .. $seeds;

say SVG.serialize(
svg => [
:600width, :600height, :style<stroke:yellow>,
:rect[:width<100%>, :height<100%>, :fill<black>],
|@c.map( { :circle[:cx(.[0]), :cy(.[1]), :r(.[2])] } ),
],
);</lang>
See: [https://github.com/thundergnat/rc/blob/master/img/phi-packing-perl6.svg Phi packing] (SVG image)


=={{header|Phix}}==
=={{header|Phix}}==
Line 453: Line 426:
end procedure
end procedure
main()</lang>
main()</lang>

=={{header|Python}}==
=={{header|Python}}==
<lang python>
<lang python>
Line 506: Line 480:
done()
done()
</lang>
</lang>

=={{header|R}}==
=={{header|R}}==
<lang R>
<lang R>
Line 551: Line 526:
(+ (/ HEIGHT 2) (* r (cos theta)))
(+ (/ HEIGHT 2) (* r (cos theta)))
image))</lang>
image))</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.06}}
This is not really a fractal. It is more accurately an example of a Fibonacci spiral or Phi-packing.

Or, to be completely accurate: It is a variation of a generative [[wp:Fermat's_spiral|Fermat's spiral]] using the Vogel model to implement phi-packing. See: [https://thatsmaths.com/2014/06/05/sunflowers-and-fibonacci-models-of-efficiency/ https://thatsmaths.com/2014/06/05/sunflowers-and-fibonacci-models-of-efficiency]

<lang perl6>use SVG;

my $seeds = 3000;
my @center = 300, 300;
my $scale = 5;

constant \φ = (3 - 5.sqrt) / 2;

my @c = map {
my ($x, $y) = ($scale * .sqrt) «*« |cis($_ * φ * τ).reals »+« @center;
[ $x.round(.01), $y.round(.01), (.sqrt * $scale / 100).round(.1) ]
}, 1 .. $seeds;

say SVG.serialize(
svg => [
:600width, :600height, :style<stroke:yellow>,
:rect[:width<100%>, :height<100%>, :fill<black>],
|@c.map( { :circle[:cx(.[0]), :cy(.[1]), :r(.[2])] } ),
],
);</lang>
See: [https://github.com/thundergnat/rc/blob/master/img/phi-packing-perl6.svg Phi packing] (SVG image)


=={{header|Ring}}==
=={{header|Ring}}==