-
Notifications
You must be signed in to change notification settings - Fork 2
/
shape.lua
88 lines (87 loc) · 2.51 KB
/
shape.lua
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
84
85
86
87
88
function init()
setName("Shape")
setDesc("Generates a shape")
setSize(100, 24+64+8+8+18+7+4)
addOutput(24+32)
addParameter("Type", "Shape type", 24+64+8+8, 0, 0, 10)
addParameter("Intensity", "Height intensity", 24+64+8+8+18, 100, 0, -1, true)
end
function apply()
tileSize = getTileSize()
mode = getValue(0, 0, 0, 1)
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
value = 0
if mode==0 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
d = math.sqrt(dx*dx+dy*dy)
value = math.min(1.0, (d/(tileSize/2.0)))
value = 1.0-value*value
end
if mode==1 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
d = math.abs(dx)+math.abs(dy)
value = 1.0-math.min(1.0, (d/(tileSize/2.0)))
end
if mode==2 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
d = math.max(math.abs(dx), math.abs(dy))
value = 1.0-math.min(1.0, (d/(tileSize/2.0)))
end
if mode==3 then
value = 1.0-(y/tileSize)
end
if mode==4 then
value = x/tileSize
end
if mode==5 then
value = y/tileSize
end
if mode==6 then
value = 1.0-(x/tileSize)
end
--thanks to rerere284 for the following four modes
if mode==7 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
rot = math.atan2(dy, dx)*180/math.pi
if rot<0 then
rot = rot+360;
end
value = rot/360.0
end
if mode==8 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
rot = math.atan2(dy, dx)*180/math.pi-90
if rot<0 then
rot = rot+360;
end
value = rot/360.0
end
if mode==9 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
rot = math.atan2(dy, dx)*180/math.pi+180
if rot<0 then
rot = rot+360;
end
value = rot/360.0
end
if mode==10 then
dx = x-tileSize/2.0
dy = y-tileSize/2.0
rot = math.atan2(dy, dx)*180/math.pi+90
if rot<0 then
rot = rot+360;
end
value = rot/360.0
end
value = value*getValue(1, 0, 0, 100.0)
setPixel(0, x, y, value, value, value)
end
end