Barnsley fern: Difference between revisions

Adding SequenceL.
(wrong header)
(Adding SequenceL.)
Line 996:
render #g
#g "flush"</lang>
 
=={{header|SequenceL}}==
'''Tail-Recursive SequenceL Code:'''<br>
<lang sequencel>import <Utilities/Math.sl>;
import <Utilities/Random.sl>;
 
transform(p(1), rand) :=
let
x := p[1]; y := p[2];
in
[0.0, 0.16*y] when rand <= 0.01
else
[0.85*x + 0.04*y, -0.04*x + 0.85*y + 1.6] when rand <= 0.86
else
[0.2*x - 0.26*y, 0.23*x + 0.22*y + 1.6] when rand <= 0.93
else
[-0.15*x + 0.28*y, 0.26*x + 0.24*y + 0.44];
barnsleyFern(rand, count, result(2)) :=
let
nextRand := getRandom(rand);
next := transform(result[size(result)], nextRand.value / 2147483647.0);
in
result when count <= 0
else
barnsleyFern(nextRand.generator, count - 1, result ++ [next]);
 
scale(p(1), width, height) := [round((p[1] + 2.182) * width / 4.8378),
round((9.9983 - p[2]) * height / 9.9983)];
entry(seed, count, width, height) :=
let
fern := barnsleyFern(seedRandom(seed), count, [[0.0,0.0]]);
in
scale(fern, width, height);</lang>
 
'''C++ Driver Code:'''<br>
{{libheader|CImg}}
<lang c>#include "SL_Generated.h"
#include "CImg.h"
 
using namespace cimg_library;
 
int main(int argc, char** argv)
{
int threads = 0; if(argc > 1) threads = atoi(argv[1]);
int width = 300; if(argc > 2) width = atoi(argv[2]);
int height = 600; if(argc > 3) height = atoi(argv[3]);
int steps = 10000; if(argc > 4) steps = atoi(argv[4]);
int seed = 314159; if(argc > 5) seed = atoi(argv[5]);
CImg<unsigned char> visu(width, height, 1, 3, 0);
Sequence< Sequence<int> > result;
 
sl_init(threads);
 
sl_entry(seed, steps, width-1, height-1, threads, result);
visu.fill(0);
for(int i = 1; i <= result.size(); i++)
visu(result[i][1], result[i][2],1) = 255;
CImgDisplay draw_disp(visu);
draw_disp.set_title("Barnsley Fern in SequenceL");
visu.display(draw_disp);
while(!draw_disp.is_closed()) draw_disp.wait();
 
sl_done();
 
return 0;
}</lang>
 
{{out}}
[https://i.imgur.com/zerRZo8.png Output Screenshot]
 
 
=={{header|Sidef}}==