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