Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,88 @@
import <Utilities/Complex.sl>;
import <Utilities/Sequence.sl>;
import <Utilities/Math.sl>;
COLOR_STRUCT ::= (R: int(0), G: int(0), B: int(0));
rgb(r(0), g(0), b(0)) := (R: r, G: g, B: b);
RESULT_STRUCT ::= (FinalValue: Complex(0), Iterations: int(0));
makeResult(val(0), iters(0)) := (FinalValue: val, Iterations: iters);
zSquaredOperation(startingNum(0), currentNum(0)) :=
complexAdd(startingNum, complexMultiply(currentNum, currentNum));
zSquared(minX(0), maxX(0), resolutionX(0), minY(0), maxY(0), resolutionY(0), maxMagnitude(0), maxIters(0))[Y,X] :=
let
stepX := (maxX - minX) / resolutionX;
stepY := (maxY - minY) / resolutionY;
currentX := X * stepX + minX;
currentY := Y * stepY + minY;
in
operateUntil(zSquaredOperation, makeComplex(currentX, currentY), makeComplex(currentX, currentY), maxMagnitude, 0, maxIters)
foreach Y within 0 ... (resolutionY - 1),
X within 0 ... (resolutionX - 1);
operateUntil(operation(0), startingNum(0), currentNum(0), maxMagnitude(0), currentIters(0), maxIters(0)) :=
let
operated := operation(startingNum, currentNum);
in
makeResult(currentNum, maxIters) when currentIters >= maxIters
else
makeResult(currentNum, currentIters) when complexMagnitude(currentNum) >= maxMagnitude
else
operateUntil(operation, startingNum, operated, maxMagnitude, currentIters + 1, maxIters);
//region Smooth Coloring
COLOR_COUNT := size(colorSelections);
colorRange := range(0, 255, 1);
colors :=
let
first[i] := rgb(0, 0, i) foreach i within colorRange;
second[i] := rgb(i, i, 255) foreach i within colorRange;
third[i] := rgb(255, 255, i) foreach i within reverse(colorRange);
fourth[i] := rgb(255, i, 0) foreach i within reverse(colorRange);
fifth[i] := rgb(i, 0, 0) foreach i within reverse(colorRange);
red[i] := rgb(i, 0, 0) foreach i within colorRange;
redR[i] := rgb(i, 0, 0) foreach i within reverse(colorRange);
green[i] := rgb(0, i, 0) foreach i within colorRange;
greenR[i] :=rgb(0, i, 0) foreach i within reverse(colorRange);
blue[i] := rgb(0, 0, i) foreach i within colorRange;
blueR[i] := rgb(0, 0, i) foreach i within reverse(colorRange);
in
//red ++ redR ++ green ++ greenR ++ blue ++ blueR;
first ++ second ++ third ++ fourth ++ fifth;
//first ++ fourth;
colorSelections := range(1, size(colors), 30);
getSmoothColorings(zSquaredResult(2), maxIters(0))[Y,X] :=
let
current := zSquaredResult[Y,X];
zn := complexMagnitude(current.FinalValue);
nu := ln(ln(zn) / ln(2)) / ln(2);
result := abs(current.Iterations + 1 - nu);
index := floor(result);
rem := result - index;
color1 := colorSelections[(index mod COLOR_COUNT) + 1];
color2 := colorSelections[((index + 1) mod COLOR_COUNT) + 1];
in
rgb(0, 0, 0) when current.Iterations = maxIters
else
colors[color1] when color2 < color1
else
colors[floor(linearInterpolate(color1, color2, rem))];
linearInterpolate(v0(0), v1(0), t(0)) := (1 - t) * v0 + t * v1;
//endregion

View file

@ -0,0 +1,103 @@
#include "SL_Generated.h"
#include "../../../ThirdParty/CImg/CImg.h"
using namespace std;
using namespace cimg_library;
int main(int argc, char ** argv)
{
int cores = 0;
Sequence<Sequence<_sl_RESULT_STRUCT> > computeResult;
Sequence<Sequence<_sl_COLOR_STRUCT> > colorResult;
sl_init(cores);
int maxIters = 1000;
int imageWidth = 1920;
int imageHeight = 1200;
double maxMag = 256;
double xmin = -2.5;
double xmax = 1.0;
double ymin = -1.0;
double ymax = 1.0;
CImg<unsigned char> visu(imageWidth, imageHeight, 1, 3);
CImgDisplay draw_disp(visu, "Mandelbrot Fractal in SequenceL");
bool redraw = true;
SLTimer t;
double computeTime;
double colorTime;
double renderTime;
while(!draw_disp.is_closed())
{
if(redraw)
{
redraw = false;
t.start();
sl_zSquared(xmin, xmax, imageWidth, ymin, ymax, imageHeight, maxMag, maxIters, cores, computeResult);
t.stop();
computeTime = t.getTime();
t.start();
sl_getSmoothColorings(computeResult, maxIters, cores, colorResult);
t.stop();
colorTime = t.getTime();
t.start();
visu.fill(0);
for(int i = 1; i <= colorResult.size(); i++)
{
for(int j = 1; j <= colorResult[i].size(); j++)
{
visu(j-1,i-1,0,0) = colorResult[i][j].R;
visu(j-1,i-1,0,1) = colorResult[i][j].G;
visu(j-1,i-1,0,2) = colorResult[i][j].B;
}
}
visu.display(draw_disp);
t.stop();
renderTime = t.getTime();
draw_disp.set_title("X:[%f, %f] Y:[%f, %f] | Mandelbrot Fractal in SequenceL | Compute Time: %f | Color Time: %f | Render Time: %f | Total FPS: %f", xmin, xmax, ymin, ymax, cores, computeTime, colorTime, renderTime, 1 / (computeTime + colorTime + renderTime));
}
draw_disp.wait();
double xdiff = (xmax - xmin);
double ydiff = (ymax - ymin);
double xcenter = ((1.0 * draw_disp.mouse_x()) / imageWidth) * xdiff + xmin;
double ycenter = ((1.0 * draw_disp.mouse_y()) / imageHeight) * ydiff + ymin;
if(draw_disp.button()&1)
{
redraw = true;
xmin = xcenter - (xdiff / 4);
xmax = xcenter + (xdiff / 4);
ymin = ycenter - (ydiff / 4);
ymax = ycenter + (ydiff / 4);
}
else if(draw_disp.button()&2)
{
redraw = true;
xmin = xcenter - xdiff;
xmax = xcenter + xdiff;
ymin = ycenter - ydiff;
ymax = ycenter + ydiff;
}
}
sl_done();
return 0;
}