git.s-ol.nu watch-cad / 687bd8a
a touch of color s-ol 3 years ago
4 changed file(s) with 42 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
11
22 import vec2, bound2 from require 'cpml'
33 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!
411
512 random =
613 point: ->
3845 mx, my = (pos - hs)\unpack!
3946 Mx, My = (pos + hs)\unpack!
4047
41 lg.setColor 1, 1, 1
4248 lg.line mx, my, Mx, My
4349 lg.line mx, My, Mx, my
4450
4551 hit.radius2 pos, hs\len2!
4652
4753 line: (frm, to) ->
48 lg.setColor 1, 1, 1
4954 lg.line frm.x, frm.y, to.x, to.y
5055
5156 hit.line frm, to
6166 rect: (min, max) ->
6267 x, y = min\unpack!
6368 w, h = (max - min)\unpack!
64 lg.setColor 1, 1, 1
6569 lg.rectangle 'line', x, y, w, h
6670
6771 hit.rect min, max
6872
6973 circle: (center, r) ->
7074 x, y = center\unpack!
71 lg.setColor 1, 1, 1
7275 lg.circle 'line', x, y, r
7376
7477 hit.radius2 center, r*r
210213 table.remove selection, to_remove[i]
211214
212215 op =
213 move: (obj, to) ->
216 move: pushpop (obj, to) ->
214217 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
216237
217238 {
218239 :hit
1414 local r = (i % 2 == 0) and inner.radius or outer.radius
1515 local pos = inner.center + vec2.from_cartesian(r, step * i)
1616
17 draw.cross(pos)
17 op.add(pos, vec2(20, 20))
1818 draw.line(pos, lag)
19
20 -- obj = Object("object_"..i, pos, vec2(20, 20))
21 -- op.add(obj)
2219
2320 lag = pos
2421 end
00 import vec2 from require 'cpml'
1 import random, hit, draw from require 'api'
1 -- import random, hit, draw from require 'api'
22
33 class Object
44 new: (@pos=random.point!, @size=random.size!) =>
5
6 copy: => Object @pos, @size
57
68 minmax: =>
79 @pos - @size/2, @pos + @size/2
6969 FONTSIZE = 20
7070 new: (scriptfile) =>
7171 @objects = {}
72 for i=1,4
73 print
74 -- table.insert @objects, Object nil, random.size!/8
7572
7673 if scriptfile
7774 @script = Script scriptfile
8481 when 'quit'
8582 love.event.quit!
8683 when 'run'
87 @script = Script command\match '^run%s+(.+)'
84 arg = command\match '^run%s+(.+)'
85 @script = arg and Script arg
8886
8987 frame: =>
88 lg.setColor 1, 1, 1
9089 for obj in *@objects
9190 obj\draw!
9291
9796 lg.setFont @font
9897
9998 if @script
99 lg.setColor .5, .5, .5
100 depth = lg.getStackDepth!
101
100102 @script\reload_and_run!
101103
102104 if INPUT\key_down 'space'
103105 @script\commit!
104106 STATE\reset!
107
108 while lg.getStackDepth! > depth
109 lg.pop!
105110
111 lg.setColor 1, 1, 1
106112 lg.print "script: #{@script.file}", 10, 10
107113
108114 if (INPUT\key_down ':') or (INPUT\key_down ';') and INPUT\key_held 'lshift'
110116 @ex = true
111117
112118 if @ex
119 lg.setColor 1, 1, 1
113120 lg.print ":#{INPUT.text}", 10, h - 10 - FONTSIZE
114121
115122 apply = INPUT\key_down 'return'