git.s-ol.nu watch-cad / 670fa39
move examples to library folder s-ol 2 years ago
18 changed file(s) with 184 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
151151
152152 frm, to = @frm!, @to!
153153 @set :frm, :to
154 draw.line frm, to
154 draw.arrow frm, to
155155
156156 rect: do
157157 meta = size: => @max - @min
235235
236236 tmp
237237
238 remove: pushpop (obj) ->
239 lg.setColor .8, 0, 0
240 copy = obj\copy!
241 copy\draw!
242
243 if COMMIT
244 SESSION.objects = [o for o in *SESSION.objects when o != obj]
245
246 copy: pushpop (obj, pos) ->
247 lg.setColor 0, .8, 0
248 copy = obj\copy!
249 copy.pos = pos
250 copy\draw!
251
252 if COMMIT
253 table.insert SESSION.objects, copy
254
255 copy
256
238257 {
239258 :hit
240259 :random
+0
-17
examples/axis_lock.moon less more
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
-25
examples/capsule.moon less more
0 -- let's load a vector library for doing some
1 -- more interesting transformations
2
3 import vec2 from require 'cpml'
4
5 =>
6 -- let's try to construct a pill-shape
7 input.rect @rect
8 rect = @rect!
9 hsize = (rect.max - rect.min) / 2
10
11 input.circle @left, {
12 center: rect.min + vec2 0, hsize.y
13 radius: hsize.y
14 }
15 input.circle @left, {
16 center: rect.min + vec2 hsize.x*2, hsize.y
17 radius: hsize.y
18 }
19
20 -- right, so that's that....
21 -- kinda forgetting whether there was something
22 -- else I wanted to show.
23 -- does this seem interesting to you?
24 -- let me know :)
+0
-25
examples/create_star.lua less more
0 local vec2 = (require 'cpml').vec2
1
2 function draw_star(S)
3 input.circle(S.inner)
4 input.circle(S.outer, { center = S.inner().center })
5
6 local inner, outer = S.inner(), S.outer()
7
8 input.slider(S.cnt, 2, 20)
9
10 local cnt = math.floor(S.cnt()) * 2
11 local step = 2*math.pi/cnt
12 local lag = inner.center + vec2(inner.radius, 0)
13 for i = 0, cnt do
14 local r = (i % 2 == 0) and inner.radius or outer.radius
15 local pos = inner.center + vec2.from_cartesian(r, step * i)
16
17 op.add(pos, vec2(20, 20))
18 draw.line(pos, lag)
19
20 lag = pos
21 end
22 end
23
24 return draw_star
+0
-16
examples/place_on_line.lua less more
0 function place_on_line(S)
1 input.selection(S.objs, '^led-')
2 input.line(S.dest)
3
4 local dest = S.dest()
5 local start = dest.frm
6 local step = (dest.to - dest.frm) / #S.objs()
7 start = start - step/2
8
9 for i, obj in ipairs(S.objs()) do
10 local pos = start + step * i
11 op.move(obj, pos)
12 end
13 end
14
15 return place_in_rect
+0
-10
examples/place_on_line.moon less more
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
+0
-8
examples/test.moon less more
0 import vec2 from require 'cpml'
1
2 =>
3 input.point @p
4
5 input.rect @re, max: @p!
6
7 input.circle @circ, center: @p!
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 import vec2 from require 'cpml'
1
2 =>
3 input.selection @objs
4
5 center = vec2!
6 for o in *@objs!
7 center += o.pos
8 num = #@objs!
9 if num > 0
10 center /= num
11 input.arrow @delta, center
12
13 delta = @delta!.to - @delta!.frm
14 for o in *@objs!
15 op.move o, o.pos + delta
0 -- let's load a vector library for doing some
1 -- more interesting transformations
2
3 import vec2 from require 'cpml'
4
5 =>
6 -- let's try to construct a pill-shape
7 input.rect @rect
8 rect = @rect!
9 hsize = (rect.max - rect.min) / 2
10
11 input.circle @left, {
12 center: rect.min + vec2 0, hsize.y
13 radius: hsize.y
14 }
15 input.circle @left, {
16 center: rect.min + vec2 hsize.x*2, hsize.y
17 radius: hsize.y
18 }
19
20 -- right, so that's that....
21 -- kinda forgetting whether there was something
22 -- else I wanted to show.
23 -- does this seem interesting to you?
24 -- let me know :)
0 local vec2 = (require 'cpml').vec2
1
2 function draw_star(S)
3 input.circle(S.inner)
4 input.circle(S.outer, { center = S.inner().center })
5
6 local inner, outer = S.inner(), S.outer()
7
8 input.slider(S.cnt, 2, 20)
9
10 local cnt = math.floor(S.cnt()) * 2
11 local step = 2*math.pi/cnt
12 local lag = inner.center + vec2(inner.radius, 0)
13 for i = 0, cnt do
14 local r = (i % 2 == 0) and inner.radius or outer.radius
15 local pos = inner.center + vec2.from_cartesian(r, step * i)
16
17 op.add(pos, vec2(20, 20))
18 draw.line(pos, lag)
19
20 lag = pos
21 end
22 end
23
24 return draw_star
0 =>
1 input.selection @to_delete
2 for b in *@to_delete!
3 op.remove b
0 =>
1 @init {}
2
3 if INPUT\mouse_down!
4 @start\set INPUT.mouse
5
6 if INPUT\mouse_held!
7 if INPUT\key_held 'lshift'
8 size = INPUT.mouse - @start!
9 draw.rect @start! - size, @start! + size
10 else
11 draw.rect @start!, INPUT.mouse
12
13 if INPUT\mouse_up!
14 size = INPUT.mouse - @start!
15 if INPUT\key_held 'lshift'
16 table.insert @!, pos: @start!, size: size*2
17 else
18 table.insert @!, pos: @start! + size/2, size: size
19
20 for o in *@!
21 op.add o.pos, o.size
0 function place_on_line(S)
1 input.selection(S.objs, '^led-')
2 input.line(S.dest)
3
4 local dest = S.dest()
5 local start = dest.frm
6 local step = (dest.to - dest.frm) / #S.objs()
7 start = start - step/2
8
9 for i, obj in ipairs(S.objs()) do
10 local pos = start + step * i
11 op.move(obj, pos)
12 end
13 end
14
15 return place_in_rect
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
0 import vec2 from require 'cpml'
1
2 =>
3 input.selection @objs
4
5 center = vec2!
6 for o in *@objs!
7 center += o.pos
8 num = #@objs!
9 if num > 0
10 center /= num
11 input.arrow @delta, center
12
13 delta = @delta!.to - @delta!.frm
14 -- delta.x = 25 * math.floor delta.x / 25
15 -- delta.y = 25 * math.floor delta.y / 25
16 for o in *@objs!
17 op.copy o, o.pos + delta
0 import vec2 from require 'cpml'
1
2 =>
3 input.point @p
4
5 input.rect @re, max: @p!
6
7 input.circle @circ, center: @p!
55 trace = (msg) -> debug.traceback msg, 2
66
77 class Script
8 new: (@file) =>
8 new: (file='scratch.moon') =>
9 @file = "library/#{file}"
910 @last_modification = 0
1011 @func = ->
1112
8283 love.event.quit!
8384 when 'run'
8485 arg = command\match '^run%s+(.+)'
85 @script = arg and Script arg
86 @script = Script arg
8687
8788 frame: =>
8889 lg.setColor 1, 1, 1