最終更新 1732421040

capitalex's Avatar capitalex revised this gist 1732421039. Go to revision

1 file changed, 215 insertions

cooler-draw.nv(file created)

@@ -0,0 +1,215 @@
1 + |#| constant, @sleep, 60
2 + |#| constant, @line x1, 10
3 + |#| constant, @line y1, 10
4 + |#| constant, @line x2, 30
5 + |#| constant, @line y2, 10
6 + |#| constant, @pixel r, 255
7 + |#| constant, @pixel g, 255
8 + |#| constant, @pixel b, 255
9 + |#| constant, @pixel r, 87
10 + |#| constant, @pixel g, 87
11 + |#| constant, @pixel b, 87
12 + |#| constant, @pixel r, 219
13 + |#| constant, @pixel b, 12
14 + |#| constant, clear @pixel r, 255
15 + |#| constant, clear @pixel g, 255
16 + |#| constant, clear @pixel b, 255
17 + |#| constant, clear old mouse x, 1000000
18 + |#| constant, clear old mouse y, 1000000
19 + |#| constant, current mouse x -> old mouse x, 1000000
20 + |#| constant, current mouse y -> old mouse y, 1000000
21 + |#| constant, @mouse x -> current mouse x, 1000000
22 + |#| constant, @mouse y -> current mouse y, 1000000
23 + |#| constant, copy old mouse x -> @line x1, 1000000
24 + |#| constant, copy old mouse y -> @line y1, 1000000
25 + |#| constant, copy current mouse x -> @line x2, 1000000
26 + |#| constant, copy current mouse y -> @line y2, 1000000
27 +
28 + |clear pixel color|
29 + , clear @pixel r:255
30 + , clear @pixel g:255
31 + , clear @pixel b:255
32 +
33 + |clear @pixel r, @pixel r| |clear @pixel g, @pixel g| |clear @pixel b, @pixel b|
34 + |clear @pixel r| |clear @pixel g| |clear @pixel b|
35 +
36 + |clear old mouse x, old mouse x| |clear old mouse x|
37 + |clear old mouse y, old mouse y| |clear old mouse y|
38 +
39 + |current mouse x -> old mouse x, current mouse x| old mouse x
40 + |current mouse y -> old mouse y, current mouse y| old mouse y
41 +
42 + |current mouse x -> old mouse x| |current mouse y -> old mouse y|
43 +
44 + |@mouse x -> current mouse x, @mouse x| current mouse x
45 + |@mouse y -> current mouse y, @mouse y| current mouse y
46 +
47 + |@mouse x -> current mouse x| |@mouse y -> current mouse y|
48 +
49 + |copy old mouse x -> @line x1, old mouse x|
50 + , used old mouse x, @line x1
51 +
52 + |copy old mouse y -> @line y1, old mouse y|
53 + , used old mouse y, @line y1
54 +
55 + |copy current mouse x -> @line x2, current mouse x|
56 + , used current mouse x, @line x2
57 +
58 + |copy current mouse y -> @line y2, current mouse y|
59 + , used current mouse y, @line y2
60 +
61 + |copy old mouse x -> @line x1| |copy old mouse y -> @line y1|
62 + |copy current mouse x -> @line x2| |copy current mouse y -> @line y2|
63 +
64 + |used old mouse x| old mouse x
65 + |used old mouse y| old mouse y
66 + |used current mouse x| current mouse x
67 + |used current mouse y| current mouse y
68 +
69 + |clear old mouse position|
70 + , clear old mouse x:1000000
71 + , clear old mouse y:1000000
72 +
73 + |move current mouse position to old mouse position|
74 + , current mouse x -> old mouse x:1000000
75 + , current mouse y -> old mouse y:1000000
76 +
77 + |move @mouse position to current mouse position|
78 + , @mouse x -> current mouse x:1000000
79 + , @mouse y -> current mouse y:1000000
80 +
81 + |update mouse position|
82 + , @mouse position
83 + , clear old mouse position
84 + , move current mouse position to old mouse position
85 + , move @mouse position to current mouse position
86 +
87 + |check if mouse button 1 is down, find brush mode|
88 + , @mouse is down
89 + , @mouse button
90 + , checking button 1
91 +
92 + |check if mouse button 2 is down, find brush mode|
93 + , @mouse is down
94 + , @mouse button, @mouse button
95 + , checking button 2
96 +
97 + |check if mouse button 3 is down, find brush mode|
98 + , @mouse is down
99 + , @mouse button, @mouse button, @mouse button
100 + , checking button 3
101 +
102 + |checking button 1, @mouse button is down|
103 + brush is drawing
104 +
105 + |checking button 2, @mouse button is down|
106 + brush is erasing
107 +
108 + |checking button 3, @mouse button is down|
109 + brush is drawing red
110 +
111 + |checking button 3| find brush mode
112 + |checking button 2| find brush mode
113 + |checking button 1| find brush mode
114 + |find brush mode|
115 +
116 + |check if mouse button is down|
117 + , find brush mode
118 + , check if mouse button 1 is down
119 + , check if mouse button 2 is down
120 + , check if mouse button 3 is down
121 +
122 + |set line color, current color is 1|
123 + , current color is 1
124 + , @pixel r:255
125 + , @pixel g:255
126 + , @pixel b:255
127 +
128 + |set line color, current color is 2|
129 + , current color is 2
130 + , @pixel r:87
131 + , @pixel g:87
132 + , @pixel b:87
133 +
134 + |set line color, current color is 3|
135 + , current color is 3
136 + , @pixel r:219
137 + , @pixel b:12
138 +
139 + |set line color, current color is 4|
140 + current color is 4
141 +
142 + |set line position|
143 + , copy old mouse x -> @line x1:1000000
144 + , copy old mouse y -> @line y1:1000000
145 + , copy current mouse x -> @line x2:1000000
146 + , copy current mouse y -> @line y2:1000000
147 +
148 + |draw the line| @draw line
149 +
150 + |plot line|
151 + , set line position
152 + , draw the line
153 +
154 + |draw a line, brush is drawing|
155 + , clear pixel color
156 + , set line color
157 + , plot line
158 +
159 + |draw a line, brush is erasing|
160 + , clear pixel color
161 + , plot line
162 +
163 + |draw a line|
164 +
165 + |check for color change|
166 + , update color
167 + , @mouse wheel
168 +
169 + |update color, @mouse wheel +y| next color
170 +
171 + |update color, @mouse wheel -y| previous color
172 +
173 + |current color is 1, next color| current color is 2
174 + |current color is 2, next color| current color is 3
175 + |current color is 3, next color| current color is 4
176 + |current color is 4, next color| current color is 1
177 +
178 + |current color is 1, previous color| current color is 4
179 + |current color is 2, previous color| current color is 1
180 + |current color is 3, previous color| current color is 2
181 + |current color is 4, previous color| current color is 3
182 +
183 + |@mouse wheel +y| |@mouse wheel -y|
184 +
185 + |update|
186 + , update mouse position
187 + , check if mouse button is down
188 + , draw a line
189 +
190 + |poll inputs|
191 + @poll inputs
192 +
193 + |draw brush color|
194 + , set line color
195 + , @line x1:10, @line x2:30
196 + , @line y1:10, @line y2:10
197 + , draw the line
198 +
199 + |display|
200 + @display
201 +
202 + |sleep|
203 + @sleep:16
204 +
205 +
206 + |main loop|
207 + , poll inputs
208 + , check for color change
209 + , update
210 + , draw brush color
211 + , display
212 + , sleep
213 + , main loop
214 +
215 + || current color is 1, main loop

