-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmandelbrute.spd
More file actions
executable file
·61 lines (51 loc) · 1.35 KB
/
mandelbrute.spd
File metadata and controls
executable file
·61 lines (51 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/local/bin/spd
import "GUI"
// Copy of a seed7 mandelbrot example.
// Mine is more readable... and has less lines of code.
// Also added keyboard/mouse handling, which was missing from theirs.
// Probably this would be better using fixed-point int math.
|vec4[256]| ColorTable
main
for col in 256
|| C = vec4(2609, 5003, 257, 0)
|| F = Col|float| / 64K|float|
C = 1.0 - (C*F).fract
colorTable[col] = C
return Mandelbroat().RunAsMain(1.0, 1)
class Mandelbroat (window)
|float| zoom = 1.3
|vec2| center = (-0.75, 0.0)
function Iterate (|vec2| z0, |int|)
rz++
|| z = z0
while (z.lengthsq < 4.0) and (rz < 256)
(z cmul= z)
z += z0
rz++
behaviour draw
Where.DrawRect(self, colors.black)
|| pix = (where.height/2)-1
|| zoom = .zoom / pix|float|
|| z0 = vec2()
|| adjust = (Where.Size-pix*2)/2
for x in -pix to pix
for y in -pix to pix
z0 = .center + vec2(x,y)*zoom
|| c = colorTable[.iterate(z0)]
where[(x,y)+adjust+pix] <~ C
// Extra mouse/keyboard handling. Not in original.
behaviour Gesture
if Wheel.y > 0
.zoom /= 0.9
gui.touch
elseif Wheel.y < 0
.zoom *= 0.9
gui.touch
behaviour keydown
|| M = keys.Movement.sign
.center += M.xz*0.05*.zoom
.zoom += m.y * 0.05
gui.touch
behaviour MouseMove
.center += move.Vec2*(1.0, -1.0)*0.0025*.zoom
gui.touch