Moving examples
This commit is contained in:
54
examples/events/on-animate.lisp
Normal file
54
examples/events/on-animate.lisp
Normal file
@@ -0,0 +1,54 @@
|
||||
; this demo shows how to use the animate event to animate lines into a sine wave.
|
||||
;
|
||||
(def seg-count 50)
|
||||
;
|
||||
(def frame-middle
|
||||
(div
|
||||
(of
|
||||
(frame) :h) 2))
|
||||
;
|
||||
(def seg-width
|
||||
(div
|
||||
(of
|
||||
(frame) :w) seg-count))
|
||||
;
|
||||
(defn elevation
|
||||
(i)
|
||||
(add
|
||||
(mul
|
||||
(sin
|
||||
(add
|
||||
(time 0.001)
|
||||
(div i 5)))
|
||||
(div
|
||||
(of
|
||||
(frame) :h) 5)) frame-middle))
|
||||
;
|
||||
(defn draw-dash
|
||||
(i)
|
||||
(
|
||||
(def x
|
||||
(mul
|
||||
(sub i 1) seg-width))
|
||||
(def y
|
||||
(elevation i))
|
||||
(stroke
|
||||
(line
|
||||
(pos x
|
||||
(elevation
|
||||
(sub i 1)))
|
||||
(pos
|
||||
(add x seg-width)
|
||||
(elevation i))) 4
|
||||
(gradient
|
||||
(50 0
|
||||
(of
|
||||
(frame) :w) 0)
|
||||
("#ffb545" "#72dec2")))))
|
||||
;
|
||||
(defn redraw
|
||||
()
|
||||
(
|
||||
(clear)
|
||||
(times seg-count draw-dash)))
|
||||
(on "animate" redraw)
|
||||
38
examples/events/on-mouse.lisp
Normal file
38
examples/events/on-mouse.lisp
Normal file
@@ -0,0 +1,38 @@
|
||||
; this demo shows how to use the mouse events to draw make a simple drawing tool.
|
||||
;
|
||||
(clear)
|
||||
;
|
||||
(def prev-pos {:x 0 :y 0})
|
||||
;
|
||||
(defn stroke-color
|
||||
(e)
|
||||
(if
|
||||
(of e :is-down) "#ffb545" "#72dec2"))
|
||||
;
|
||||
(defn draw-line
|
||||
(e)
|
||||
(
|
||||
(if
|
||||
(of e :is-down)
|
||||
(
|
||||
(stroke
|
||||
(line prev-pos e) 2 "white")
|
||||
(set prev-pos :x
|
||||
(of e :x) :y
|
||||
(of e :y))))))
|
||||
;
|
||||
(defn draw-circle
|
||||
(e)
|
||||
(
|
||||
(set prev-pos :x
|
||||
(of e :x) :y
|
||||
(of e :y))
|
||||
(stroke
|
||||
(circle
|
||||
(of e :x)
|
||||
(of e :y) 10) 4
|
||||
(stroke-color e))))
|
||||
;
|
||||
(on "mouse-down" draw-circle)
|
||||
(on "mouse-up" draw-circle)
|
||||
(on "mouse-move" draw-line)
|
||||
24
examples/events/on-osc.lisp
Normal file
24
examples/events/on-osc.lisp
Normal file
@@ -0,0 +1,24 @@
|
||||
;
|
||||
(def ring
|
||||
(circle 300 300 150))
|
||||
;
|
||||
(defn redraw
|
||||
()
|
||||
(
|
||||
(clear)
|
||||
(stroke ring 2 "red")))
|
||||
;
|
||||
(defn on-msg
|
||||
(msg)
|
||||
(
|
||||
(def msg-value
|
||||
(of
|
||||
(first msg) :value))
|
||||
(set ring :r 150)))
|
||||
; frame
|
||||
(set ring :r
|
||||
(sub
|
||||
(of ring :r) 1))
|
||||
(redraw)
|
||||
; trigger
|
||||
(on "/a" on-msg)
|
||||
Reference in New Issue
Block a user