capitalex's Avatar capitalex revised this gist 1732415149. Go to revision

1 file changed, 0 insertions, 0 deletions

draw.generated.lua renamed to zz.draw.generated.lua

File renamed without changes

capitalex's Avatar capitalex revised this gist 1732415118. Go to revision

1 file changed, 356 insertions

draw.generated.lua(file created)

@@ -0,0 +1,356 @@
1 + local min, max, huge = math.min, math.max, math.huge
2 + return function(counters)
3 + if counters["@sleep:60"] > 0 then
4 + local acc = huge
5 + acc = min(acc, counters["@sleep:60"])
6 + counters["@sleep:60"] = max(counters["@sleep:60"] - acc, 0)
7 + counters["@sleep"] = counters["@sleep"] + acc * 60
8 + return true
9 + elseif counters["@pixel r:255"] > 0 then
10 + local acc = huge
11 + acc = min(acc, counters["@pixel r:255"])
12 + counters["@pixel r:255"] = max(counters["@pixel r:255"] - acc, 0)
13 + counters["@pixel r"] = counters["@pixel r"] + acc * 255
14 + return true
15 + elseif counters["@pixel g:255"] > 0 then
16 + local acc = huge
17 + acc = min(acc, counters["@pixel g:255"])
18 + counters["@pixel g:255"] = max(counters["@pixel g:255"] - acc, 0)
19 + counters["@pixel g"] = counters["@pixel g"] + acc * 255
20 + return true
21 + elseif counters["@pixel b:255"] > 0 then
22 + local acc = huge
23 + acc = min(acc, counters["@pixel b:255"])
24 + counters["@pixel b:255"] = max(counters["@pixel b:255"] - acc, 0)
25 + counters["@pixel b"] = counters["@pixel b"] + acc * 255
26 + return true
27 + elseif counters["clear old mouse x:1000000"] > 0 then
28 + local acc = huge
29 + acc = min(acc, counters["clear old mouse x:1000000"])
30 + counters["clear old mouse x:1000000"] = max(counters["clear old mouse x:1000000"] - acc, 0)
31 + counters["clear old mouse x"] = counters["clear old mouse x"] + acc * 1000000
32 + return true
33 + elseif counters["clear old mouse y:1000000"] > 0 then
34 + local acc = huge
35 + acc = min(acc, counters["clear old mouse y:1000000"])
36 + counters["clear old mouse y:1000000"] = max(counters["clear old mouse y:1000000"] - acc, 0)
37 + counters["clear old mouse y"] = counters["clear old mouse y"] + acc * 1000000
38 + return true
39 + elseif counters["current mouse x -> old mouse x:1000000"] > 0 then
40 + local acc = huge
41 + acc = min(acc, counters["current mouse x -> old mouse x:1000000"])
42 + counters["current mouse x -> old mouse x:1000000"] = max(counters["current mouse x -> old mouse x:1000000"] - acc, 0)
43 + counters["current mouse x -> old mouse x"] = counters["current mouse x -> old mouse x"] + acc * 1000000
44 + return true
45 + elseif counters["current mouse y -> old mouse y:1000000"] > 0 then
46 + local acc = huge
47 + acc = min(acc, counters["current mouse y -> old mouse y:1000000"])
48 + counters["current mouse y -> old mouse y:1000000"] = max(counters["current mouse y -> old mouse y:1000000"] - acc, 0)
49 + counters["current mouse y -> old mouse y"] = counters["current mouse y -> old mouse y"] + acc * 1000000
50 + return true
51 + elseif counters["@mouse x -> current mouse x:1000000"] > 0 then
52 + local acc = huge
53 + acc = min(acc, counters["@mouse x -> current mouse x:1000000"])
54 + counters["@mouse x -> current mouse x:1000000"] = max(counters["@mouse x -> current mouse x:1000000"] - acc, 0)
55 + counters["@mouse x -> current mouse x"] = counters["@mouse x -> current mouse x"] + acc * 1000000
56 + return true
57 + elseif counters["@mouse y -> current mouse y:1000000"] > 0 then
58 + local acc = huge
59 + acc = min(acc, counters["@mouse y -> current mouse y:1000000"])
60 + counters["@mouse y -> current mouse y:1000000"] = max(counters["@mouse y -> current mouse y:1000000"] - acc, 0)
61 + counters["@mouse y -> current mouse y"] = counters["@mouse y -> current mouse y"] + acc * 1000000
62 + return true
63 + elseif counters["copy old mouse x -> @line x1:1000000"] > 0 then
64 + local acc = huge
65 + acc = min(acc, counters["copy old mouse x -> @line x1:1000000"])
66 + counters["copy old mouse x -> @line x1:1000000"] = max(counters["copy old mouse x -> @line x1:1000000"] - acc, 0)
67 + counters["copy old mouse x -> @line x1"] = counters["copy old mouse x -> @line x1"] + acc * 1000000
68 + return true
69 + elseif counters["copy old mouse y -> @line y1:1000000"] > 0 then
70 + local acc = huge
71 + acc = min(acc, counters["copy old mouse y -> @line y1:1000000"])
72 + counters["copy old mouse y -> @line y1:1000000"] = max(counters["copy old mouse y -> @line y1:1000000"] - acc, 0)
73 + counters["copy old mouse y -> @line y1"] = counters["copy old mouse y -> @line y1"] + acc * 1000000
74 + return true
75 + elseif counters["copy current mouse x -> @line x2:1000000"] > 0 then
76 + local acc = huge
77 + acc = min(acc, counters["copy current mouse x -> @line x2:1000000"])
78 + counters["copy current mouse x -> @line x2:1000000"] = max(counters["copy current mouse x -> @line x2:1000000"] - acc, 0)
79 + counters["copy current mouse x -> @line x2"] = counters["copy current mouse x -> @line x2"] + acc * 1000000
80 + return true
81 + elseif counters["copy current mouse y -> @line y2:1000000"] > 0 then
82 + local acc = huge
83 + acc = min(acc, counters["copy current mouse y -> @line y2:1000000"])
84 + counters["copy current mouse y -> @line y2:1000000"] = max(counters["copy current mouse y -> @line y2:1000000"] - acc, 0)
85 + counters["copy current mouse y -> @line y2"] = counters["copy current mouse y -> @line y2"] + acc * 1000000
86 + return true
87 + elseif counters["clear old mouse x"] > 0 and counters["old mouse x"] > 0 then
88 + local acc = huge
89 + acc = min(acc, counters["clear old mouse x"])
90 + acc = min(acc, counters["old mouse x"])
91 + counters["clear old mouse x"] = max(counters["clear old mouse x"] - acc, 0)
92 + counters["old mouse x"] = max(counters["old mouse x"] - acc, 0)
93 + return true
94 + elseif counters["clear old mouse x"] > 0 then
95 + local acc = huge
96 + acc = min(acc, counters["clear old mouse x"])
97 + counters["clear old mouse x"] = max(counters["clear old mouse x"] - acc, 0)
98 + return true
99 + elseif counters["clear old mouse y"] > 0 and counters["old mouse y"] > 0 then
100 + local acc = huge
101 + acc = min(acc, counters["old mouse y"])
102 + acc = min(acc, counters["clear old mouse y"])
103 + counters["clear old mouse y"] = max(counters["clear old mouse y"] - acc, 0)
104 + counters["old mouse y"] = max(counters["old mouse y"] - acc, 0)
105 + return true
106 + elseif counters["clear old mouse y"] > 0 then
107 + local acc = huge
108 + acc = min(acc, counters["clear old mouse y"])
109 + counters["clear old mouse y"] = max(counters["clear old mouse y"] - acc, 0)
110 + return true
111 + elseif counters["current mouse x -> old mouse x"] > 0 and counters["current mouse x"] > 0 then
112 + local acc = huge
113 + acc = min(acc, counters["current mouse x -> old mouse x"])
114 + acc = min(acc, counters["current mouse x"])
115 + counters["current mouse x -> old mouse x"] = max(counters["current mouse x -> old mouse x"] - acc, 0)
116 + counters["current mouse x"] = max(counters["current mouse x"] - acc, 0)
117 + counters["old mouse x"] = counters["old mouse x"] + acc * 1
118 + return true
119 + elseif counters["current mouse y -> old mouse y"] > 0 and counters["current mouse y"] > 0 then
120 + local acc = huge
121 + acc = min(acc, counters["current mouse y"])
122 + acc = min(acc, counters["current mouse y -> old mouse y"])
123 + counters["current mouse y -> old mouse y"] = max(counters["current mouse y -> old mouse y"] - acc, 0)
124 + counters["current mouse y"] = max(counters["current mouse y"] - acc, 0)
125 + counters["old mouse y"] = counters["old mouse y"] + acc * 1
126 + return true
127 + elseif counters["current mouse x -> old mouse x"] > 0 then
128 + local acc = huge
129 + acc = min(acc, counters["current mouse x -> old mouse x"])
130 + counters["current mouse x -> old mouse x"] = max(counters["current mouse x -> old mouse x"] - acc, 0)
131 + return true
132 + elseif counters["current mouse y -> old mouse y"] > 0 then
133 + local acc = huge
134 + acc = min(acc, counters["current mouse y -> old mouse y"])
135 + counters["current mouse y -> old mouse y"] = max(counters["current mouse y -> old mouse y"] - acc, 0)
136 + return true
137 + elseif counters["@mouse x -> current mouse x"] > 0 and counters["@mouse x"] > 0 then
138 + local acc = huge
139 + acc = min(acc, counters["@mouse x -> current mouse x"])
140 + acc = min(acc, counters["@mouse x"])
141 + counters["@mouse x -> current mouse x"] = max(counters["@mouse x -> current mouse x"] - acc, 0)
142 + counters["@mouse x"] = max(counters["@mouse x"] - acc, 0)
143 + counters["current mouse x"] = counters["current mouse x"] + acc * 1
144 + return true
145 + elseif counters["@mouse y -> current mouse y"] > 0 and counters["@mouse y"] > 0 then
146 + local acc = huge
147 + acc = min(acc, counters["@mouse y"])
148 + acc = min(acc, counters["@mouse y -> current mouse y"])
149 + counters["@mouse y -> current mouse y"] = max(counters["@mouse y -> current mouse y"] - acc, 0)
150 + counters["@mouse y"] = max(counters["@mouse y"] - acc, 0)
151 + counters["current mouse y"] = counters["current mouse y"] + acc * 1
152 + return true
153 + elseif counters["@mouse x -> current mouse x"] > 0 then
154 + local acc = huge
155 + acc = min(acc, counters["@mouse x -> current mouse x"])
156 + counters["@mouse x -> current mouse x"] = max(counters["@mouse x -> current mouse x"] - acc, 0)
157 + return true
158 + elseif counters["@mouse y -> current mouse y"] > 0 then
159 + local acc = huge
160 + acc = min(acc, counters["@mouse y -> current mouse y"])
161 + counters["@mouse y -> current mouse y"] = max(counters["@mouse y -> current mouse y"] - acc, 0)
162 + return true
163 + elseif counters["copy old mouse x -> @line x1"] > 0 and counters["old mouse x"] > 0 then
164 + local acc = huge
165 + acc = min(acc, counters["copy old mouse x -> @line x1"])
166 + acc = min(acc, counters["old mouse x"])
167 + counters["copy old mouse x -> @line x1"] = max(counters["copy old mouse x -> @line x1"] - acc, 0)
168 + counters["old mouse x"] = max(counters["old mouse x"] - acc, 0)
169 + counters["used old mouse x"] = counters["used old mouse x"] + acc * 1
170 + counters["@line x1"] = counters["@line x1"] + acc * 1
171 + return true
172 + elseif counters["copy old mouse y -> @line y1"] > 0 and counters["old mouse y"] > 0 then
173 + local acc = huge
174 + acc = min(acc, counters["old mouse y"])
175 + acc = min(acc, counters["copy old mouse y -> @line y1"])
176 + counters["copy old mouse y -> @line y1"] = max(counters["copy old mouse y -> @line y1"] - acc, 0)
177 + counters["old mouse y"] = max(counters["old mouse y"] - acc, 0)
178 + counters["@line y1"] = counters["@line y1"] + acc * 1
179 + counters["used old mouse y"] = counters["used old mouse y"] + acc * 1
180 + return true
181 + elseif counters["copy current mouse x -> @line x2"] > 0 and counters["current mouse x"] > 0 then
182 + local acc = huge
183 + acc = min(acc, counters["copy current mouse x -> @line x2"])
184 + acc = min(acc, counters["current mouse x"])
185 + counters["copy current mouse x -> @line x2"] = max(counters["copy current mouse x -> @line x2"] - acc, 0)
186 + counters["current mouse x"] = max(counters["current mouse x"] - acc, 0)
187 + counters["used current mouse x"] = counters["used current mouse x"] + acc * 1
188 + counters["@line x2"] = counters["@line x2"] + acc * 1
189 + return true
190 + elseif counters["copy current mouse y -> @line y2"] > 0 and counters["current mouse y"] > 0 then
191 + local acc = huge
192 + acc = min(acc, counters["current mouse y"])
193 + acc = min(acc, counters["copy current mouse y -> @line y2"])
194 + counters["copy current mouse y -> @line y2"] = max(counters["copy current mouse y -> @line y2"] - acc, 0)
195 + counters["current mouse y"] = max(counters["current mouse y"] - acc, 0)
196 + counters["@line y2"] = counters["@line y2"] + acc * 1
197 + counters["used current mouse y"] = counters["used current mouse y"] + acc * 1
198 + return true
199 + elseif counters["copy old mouse x -> @line x1"] > 0 then
200 + local acc = huge
201 + acc = min(acc, counters["copy old mouse x -> @line x1"])
202 + counters["copy old mouse x -> @line x1"] = max(counters["copy old mouse x -> @line x1"] - acc, 0)
203 + return true
204 + elseif counters["copy old mouse y -> @line y1"] > 0 then
205 + local acc = huge
206 + acc = min(acc, counters["copy old mouse y -> @line y1"])
207 + counters["copy old mouse y -> @line y1"] = max(counters["copy old mouse y -> @line y1"] - acc, 0)
208 + return true
209 + elseif counters["copy current mouse x -> @line x2"] > 0 then
210 + local acc = huge
211 + acc = min(acc, counters["copy current mouse x -> @line x2"])
212 + counters["copy current mouse x -> @line x2"] = max(counters["copy current mouse x -> @line x2"] - acc, 0)
213 + return true
214 + elseif counters["copy current mouse y -> @line y2"] > 0 then
215 + local acc = huge
216 + acc = min(acc, counters["copy current mouse y -> @line y2"])
217 + counters["copy current mouse y -> @line y2"] = max(counters["copy current mouse y -> @line y2"] - acc, 0)
218 + return true
219 + elseif counters["used old mouse x"] > 0 then
220 + local acc = huge
221 + acc = min(acc, counters["used old mouse x"])
222 + counters["used old mouse x"] = max(counters["used old mouse x"] - acc, 0)
223 + counters["old mouse x"] = counters["old mouse x"] + acc * 1
224 + return true
225 + elseif counters["used old mouse y"] > 0 then
226 + local acc = huge
227 + acc = min(acc, counters["used old mouse y"])
228 + counters["used old mouse y"] = max(counters["used old mouse y"] - acc, 0)
229 + counters["old mouse y"] = counters["old mouse y"] + acc * 1
230 + return true
231 + elseif counters["used current mouse x"] > 0 then
232 + local acc = huge
233 + acc = min(acc, counters["used current mouse x"])
234 + counters["used current mouse x"] = max(counters["used current mouse x"] - acc, 0)
235 + counters["current mouse x"] = counters["current mouse x"] + acc * 1
236 + return true
237 + elseif counters["used current mouse y"] > 0 then
238 + local acc = huge
239 + acc = min(acc, counters["used current mouse y"])
240 + counters["used current mouse y"] = max(counters["used current mouse y"] - acc, 0)
241 + counters["current mouse y"] = counters["current mouse y"] + acc * 1
242 + return true
243 + elseif counters["clear old mouse position"] > 0 then
244 + local acc = huge
245 + acc = min(acc, counters["clear old mouse position"])
246 + counters["clear old mouse position"] = max(counters["clear old mouse position"] - acc, 0)
247 + counters["clear old mouse y:1000000"] = counters["clear old mouse y:1000000"] + acc * 1
248 + counters["clear old mouse x:1000000"] = counters["clear old mouse x:1000000"] + acc * 1
249 + return true
250 + elseif counters["move current mouse position to old mouse position"] > 0 then
251 + local acc = huge
252 + acc = min(acc, counters["move current mouse position to old mouse position"])
253 + counters["move current mouse position to old mouse position"] = max(counters["move current mouse position to old mouse position"] - acc, 0)
254 + counters["current mouse x -> old mouse x:1000000"] = counters["current mouse x -> old mouse x:1000000"] + acc * 1
255 + counters["current mouse y -> old mouse y:1000000"] = counters["current mouse y -> old mouse y:1000000"] + acc * 1
256 + return true
257 + elseif counters["move @mouse position to current mouse position"] > 0 then
258 + local acc = huge
259 + acc = min(acc, counters["move @mouse position to current mouse position"])
260 + counters["move @mouse position to current mouse position"] = max(counters["move @mouse position to current mouse position"] - acc, 0)
261 + counters["@mouse y -> current mouse y:1000000"] = counters["@mouse y -> current mouse y:1000000"] + acc * 1
262 + counters["@mouse x -> current mouse x:1000000"] = counters["@mouse x -> current mouse x:1000000"] + acc * 1
263 + return true
264 + elseif counters["update mouse position"] > 0 then
265 + local acc = huge
266 + acc = min(acc, counters["update mouse position"])
267 + counters["update mouse position"] = max(counters["update mouse position"] - acc, 0)
268 + counters["move @mouse position to current mouse position"] = counters["move @mouse position to current mouse position"] + acc * 1
269 + counters["@mouse position"] = counters["@mouse position"] + acc * 1
270 + counters["clear old mouse position"] = counters["clear old mouse position"] + acc * 1
271 + counters["move current mouse position to old mouse position"] = counters["move current mouse position to old mouse position"] + acc * 1
272 + return true
273 + elseif counters["check if mouse button is down"] > 0 then
274 + local acc = huge
275 + acc = min(acc, counters["check if mouse button is down"])
276 + counters["check if mouse button is down"] = max(counters["check if mouse button is down"] - acc, 0)
277 + counters["@mouse is down"] = counters["@mouse is down"] + acc * 1
278 + counters["@mouse button"] = counters["@mouse button"] + acc * 1
279 + return true
280 + elseif counters["set line to white"] > 0 then
281 + local acc = huge
282 + acc = min(acc, counters["set line to white"])
283 + counters["set line to white"] = max(counters["set line to white"] - acc, 0)
284 + counters["@pixel b:255"] = counters["@pixel b:255"] + acc * 1
285 + counters["@pixel r:255"] = counters["@pixel r:255"] + acc * 1
286 + counters["@pixel g:255"] = counters["@pixel g:255"] + acc * 1
287 + return true
288 + elseif counters["set line position"] > 0 then
289 + local acc = huge
290 + acc = min(acc, counters["set line position"])
291 + counters["set line position"] = max(counters["set line position"] - acc, 0)
292 + counters["copy current mouse x -> @line x2:1000000"] = counters["copy current mouse x -> @line x2:1000000"] + acc * 1
293 + counters["copy current mouse y -> @line y2:1000000"] = counters["copy current mouse y -> @line y2:1000000"] + acc * 1
294 + counters["copy old mouse x -> @line x1:1000000"] = counters["copy old mouse x -> @line x1:1000000"] + acc * 1
295 + counters["copy old mouse y -> @line y1:1000000"] = counters["copy old mouse y -> @line y1:1000000"] + acc * 1
296 + return true
297 + elseif counters["draw the line"] > 0 then
298 + local acc = huge
299 + acc = min(acc, counters["draw the line"])
300 + counters["draw the line"] = max(counters["draw the line"] - acc, 0)
301 + counters["@draw line"] = counters["@draw line"] + acc * 1
302 + return true
303 + elseif counters["draw a line"] > 0 and counters["@mouse button is down"] > 0 then
304 + local acc = huge
305 + acc = min(acc, counters["@mouse button is down"])
306 + acc = min(acc, counters["draw a line"])
307 + counters["draw a line"] = max(counters["draw a line"] - acc, 0)
308 + counters["@mouse button is down"] = max(counters["@mouse button is down"] - acc, 0)
309 + counters["set line position"] = counters["set line position"] + acc * 1
310 + counters["draw the line"] = counters["draw the line"] + acc * 1
311 + counters["set line to white"] = counters["set line to white"] + acc * 1
312 + return true
313 + elseif counters["draw a line"] > 0 then
314 + local acc = huge
315 + acc = min(acc, counters["draw a line"])
316 + counters["draw a line"] = max(counters["draw a line"] - acc, 0)
317 + return true
318 + elseif counters["update"] > 0 then
319 + local acc = huge
320 + acc = min(acc, counters["update"])
321 + counters["update"] = max(counters["update"] - acc, 0)
322 + counters["check if mouse button is down"] = counters["check if mouse button is down"] + acc * 1
323 + counters["draw a line"] = counters["draw a line"] + acc * 1
324 + counters["update mouse position"] = counters["update mouse position"] + acc * 1
325 + return true
326 + elseif counters["poll inputs"] > 0 then
327 + local acc = huge
328 + acc = min(acc, counters["poll inputs"])
329 + counters["poll inputs"] = max(counters["poll inputs"] - acc, 0)
330 + counters["@poll inputs"] = counters["@poll inputs"] + acc * 1
331 + return true
332 + elseif counters["draw"] > 0 then
333 + local acc = huge
334 + acc = min(acc, counters["draw"])
335 + counters["draw"] = max(counters["draw"] - acc, 0)
336 + counters["@display"] = counters["@display"] + acc * 1
337 + return true
338 + elseif counters["sleep"] > 0 then
339 + local acc = huge
340 + acc = min(acc, counters["sleep"])
341 + counters["sleep"] = max(counters["sleep"] - acc, 0)
342 + counters["@sleep:16"] = counters["@sleep:16"] + acc * 1
343 + return true
344 + elseif counters["main loop"] > 0 then
345 + local acc = huge
346 + acc = min(acc, counters["main loop"])
347 + counters["main loop"] = max(counters["main loop"] - acc, 0)
348 + counters["poll inputs"] = counters["poll inputs"] + acc * 1
349 + counters["draw"] = counters["draw"] + acc * 1
350 + counters["sleep"] = counters["sleep"] + acc * 1
351 + counters["update"] = counters["update"] + acc * 1
352 + counters["main loop"] = counters["main loop"] + acc * 1
353 + return true
354 + end
355 + return false
356 + end

