git.s-ol.nu watch-cad / master
more examples s-ol 11 hours ago
3 changed file(s) with 28 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1 import vec2 from require 'cpml'
2
3 =>
4 -- draw helper lines
5 origin = vec2 200, 600
6 draw.line origin, vec2 200, 0
7 draw.line origin, vec2 1000, 600
8
9 -- input two points
10 input.line @l, { x: 200 }, { y: 600 }
11
12 -- restrict to first quadrant
13 if @l!.frm.y > 600
14 @l!.frm.y = 600
15
16 if @l!.to.x < 200
17 @l!.to.x = 200
1 -- return function (state)
2 function place_in_rect(S)
1 function place_on_line(S)
32 input.selection(S.objs, '^led-')
43 input.line(S.dest)
54
1 =>
2 input.selection @objs
3 input.line @dest
4
5 dest = @dest!
6 step = (dest.to - dest.frm) / #@objs!
7
8 for i, obj in ipairs @objs!
9 pos = dest.frm + step * (i - .5)
10 op.move obj, pos