-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pony
83 lines (69 loc) · 1.98 KB
/
main.pony
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use "collections"
use "random"
use "time"
class val CoordToLin
let _width: USize
let _height: USize
new val create(w: USize, h: USize) =>
_width = w
_height = h
fun apply(x: USize, y: USize): USize =>
(x * _width) + y
actor Main
new create(env: Env) =>
let width: USize = 50
let height: USize = 30
let factor: F64 = 20
let offsets = Map[USize, (F64, F64)]
let ctl = CoordToLin(width, height)
let rand = MT(Time.micros())
let perlin_x = Perlin(100, 100, rand)
let perlin_y = Perlin(100, 100, rand)
for i in Range(0, width) do
let x = ((i.f64() / width.f64()) * 8.109) + 0.05
for j in Range(0, height) do
let y = ((j.f64() / height.f64()) * 8.109) + 0.05
offsets(ctl(i, j)) = try
let px = perlin_x(x, y)?
let py = perlin_y(x, y)?
(px, py)
else
// If (x, y) is outside of the perlin range then just punt.
(0, 0)
end
end
end
let x_start: F64 = 100
let y_start: F64 = 100
let pcs = PathCommands
for i in Range(0, width) do
for j in Range(0, height) do
try
(let dx, let dy) = offsets(ctl(i, j))?
let x = (i.f64() * factor) + (dx * factor * 2) + x_start
let y = (j.f64() * factor) + (dy * factor * 2) + y_start
if j == 0 then
pcs.command(PathMove.abs(x, y))
else
pcs.command(PathLine.abs(x, y))
end
end
end
end
for i in Range(0, height) do
for j in Range(0, width) do
try
(let dx, let dy) = offsets(ctl(j, i))?
let x = (j.f64() * factor) + (dx * factor * 2) + x_start
let y = (i.f64() * factor) + (dy * factor * 2) + y_start
if j == 0 then
pcs.command(PathMove.abs(x, y))
else
pcs.command(PathLine.abs(x, y))
end
end
end
end
let svg = SVG.svg()
svg.c(SVG.path(pcs))
env.out.print(svg.render())