update examples to use defn

This commit is contained in:
Quentin Leonetti 2019-07-15 21:42:09 +02:00
parent f353b674b3
commit c81a0a8c96
3 changed files with 22 additions and 20 deletions

View File

@ -5,6 +5,6 @@
(def t (sin (div (time) 100)))
(def pos (add 200 (mul 30 t)))
(def square (lambda (a) (rect (add 200 a) a a a)))
(defn square (a) (rect a a a a))
(stroke (square pos) 1 "red")
)

View File

@ -1,18 +1,19 @@
; dejong attractor
(
(clear)
(def point (lambda (x y color) (stroke (circle x y 0.1) 1 color)))
(def _dejong (lambda (x y a b c d)
(defn point (x y color) (fill (circle x y 0.1) color))
(defn _dejong (x y a b c d)
(rest ((point
(add 700 (mul 100 x))
(add 300 (mul 100 x))
(add 400 (mul 100 y))
"rgba(255,0,0,1)")
"rgba(255,0,0,0.5)")
(add (sin (mul a y)) (mul x (cos (mul b x))))
(add (mul x (sin (mul x c))) (cos (mul d y)))
))
))
)
(def dejong (lambda (r a b c d)
(defn dejong (r a b c d)
(reduce
(lambda (acc val)
(first (
@ -21,6 +22,6 @@
(range 0 r)
(2 1)
)
))
(dejong 32000 1.4 -2.3 2.4 -2.1)
)
(dejong 128000 1.4 -2.3 2.4 -2.1)
)

View File

@ -1,15 +1,16 @@
; recursive
(
(clear)
(def rec
(lambda (v)
(defn rec
(v)
(if (gt v 0)
(
(stroke (circle
(mul 5 v)
(mul 5 v)
(mul 5 v)) 1 "red")
(rec (sub v 5))
)
(echo "done"))))
((stroke (circle
(mul 5 v)
(mul 5 v)
(mul 5 v)) 1 "red")
(rec (sub v 5))))
)
(rec 100)
)