aboutsummaryrefslogtreecommitdiffstats
path: root/api.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-11-03 16:23:43 +0000
committers-ol <s-ol@users.noreply.github.com>2019-11-03 16:23:43 +0000
commit157f6c0fdb37e8490c293a44d9ed08cd3dc63291 (patch)
tree4cfbb2899e615c90f033a31aa4019513047d805e /api.moon
parentadd profiling support (diff)
downloadwatch-cad-157f6c0fdb37e8490c293a44d9ed08cd3dc63291.tar.gz
watch-cad-157f6c0fdb37e8490c293a44d9ed08cd3dc63291.zip
update examples, fixes
Diffstat (limited to 'api.moon')
-rw-r--r--api.moon41
1 files changed, 29 insertions, 12 deletions
diff --git a/api.moon b/api.moon
index 74fa110..3435cb7 100644
--- a/api.moon
+++ b/api.moon
@@ -24,6 +24,12 @@ draw =
contains = (INPUT.mouse - pos)\len2! < hs\len2!
INPUT\mouse_event! if contains
+ line: (frm, to) ->
+ lg.setColor 1, 1, 1
+ lg.line frm.x, frm.y, to.x, to.y
+
+ -- @TODO: hit checking
+
rect: (min, max) ->
x, y = min\unpack!
w, h = (max - min)\unpack!
@@ -81,14 +87,21 @@ input =
delta = last and pos - last
return delta and delta\len2! > 0 and delta
- rectangle: (fixed={}) =>
- delta = input.point @min, fixed.min or Once random.point! * 0.8
- input.point @max, fixed.max or Once @min! + random.size!
- @max\set @max! + delta if delta
+ rectangle: do
+ meta = size: => @max - @min
+ meta.__index = meta
+
+ (fixed={}) =>
+ @init setmetatable {}, meta
+ delta = input.point @min, fixed.min or Once random.point! * 0.8
+ input.point @max, fixed.max or Once @min! + random.size!
+ @max\set @max! + delta if delta
+
+ min, max = @min!, @max!
+ draw.rect min, max
- min, max = @min!, @max!
- draw.rect min, max
- @set { :min, :max }
+ self = @get!
+ self.min, self.max = min, max
circle: (fixed={}) =>
local tangent
@@ -98,16 +111,20 @@ input =
radius = (is_once fixed.radius) or math.random! * 100 + 50
init_tangent = vec2.from_cartesian radius, math.random! * 2 * math.pi
input.point @tangent, fixed.tangent or Once @center! + init_tangent
- @center!\dist @tangent!
+ tangent = @tangent!
+ radius = @center!\dist tangent
+ radius, tangent
- @tangent\set @tangent! + delta if delta and tangent
+ if delta and tangent
+ @tangent\set @tangent! + delta
center, tangent = @center!, @tangent!
draw.circle center, radius
- { :center, :tangent, :radius }
+ @set { :center, :tangent, :radius }
- selection: (init, fixed) =>
- init or= {o for o in *OBJS when match and o.name\match init}
+ selection: (pattern) =>
+ -- @TOOD: fix
+ @init {o for o in *SESSION.objects when match and o.name\match init}
lg.push 'all'
lg.setLineWidth 5