Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
36
Task/Mandelbrot-set/ERRE/mandelbrot-set.erre
Normal file
36
Task/Mandelbrot-set/ERRE/mandelbrot-set.erre
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
PROGRAM MANDELBROT
|
||||
|
||||
!$KEY
|
||||
!$INCLUDE="PC.LIB"
|
||||
|
||||
BEGIN
|
||||
|
||||
SCREEN(7)
|
||||
GR_WINDOW(-2,1.5,2,-1.5)
|
||||
FOR X0=-2 TO 2 STEP 0.01 DO
|
||||
FOR Y0=-1.5 TO 1.5 STEP 0.01 DO
|
||||
X=0
|
||||
Y=0
|
||||
|
||||
ITERATION=0
|
||||
MAX_ITERATION=223
|
||||
|
||||
WHILE (X*X+Y*Y<=(2*2) AND ITERATION<MAX_ITERATION) DO
|
||||
X_TEMP=X*X-Y*Y+X0
|
||||
Y=2*X*Y+Y0
|
||||
|
||||
X=X_TEMP
|
||||
|
||||
ITERATION=ITERATION+1
|
||||
END WHILE
|
||||
|
||||
IF ITERATION<>MAX_ITERATION THEN
|
||||
C=ITERATION
|
||||
ELSE
|
||||
C=0
|
||||
END IF
|
||||
|
||||
PSET(X0,Y0,C)
|
||||
END FOR
|
||||
END FOR
|
||||
END PROGRAM
|
||||
11
Task/Mandelbrot-set/EchoLisp/mandelbrot-set.echolisp
Normal file
11
Task/Mandelbrot-set/EchoLisp/mandelbrot-set.echolisp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(lib 'math) ;; fractal function
|
||||
(lib 'plot)
|
||||
|
||||
;; (fractal z zc n) iterates z := z^2 + c, n times
|
||||
;; 100 iterations
|
||||
(define (mset z) (if (= Infinity (fractal 0 z 100)) Infinity z))
|
||||
|
||||
;; plot function argument inside square (-2 -2), (2,2)
|
||||
(plot-z-arg mset -2 -2)
|
||||
|
||||
;; result here [http://www.echolalie.org/echolisp/help.html#fractal]
|
||||
40
Task/Mandelbrot-set/Futhark/mandelbrot-set.futhark
Normal file
40
Task/Mandelbrot-set/Futhark/mandelbrot-set.futhark
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
default(f32)
|
||||
|
||||
type complex = (f32, f32)
|
||||
|
||||
fun dot(c: complex): f32 =
|
||||
let (r, i) = c
|
||||
in r * r + i * i
|
||||
|
||||
fun multComplex(x: complex, y: complex): complex =
|
||||
let (a, b) = x
|
||||
let (c, d) = y
|
||||
in (a*c - b * d,
|
||||
a*d + b * c)
|
||||
|
||||
fun addComplex(x: complex, y: complex): complex =
|
||||
let (a, b) = x
|
||||
let (c, d) = y
|
||||
in (a + c,
|
||||
b + d)
|
||||
|
||||
fun divergence(depth: int, c0: complex): int =
|
||||
loop ((c, i) = (c0, 0)) = while i < depth && dot(c) < 4.0 do
|
||||
(addComplex(c0, multComplex(c, c)),
|
||||
i + 1)
|
||||
in i
|
||||
|
||||
fun mandelbrot(screenX: int, screenY: int, depth: int, view: (f32,f32,f32,f32)): [screenX][screenY]int =
|
||||
let (xmin, ymin, xmax, ymax) = view
|
||||
let sizex = xmax - xmin
|
||||
let sizey = ymax - ymin
|
||||
in map (fn (x: int): [screenY]int =>
|
||||
map (fn (y: int): int =>
|
||||
let c0 = (xmin + (f32(x) * sizex) / f32(screenX),
|
||||
ymin + (f32(y) * sizey) / f32(screenY))
|
||||
in divergence(depth, c0))
|
||||
(iota screenY))
|
||||
(iota screenX)
|
||||
|
||||
fun main(screenX: int, screenY: int, depth: int, xmin: f32, ymin: f32, xmax: f32, ymax: f32): [screenX][screenY]int =
|
||||
mandelbrot(screenX, screenY, depth, (xmin, ymin, xmax, ymax))
|
||||
32
Task/Mandelbrot-set/GLSL/mandelbrot-set.glsl
Normal file
32
Task/Mandelbrot-set/GLSL/mandelbrot-set.glsl
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
void main(void)
|
||||
{
|
||||
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
||||
float scale = iResolution.y / iResolution.x;
|
||||
uv=((uv-0.5)*5.5);
|
||||
uv.y*=scale;
|
||||
uv.y+=0.0;
|
||||
uv.x-=0.5;
|
||||
|
||||
|
||||
vec2 z = vec2(0.0, 0.0);
|
||||
vec3 c = vec3(0.0, 0.0, 0.0);
|
||||
float v;
|
||||
|
||||
for(int i=0;(i<170);i++)
|
||||
{
|
||||
|
||||
if(((z.x*z.x+z.y*z.y) >= 4.0)) break;
|
||||
z = vec2(z.x*z.x - z.y*z.y, 2.0*z.y*z.x) + uv;
|
||||
|
||||
|
||||
if((z.x*z.x+z.y*z.y) >= 2.0)
|
||||
{
|
||||
c.b=float(i)/20.0;
|
||||
c.r=sin((float(i)/5.0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
gl_FragColor = vec4(c,1.0);
|
||||
}
|
||||
51
Task/Mandelbrot-set/Lasso/mandelbrot-set.lasso
Normal file
51
Task/Mandelbrot-set/Lasso/mandelbrot-set.lasso
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
define mandelbrotBailout => 16
|
||||
define mandelbrotMaxIterations => 1000
|
||||
|
||||
define mandelbrotIterate(x, y) => {
|
||||
local(cr = #y - 0.5,
|
||||
ci = #x,
|
||||
zi = 0.0,
|
||||
zr = 0.0,
|
||||
i = 0,
|
||||
temp, zr2, zi2)
|
||||
|
||||
{
|
||||
++#i;
|
||||
#temp = #zr * #zi
|
||||
#zr2 = #zr * #zr
|
||||
#zi2 = #zi * #zi
|
||||
|
||||
#zi2 + #zr2 > mandelbrotBailout?
|
||||
return #i
|
||||
#i > mandelbrotMaxIterations?
|
||||
return 0
|
||||
|
||||
#zr = #zr2 - #zi2 + #cr
|
||||
#zi = #temp + #temp + #ci
|
||||
|
||||
currentCapture->restart
|
||||
}()
|
||||
}
|
||||
|
||||
define mandelbrotTest() => {
|
||||
local(x, y = -39.0)
|
||||
{
|
||||
stdout('\n')
|
||||
#x = -39.0
|
||||
{
|
||||
mandelbrotIterate(#x / 40.0, #y / 40.0) == 0?
|
||||
stdout('*')
|
||||
| stdout(' ');
|
||||
++#x
|
||||
#x <= 39.0?
|
||||
currentCapture->restart
|
||||
}();
|
||||
++#y
|
||||
|
||||
#y <= 39.0?
|
||||
currentCapture->restart
|
||||
}()
|
||||
stdout('\n')
|
||||
}
|
||||
|
||||
mandelbrotTest
|
||||
20
Task/Mandelbrot-set/Nim/mandelbrot-set.nim
Normal file
20
Task/Mandelbrot-set/Nim/mandelbrot-set.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import complex
|
||||
|
||||
proc mandelbrot(a): Complex =
|
||||
for i in 0 .. <50:
|
||||
result = result * result + a
|
||||
|
||||
iterator stepIt(start, step, iterations) =
|
||||
for i in 0 .. iterations:
|
||||
yield start + float(i) * step
|
||||
|
||||
var rows = ""
|
||||
for y in stepIt(1.0, -0.05, 41):
|
||||
for x in stepIt(-2.0, 0.0315, 80):
|
||||
if abs(mandelbrot((x,y))) < 2:
|
||||
rows.add('*')
|
||||
else:
|
||||
rows.add(' ')
|
||||
rows.add("\n")
|
||||
|
||||
echo rows
|
||||
25
Task/Mandelbrot-set/Phix/mandelbrot-set-1.phix
Normal file
25
Task/Mandelbrot-set/Phix/mandelbrot-set-1.phix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
--
|
||||
-- Mandlebrot set in ascii art demo.
|
||||
--
|
||||
constant b=" .:,;!/>)|&IH%*#"
|
||||
atom r, i, c, C, z, Z, t, k
|
||||
for y=30 to 0 by -1 do
|
||||
C = y*0.1-1.5
|
||||
puts(1,'\n')
|
||||
for x=0 to 74 do
|
||||
c = x*0.04-2
|
||||
z = 0
|
||||
Z = 0
|
||||
r = c
|
||||
i = C
|
||||
k = 0
|
||||
while k<112 do
|
||||
t = z*z-Z*Z+r
|
||||
Z = 2*z*Z+i
|
||||
z = t
|
||||
if z*z+Z*Z>10 then exit end if
|
||||
k += 1
|
||||
end while
|
||||
puts(1,b[remainder(k,16)+1])
|
||||
end for
|
||||
end for
|
||||
241
Task/Mandelbrot-set/Phix/mandelbrot-set-2.phix
Normal file
241
Task/Mandelbrot-set/Phix/mandelbrot-set-2.phix
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
include arwen.ew
|
||||
include ..\arwen\dib256.ew
|
||||
|
||||
constant HelpText = "Left-click drag with the mouse to move the image.\n"&
|
||||
" (the image is currently only redrawn on mouseup).\n"&
|
||||
"Right-click-drag with the mouse to select a region to zoom in to.\n"&
|
||||
"Use the mousewheel to zoom in and out (nb: can be slow).\n"&
|
||||
"Press F2 to select iterations, higher==more detail but slower.\n"&
|
||||
"Resize the window as you please, but note that going fullscreen, \n"&
|
||||
"especially at high iteration, may mean a quite long draw time.\n"&
|
||||
"Press Escape to close the window."
|
||||
|
||||
procedure Help()
|
||||
void = messageBox("Mandelbrot Set",HelpText,MB_OK)
|
||||
end procedure
|
||||
|
||||
integer cWidth = 520 -- client area width
|
||||
integer cHeight = 480 -- client area height
|
||||
|
||||
constant Main = create(Window, "Mandelbrot Set", 0, 0, 50, 50, cWidth+16, cHeight+38, 0),
|
||||
mainHwnd = getHwnd(Main),
|
||||
mainDC = getPrivateDC(Main),
|
||||
|
||||
mIter = create(Menu, "", 0, 0, 0,0,0,0,0),
|
||||
iterHwnd = getHwnd(mIter),
|
||||
mIter50 = create(MenuItem,"50 (fast, low detail)", 0, mIter, 0,0,0,0,0),
|
||||
mIter100 = create(MenuItem,"100 (default)", 0, mIter, 0,0,0,0,0),
|
||||
mIter500 = create(MenuItem,"500", 0, mIter, 0,0,0,0,0),
|
||||
mIter1000 = create(MenuItem,"1000 (slow, high detail)",0, mIter, 0,0,0,0,0),
|
||||
m50to1000 = {mIter50,mIter100,mIter500,mIter1000},
|
||||
i50to1000 = { 50, 100, 500, 1000}
|
||||
|
||||
integer mainDib = 0
|
||||
|
||||
constant whitePen = c_func(xCreatePen, {0,1,BrightWhite})
|
||||
constant NULL_BRUSH = 5,
|
||||
NullBrushID = c_func(xGetStockObject,{NULL_BRUSH})
|
||||
|
||||
atom t0
|
||||
integer iter
|
||||
atom x0, y0 -- top-left coords to draw
|
||||
atom scale -- controls width/zoom
|
||||
|
||||
procedure init()
|
||||
x0 = -2
|
||||
y0 = -1.25
|
||||
scale = 2.5/cHeight
|
||||
iter = 100
|
||||
void = c_func(xSelectObject,{mainDC,whitePen})
|
||||
void = c_func(xSelectObject,{mainDC,NullBrushID})
|
||||
end procedure
|
||||
init()
|
||||
|
||||
function in_set(atom x, atom y)
|
||||
atom u,t
|
||||
if x>-0.75 then
|
||||
u = x-0.25
|
||||
t = u*u+y*y
|
||||
return ((2*t+u)*(2*t+u)>t)
|
||||
else
|
||||
return ((x+1)*(x+1)+y*y)>0.0625
|
||||
end if
|
||||
end function
|
||||
|
||||
function pixel_colour(atom x0, atom y0, integer iter)
|
||||
integer count = 1
|
||||
atom x = 0, y = 0
|
||||
while (count<=iter) and (x*x+y*y<4) do
|
||||
count += 1
|
||||
{x,y} = {x*x-y*y+x0,2*x*y+y0}
|
||||
end while
|
||||
if count<=iter then return count end if
|
||||
return 0
|
||||
end function
|
||||
|
||||
procedure mandel(atom x0, atom y0, atom scale)
|
||||
atom x,y
|
||||
integer c
|
||||
t0 = time()
|
||||
y = y0
|
||||
for yi=1 to cHeight do
|
||||
x = x0
|
||||
for xi=1 to cWidth do
|
||||
c = 0 -- default to black
|
||||
if in_set(x,y) then
|
||||
c = pixel_colour(x,y,iter)
|
||||
end if
|
||||
setDibPixel(mainDib, xi, yi, c)
|
||||
x += scale
|
||||
end for
|
||||
y += scale
|
||||
end for
|
||||
end procedure
|
||||
|
||||
integer firsttime = 1
|
||||
integer drawBox = 0
|
||||
integer drawTime = 0
|
||||
|
||||
procedure newDib()
|
||||
sequence pal
|
||||
|
||||
if mainDib!=0 then
|
||||
{} = deleteDib(mainDib)
|
||||
end if
|
||||
mainDib = createDib(cWidth, cHeight)
|
||||
pal = repeat({0,0,0},256)
|
||||
for i=2 to 256 do
|
||||
pal[i][1] = i*5
|
||||
pal[i][2] = 0
|
||||
pal[i][3] = i*10
|
||||
end for
|
||||
setDibPalette(mainDib, 1, pal)
|
||||
mandel(x0,y0,scale)
|
||||
drawTime = 2
|
||||
end procedure
|
||||
|
||||
procedure reDraw()
|
||||
setText(Main,"Please Wait...")
|
||||
mandel(x0,y0,scale)
|
||||
drawTime = 2
|
||||
repaintWindow(Main,False)
|
||||
end procedure
|
||||
|
||||
procedure zoom(integer z)
|
||||
while z do
|
||||
if z>0 then
|
||||
scale /= 1.1
|
||||
z -= 1
|
||||
else
|
||||
scale *= 1.1
|
||||
z += 1
|
||||
end if
|
||||
end while
|
||||
reDraw()
|
||||
end procedure
|
||||
|
||||
integer dx=0,dy=0 -- mouse down coords
|
||||
integer mx=0,my=0 -- mouse move/up coords
|
||||
|
||||
function mainHandler(integer id, integer msg, atom wParam, object lParam)
|
||||
integer x, y -- scratch vars
|
||||
atom scale10
|
||||
|
||||
if msg=WM_SIZE then -- (also activate/firsttime)
|
||||
{{},{},x,y} = getClientRect(Main)
|
||||
if firsttime or cWidth!=x or cHeight!=y then
|
||||
scale *= cWidth/x
|
||||
{cWidth, cHeight} = {x,y}
|
||||
newDib()
|
||||
firsttime = 0
|
||||
end if
|
||||
elsif msg=WM_PAINT then
|
||||
copyDib(mainDC, 0, 0, mainDib)
|
||||
if drawBox then
|
||||
void = c_func(xRectangle, {mainDC, dx, dy, mx, my})
|
||||
end if
|
||||
if drawTime then
|
||||
if drawTime=2 then
|
||||
setText(Main,sprintf("Mandelbrot Set [generated in %gs]",time()-t0))
|
||||
else
|
||||
setText(Main,"Mandelbrot Set")
|
||||
end if
|
||||
drawTime -= 1
|
||||
end if
|
||||
elsif msg=WM_CHAR then
|
||||
if wParam=VK_ESCAPE then
|
||||
closeWindow(Main)
|
||||
elsif wParam='+' then zoom(+1)
|
||||
elsif wParam='-' then zoom(-1)
|
||||
end if
|
||||
elsif msg=WM_LBUTTONDOWN
|
||||
or msg=WM_RBUTTONDOWN then
|
||||
{dx,dy} = lParam
|
||||
elsif msg=WM_MOUSEMOVE then
|
||||
if and_bits(wParam,MK_LBUTTON) then
|
||||
{mx,my} = lParam
|
||||
-- minus dx,dy (see WM_LBUTTONUP)
|
||||
-- DEV maybe a timer to redraw, but probably too slow...
|
||||
-- (this is where we need a background worker thread,
|
||||
-- ideally one we can direct to abandon what it is
|
||||
-- currently doing and start work on new x,y instead)
|
||||
elsif and_bits(wParam,MK_RBUTTON) then
|
||||
{mx,my} = lParam
|
||||
drawBox = 1
|
||||
repaintWindow(Main,False)
|
||||
end if
|
||||
elsif msg=WM_MOUSEWHEEL then
|
||||
wParam = floor(wParam/#10000)
|
||||
if wParam>=#8000 then -- sign bit set
|
||||
wParam-=#10000
|
||||
end if
|
||||
wParam = floor(wParam/120) -- (gives +/-1, usually)
|
||||
zoom(wParam)
|
||||
elsif msg=WM_LBUTTONUP then
|
||||
{mx,my} = lParam
|
||||
drawBox = 0
|
||||
x0 += (dx-mx)*scale
|
||||
y0 += (dy-my)*scale
|
||||
reDraw()
|
||||
elsif msg=WM_RBUTTONUP then
|
||||
{mx,my} = lParam
|
||||
drawBox = 0
|
||||
if mx!=dx and my!=dy then
|
||||
x0 += min(mx,dx)*scale
|
||||
y0 += min(my,dy)*scale
|
||||
scale *= (abs(mx-dx))/cHeight
|
||||
reDraw()
|
||||
end if
|
||||
elsif msg=WM_KEYDOWN then
|
||||
if wParam=VK_F1 then
|
||||
Help()
|
||||
elsif wParam=VK_F2 then
|
||||
{x,y} = getWindowRect(Main)
|
||||
void = c_func(xTrackPopupMenu, {iterHwnd,TPM_LEFTALIGN,x+20,y+40,0,mainHwnd,NULL})
|
||||
elsif find(wParam,{VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT}) then
|
||||
drawBox = 0
|
||||
scale10 = scale*10
|
||||
if wParam=VK_UP then
|
||||
y0 += scale10
|
||||
elsif wParam=VK_DOWN then
|
||||
y0 -= scale10
|
||||
elsif wParam=VK_LEFT then
|
||||
x0 += scale10
|
||||
elsif wParam=VK_RIGHT then
|
||||
x0 -= scale10
|
||||
end if
|
||||
reDraw()
|
||||
end if
|
||||
elsif msg=WM_COMMAND then
|
||||
id = find(id,m50to1000)
|
||||
if id!=0 then
|
||||
iter = i50to1000[id]
|
||||
reDraw()
|
||||
end if
|
||||
end if
|
||||
return 0
|
||||
end function
|
||||
setHandler({Main,mIter50,mIter100,mIter500,mIter1000}, routine_id("mainHandler"))
|
||||
|
||||
WinMain(Main,SW_NORMAL)
|
||||
void = deleteDib(0)
|
||||
53
Task/Mandelbrot-set/Ring/mandelbrot-set.ring
Normal file
53
Task/Mandelbrot-set/Ring/mandelbrot-set.ring
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
load "guilib.ring"
|
||||
|
||||
new qapp
|
||||
{
|
||||
win1 = new qwidget() {
|
||||
setwindowtitle("drawing using qpainter")
|
||||
setgeometry(100,100,500,500)
|
||||
label1 = new qlabel(win1) {
|
||||
setgeometry(10,10,400,400)
|
||||
settext("")
|
||||
}
|
||||
new qpushbutton(win1) {
|
||||
setgeometry(200,400,100,30)
|
||||
settext("draw")
|
||||
setclickevent("draw()")
|
||||
}
|
||||
show()
|
||||
}
|
||||
exec()
|
||||
}
|
||||
|
||||
func draw
|
||||
p1 = new qpicture()
|
||||
color = new qcolor() {
|
||||
setrgb(0,0,255,255)
|
||||
}
|
||||
pen = new qpen() {
|
||||
setcolor(color)
|
||||
setwidth(1)
|
||||
}
|
||||
new qpainter() {
|
||||
begin(p1)
|
||||
setpen(pen)
|
||||
|
||||
x1=300 y1=250
|
||||
i1=-1 i2=1 r1=-2 r2=1
|
||||
s1=(r2-r1)/x1 s2=(i2-i1)/y1
|
||||
for y=0 to y1
|
||||
i3=i1+s2*y
|
||||
for x=0 to x1
|
||||
r3=r1+s1*x z1=r3 z2=i3
|
||||
for n=0 to 30
|
||||
a=z1*z1 b=z2*z2
|
||||
if a+b>4 exit ok
|
||||
z2=2*z1*z2+i3 z1=a-b+r3
|
||||
next
|
||||
if n != 31 drawpoint(x,y) ok
|
||||
next
|
||||
next
|
||||
|
||||
endpaint()
|
||||
}
|
||||
label1 { setpicture(p1) show() }
|
||||
88
Task/Mandelbrot-set/SequenceL/mandelbrot-set-1.sequencel
Normal file
88
Task/Mandelbrot-set/SequenceL/mandelbrot-set-1.sequencel
Normal 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
|
||||
103
Task/Mandelbrot-set/SequenceL/mandelbrot-set-2.sequencel
Normal file
103
Task/Mandelbrot-set/SequenceL/mandelbrot-set-2.sequencel
Normal 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;
|
||||
}
|
||||
14
Task/Mandelbrot-set/Sidef/mandelbrot-set.sidef
Normal file
14
Task/Mandelbrot-set/Sidef/mandelbrot-set.sidef
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
func mandelbrot(z) {
|
||||
var c = z;
|
||||
{ z = (z*z + c);
|
||||
z.abs > 2 && return true;
|
||||
} * 20;
|
||||
return false;
|
||||
}
|
||||
|
||||
1 ^.. (-1, 0.05) -> each { |y|
|
||||
-2 ..^ (0.5, 0.0315) -> each { |x|
|
||||
print(mandelbrot(y.i + x) ? ' ' : '#');
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
14
Task/Mandelbrot-set/jq/mandelbrot-set-1.jq
Normal file
14
Task/Mandelbrot-set/jq/mandelbrot-set-1.jq
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# SVG STUFF
|
||||
def svg(id; width; height):
|
||||
"<svg width='\(width // "100%")' height='\(height // "100%") '
|
||||
id='\(id)'
|
||||
xmlns='http://www.w3.org/2000/svg'>";
|
||||
|
||||
def pixel(x;y;r;g;b;a):
|
||||
"<circle cx='\(x)' cy='\(y)' r='1' fill='rgb(\(r|floor),\(g|floor),\(b|floor))' />";
|
||||
|
||||
# "UNTIL"
|
||||
# As soon as "condition" is true, then emit . and stop:
|
||||
def do_until(condition; next):
|
||||
def u: if condition then . else (next|u) end;
|
||||
u;
|
||||
40
Task/Mandelbrot-set/jq/mandelbrot-set-2.jq
Normal file
40
Task/Mandelbrot-set/jq/mandelbrot-set-2.jq
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
def Mandeliter( cx; cy; maxiter ):
|
||||
# [i, x, y, x^2+y^2]
|
||||
[ maxiter, 0.0, 0.0, 0.0 ]
|
||||
| do_until( .[0] == 0 or .[3] > 4;
|
||||
.[1] as $x | .[2] as $y
|
||||
| ($x * $y) as $xy
|
||||
| ($x * $x) as $xx
|
||||
| ($y * $y) as $yy
|
||||
| [ (.[0] - 1), # i
|
||||
($xx - $yy + cx), # x
|
||||
($xy + $xy + cy), # y
|
||||
($xx+$yy) # xx+yy
|
||||
] )
|
||||
| maxiter - .[0];
|
||||
|
||||
# width and height should be specified as the number of pixels.
|
||||
# obj == { xmin: _, xmax: _, ymin: _, ymax: _ }
|
||||
def Mandelbrot( obj; width; height; iterations ):
|
||||
def pixies:
|
||||
range(0; width) as $ix
|
||||
| (obj.xmin + ((obj.xmax - obj.xmin) * $ix / (width - 1))) as $x
|
||||
| range(0; height) as $iy
|
||||
| (obj.ymin + ((obj.ymax - obj.ymin) * $iy / (height - 1))) as $y
|
||||
| Mandeliter( $x; $y; iterations ) as $i
|
||||
| if $i == iterations then
|
||||
pixel($ix; $iy; 0; 0; 0; 255)
|
||||
else
|
||||
(3 * ($i|log)/((iterations - 1.0)|log)) as $c # redness
|
||||
| if $c < 1 then
|
||||
pixel($ix;$iy; 255*$c; 0; 0; 255)
|
||||
elif $c < 2 then
|
||||
pixel($ix;$iy; 255; 255*($c-1); 0; 255)
|
||||
else
|
||||
pixel($ix;$iy; 255; 255; 255*($c-2); 255)
|
||||
end
|
||||
end;
|
||||
|
||||
svg("mandelbrot"; "100%"; "100%"),
|
||||
pixies,
|
||||
"</svg>";
|
||||
1
Task/Mandelbrot-set/jq/mandelbrot-set-3.jq
Normal file
1
Task/Mandelbrot-set/jq/mandelbrot-set-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
Mandelbrot( {"xmin": -2, "xmax": 1, "ymin": -1, "ymax":1}; 900; 600; 1000 )
|
||||
Loading…
Add table
Add a link
Reference in a new issue