a touch of color
s-ol
3 years ago
1 | 1 |
|
2 | 2 |
import vec2, bound2 from require 'cpml'
|
3 | 3 |
import is_once, is_live, are_live, Once from require 'state'
|
|
4 |
import Object from require 'object'
|
|
5 |
|
|
6 |
pushpop = (fn) ->
|
|
7 |
(...) ->
|
|
8 |
lg.push 'all'
|
|
9 |
with fn ...
|
|
10 |
lg.pop!
|
4 | 11 |
|
5 | 12 |
random =
|
6 | 13 |
point: ->
|
|
38 | 45 |
mx, my = (pos - hs)\unpack!
|
39 | 46 |
Mx, My = (pos + hs)\unpack!
|
40 | 47 |
|
41 | |
lg.setColor 1, 1, 1
|
42 | 48 |
lg.line mx, my, Mx, My
|
43 | 49 |
lg.line mx, My, Mx, my
|
44 | 50 |
|
45 | 51 |
hit.radius2 pos, hs\len2!
|
46 | 52 |
|
47 | 53 |
line: (frm, to) ->
|
48 | |
lg.setColor 1, 1, 1
|
49 | 54 |
lg.line frm.x, frm.y, to.x, to.y
|
50 | 55 |
|
51 | 56 |
hit.line frm, to
|
|
61 | 66 |
rect: (min, max) ->
|
62 | 67 |
x, y = min\unpack!
|
63 | 68 |
w, h = (max - min)\unpack!
|
64 | |
lg.setColor 1, 1, 1
|
65 | 69 |
lg.rectangle 'line', x, y, w, h
|
66 | 70 |
|
67 | 71 |
hit.rect min, max
|
68 | 72 |
|
69 | 73 |
circle: (center, r) ->
|
70 | 74 |
x, y = center\unpack!
|
71 | |
lg.setColor 1, 1, 1
|
72 | 75 |
lg.circle 'line', x, y, r
|
73 | 76 |
|
74 | 77 |
hit.radius2 center, r*r
|
|
210 | 213 |
table.remove selection, to_remove[i]
|
211 | 214 |
|
212 | 215 |
op =
|
213 | |
move: (obj, to) ->
|
|
216 |
move: pushpop (obj, to) ->
|
214 | 217 |
draw.arrow obj.pos, to
|
215 | |
obj\draw!
|
|
218 |
|
|
219 |
lg.setColor .8, .8, 0
|
|
220 |
copy = obj\copy!
|
|
221 |
copy.pos = to
|
|
222 |
copy\draw!
|
|
223 |
|
|
224 |
if COMMIT
|
|
225 |
obj.pos = to
|
|
226 |
|
|
227 |
add: pushpop (pos, size) ->
|
|
228 |
tmp = Object pos, size
|
|
229 |
|
|
230 |
lg.setColor 0, .8, 0
|
|
231 |
tmp\draw!
|
|
232 |
|
|
233 |
if COMMIT
|
|
234 |
table.insert SESSION.objects, tmp
|
|
235 |
|
|
236 |
tmp
|
216 | 237 |
|
217 | 238 |
{
|
218 | 239 |
:hit
|
14 | 14 |
local r = (i % 2 == 0) and inner.radius or outer.radius
|
15 | 15 |
local pos = inner.center + vec2.from_cartesian(r, step * i)
|
16 | 16 |
|
17 | |
draw.cross(pos)
|
|
17 |
op.add(pos, vec2(20, 20))
|
18 | 18 |
draw.line(pos, lag)
|
19 | |
|
20 | |
-- obj = Object("object_"..i, pos, vec2(20, 20))
|
21 | |
-- op.add(obj)
|
22 | 19 |
|
23 | 20 |
lag = pos
|
24 | 21 |
end
|
0 | 0 |
import vec2 from require 'cpml'
|
1 | |
import random, hit, draw from require 'api'
|
|
1 |
-- import random, hit, draw from require 'api'
|
2 | 2 |
|
3 | 3 |
class Object
|
4 | 4 |
new: (@pos=random.point!, @size=random.size!) =>
|
|
5 |
|
|
6 |
copy: => Object @pos, @size
|
5 | 7 |
|
6 | 8 |
minmax: =>
|
7 | 9 |
@pos - @size/2, @pos + @size/2
|
69 | 69 |
FONTSIZE = 20
|
70 | 70 |
new: (scriptfile) =>
|
71 | 71 |
@objects = {}
|
72 | |
for i=1,4
|
73 | |
print
|
74 | |
-- table.insert @objects, Object nil, random.size!/8
|
75 | 72 |
|
76 | 73 |
if scriptfile
|
77 | 74 |
@script = Script scriptfile
|
|
84 | 81 |
when 'quit'
|
85 | 82 |
love.event.quit!
|
86 | 83 |
when 'run'
|
87 | |
@script = Script command\match '^run%s+(.+)'
|
|
84 |
arg = command\match '^run%s+(.+)'
|
|
85 |
@script = arg and Script arg
|
88 | 86 |
|
89 | 87 |
frame: =>
|
|
88 |
lg.setColor 1, 1, 1
|
90 | 89 |
for obj in *@objects
|
91 | 90 |
obj\draw!
|
92 | 91 |
|
|
97 | 96 |
lg.setFont @font
|
98 | 97 |
|
99 | 98 |
if @script
|
|
99 |
lg.setColor .5, .5, .5
|
|
100 |
depth = lg.getStackDepth!
|
|
101 |
|
100 | 102 |
@script\reload_and_run!
|
101 | 103 |
|
102 | 104 |
if INPUT\key_down 'space'
|
103 | 105 |
@script\commit!
|
104 | 106 |
STATE\reset!
|
|
107 |
|
|
108 |
while lg.getStackDepth! > depth
|
|
109 |
lg.pop!
|
105 | 110 |
|
|
111 |
lg.setColor 1, 1, 1
|
106 | 112 |
lg.print "script: #{@script.file}", 10, 10
|
107 | 113 |
|
108 | 114 |
if (INPUT\key_down ':') or (INPUT\key_down ';') and INPUT\key_held 'lshift'
|
|
110 | 116 |
@ex = true
|
111 | 117 |
|
112 | 118 |
if @ex
|
|
119 |
lg.setColor 1, 1, 1
|
113 | 120 |
lg.print ":#{INPUT.text}", 10, h - 10 - FONTSIZE
|
114 | 121 |
|
115 | 122 |
apply = INPUT\key_down 'return'
|