capitalex's Avatar capitalex revised this gist 1732414981. Go to revision

1 file changed, 112 insertions

draw.nv(file created)

@@ -0,0 +1,112 @@
1 + |#| constant, @sleep, 60
2 + |#| constant, @pixel r, 255
3 + |#| constant, @pixel g, 255
4 + |#| constant, @pixel b, 255
5 + |#| constant, clear old mouse x, 1000000
6 + |#| constant, clear old mouse y, 1000000
7 + |#| constant, current mouse x -> old mouse x, 1000000
8 + |#| constant, current mouse y -> old mouse y, 1000000
9 + |#| constant, @mouse x -> current mouse x, 1000000
10 + |#| constant, @mouse y -> current mouse y, 1000000
11 + |#| constant, copy old mouse x -> @line x1, 1000000
12 + |#| constant, copy old mouse y -> @line y1, 1000000
13 + |#| constant, copy current mouse x -> @line x2, 1000000
14 + |#| constant, copy current mouse y -> @line y2, 1000000
15 +
16 + |clear old mouse x, old mouse x| |clear old mouse x|
17 + |clear old mouse y, old mouse y| |clear old mouse y|
18 +
19 + |current mouse x -> old mouse x, current mouse x| old mouse x
20 + |current mouse y -> old mouse y, current mouse y| old mouse y
21 +
22 + |current mouse x -> old mouse x| |current mouse y -> old mouse y|
23 +
24 + |@mouse x -> current mouse x, @mouse x| current mouse x
25 + |@mouse y -> current mouse y, @mouse y| current mouse y
26 +
27 + |@mouse x -> current mouse x| |@mouse y -> current mouse y|
28 +
29 + |copy old mouse x -> @line x1, old mouse x|
30 + , used old mouse x, @line x1
31 +
32 + |copy old mouse y -> @line y1, old mouse y|
33 + , used old mouse y, @line y1
34 +
35 + |copy current mouse x -> @line x2, current mouse x|
36 + , used current mouse x, @line x2
37 +
38 + |copy current mouse y -> @line y2, current mouse y|
39 + , used current mouse y, @line y2
40 +
41 + |copy old mouse x -> @line x1| |copy old mouse y -> @line y1|
42 + |copy current mouse x -> @line x2| |copy current mouse y -> @line y2|
43 +
44 + |used old mouse x| old mouse x
45 + |used old mouse y| old mouse y
46 + |used current mouse x| current mouse x
47 + |used current mouse y| current mouse y
48 +
49 + |clear old mouse position|
50 + , clear old mouse x:1000000
51 + , clear old mouse y:1000000
52 +
53 + |move current mouse position to old mouse position|
54 + , current mouse x -> old mouse x:1000000
55 + , current mouse y -> old mouse y:1000000
56 +
57 + |move @mouse position to current mouse position|
58 + , @mouse x -> current mouse x:1000000
59 + , @mouse y -> current mouse y:1000000
60 +
61 + |update mouse position|
62 + , @mouse position
63 + , clear old mouse position
64 + , move current mouse position to old mouse position
65 + , move @mouse position to current mouse position
66 +
67 + |check if mouse button is down|
68 + , @mouse is down
69 + , @mouse button
70 +
71 + |set line to white|
72 + , @pixel r:255
73 + , @pixel g:255
74 + , @pixel b:255
75 +
76 + |set line position|
77 + , copy old mouse x -> @line x1:1000000
78 + , copy old mouse y -> @line y1:1000000
79 + , copy current mouse x -> @line x2:1000000
80 + , copy current mouse y -> @line y2:1000000
81 +
82 + |draw the line| @draw line
83 +
84 + |draw a line, @mouse button is down|
85 + , set line to white
86 + , set line position
87 + , draw the line
88 +
89 + |draw a line|
90 +
91 + |update|
92 + , update mouse position
93 + , check if mouse button is down
94 + , draw a line
95 +
96 + |poll inputs|
97 + @poll inputs
98 +
99 + |draw|
100 + @display
101 +
102 + |sleep|
103 + @sleep:16
104 +
105 + |main loop|
106 + , poll inputs
107 + , update
108 + , draw
109 + , sleep
110 + , main loop
111 +
112 + || main loop
Newer Older