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
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue