Improved examples

This commit is contained in:
neauoire
2020-03-26 11:51:35 +09:00
parent 2bfbb96d59
commit ff51bd7b89
13 changed files with 164 additions and 126 deletions

View File

@@ -1,60 +0,0 @@
; benchmark
; this file is used to test the library.
; Basics
(test "add" (add 8 4 2) 14)
(test "sub" (sub 8 4 2) 2)
(test "mul" (mul 8 4 2) 64)
(test "div" (div 8 4 2) 1)
; Others
(test "mod" (mod 6 4) 2)
(test "clamp" (clamp 12 4 8) 8)
(test "step" (step 12 10) 10)
(test "PI" TWO_PI (mul 2 PI))
; Logic
(test "lt" (lt 3 4) true)
(test "gt" (gt 3 4) false)
(test "and - true" (and 1 2 true 4) 4)
(test "and - false" (and 1 false 2) false)
(test "or - true" (or false false 2 false) 2)
(test "if - branch 1" (if (gt 3 2) ("branch 1") ("branch 2")) "branch 1")
(test "if - branch 2" (if (lt 3 2) ("branch 1") ("branch 2")) "branch 2")
(test "if - no else" (if (lt 3 2) ("branch 1")) ())
; Arrays
(test "first" (first ("a" "b" "c")) "a")
(test "rest" (rest ("a" "b" "c")) ("b" "c"))
(test "last" (last ("a" "b" "c")) "c")
(test "range simple" (range 0 4) (0 1 2 3 4))
(test "range with step" (range 0 4 2) (0 2 4))
(test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4))
(test "map" (map (1 2 3) (λ (a) (add 1 a))) (2 3 4))
(test "filter" (filter (2 3 4 5 6) (λ (a) (eq 0 (mod a 2)))) (2 4 6))
(test "reduce" (reduce (1 2 3) (λ (acc val) (add acc val)) 4) 10)
; Scope
(def aaa 123)
(def addOne (λ (a) (add a 1)))
(test "def - value" aaa 123)
(test "def - func" (addOne 4) 5)
(defn addTwo (a) (add 2 a))
(test "defn" (addTwo 4) 6)
(defn mulTwo "multiplies by two" (a) (mul 2 a))
(test "docstring" (mulTwo 4) 8)
; Generics
(test "concat" (concat 1 4 "-" (add 3 4) ".jpg") "14-7.jpg")
; Interop
(test "interop" ((of (of (js) "Math") "max") 2 4) 4)
(test "recursive key selector" ((of (js) "Math" "max") 2 4) 4)

View File

@@ -1,19 +1,28 @@
; gradients
(def frame
(get-frame))
(clear)
(def gl
(line 0 0 frame:h frame:h))
(def cl1
(gradient gl
(theme:b_med theme:b_high)))
(def cl2
(gradient gl
(theme:b_high theme:b_med)))
(guide gl)
(def colors
("#72dec2" "#ffffff"))
(def gradient1
(gradient
(line 0 0 frame:h frame:h) colors))
(def gradient2
(gradient
(line frame:h frame:h 0 0) colors))
(fill
(circle frame:m frame:m frame:m) cl1)
(circle frame:m frame:m frame:m) gradient1)
(fill
(circle frame:m frame:m
(mul frame:m 0.75)) cl2)
(mul frame:m 0.75)) gradient2)
(fill
(circle frame:m frame:m
(mul frame:m 0.5)) cl1)
(mul frame:m 0.5)) gradient1)

View File

@@ -1,42 +1,63 @@
; display a collection of all shapes.
(def colors
("#000000" "#72dec2"))
;
(clear)
(stroke
(rect 0 0 300 300) theme:b_high)
(rect 0 0 300 300) colors:0)
(stroke
(circle 150 150 150) theme:b_med)
(circle 150 150 150) colors:1)
(stroke
(ellipse 150 150 75 150) theme:b_high)
(ellipse 150 150 75 150) colors:0)
(stroke
(line 0 150 300 150) theme:b_high)
(line 0 150 300 150) colors:0)
(stroke
(text 600 300 60 "hell") theme:b_med)
(text 600 300 60 "hell") colors:1)
(stroke
(arc 600 298 296
(rad 180)
(rad -90)) theme:b_med)
(rad -90)) colors:1)
(stroke
(poly
(pos 300 300)
(pos 600 0)
(pos 600 300)) theme:b_high)
(pos 600 300)) colors:0)
(transform:move 0 300)
(fill
(rect 0 0 300 300) theme:b_high)
(rect 0 0 300 300) colors:0)
(fill
(circle 150 150 150) theme:b_med)
(circle 150 150 150) colors:1)
(fill
(ellipse 150 150 75 150) theme:b_high)
(ellipse 150 150 75 150) colors:0)
(fill
(line 0 150 300 150) theme:b_high)
(line 0 150 300 150) colors:0)
(fill
(text 600 300 60 "hell") theme:b_med)
(text 600 300 60 "hell") colors:1)
(fill
(arc 600 298 296
(rad 180)
(rad -90)) theme:b_med)
(rad -90)) colors:1)
(fill
(poly
(pos 300 300)
(pos 600 0)
(pos 600 300)) theme:b_high)
(pos 600 300)) colors:0)
(transform:reset)

View File

@@ -1,5 +1,9 @@
; animated recusive spiral
; by @local_guru
(def frame
(get-frame))
;
(defn rec
(v)
(if
@@ -27,12 +31,14 @@
(circle spiral-x spiral-y spiral-r)
(color 114 222 194 0.1) 1)
(rec
(sub v 0.3)))))
(sub v 0.3)))))
;
(defn redraw
()
(
(clear)
(rec 300)))
;
(on "animate" redraw)

View File

@@ -0,0 +1,20 @@
; this demo shows how to use the mouse events to draw make a simple drawing tool.
;
(clear)
;
(def gradient-line
(line frame:c 0 frame:c frame:h))
;
(defn draw-circle
(e)
(
(stroke
(circle e:x e:y e:d)
(gradient gradient-line
("black" "#72dec2")))))
;
(on "mouse-move" draw-circle)

View File

@@ -1,9 +1,18 @@
; display color from the theme.
(def theme
(get-theme))
; ex: theme:f_high
(clear)
(clear)
(fill frame theme:background)
(def color-box
(div frame:h 10))
(defn print-value
(item id)
(
@@ -22,5 +31,6 @@
(keys theme) id)) theme:f_high)
(fill
(text 400 box-y 30 item) theme:f_high)))
(map
(values theme) print-value)

View File

@@ -1,4 +1,5 @@
(clear)
(defn branch
(v)
(if
@@ -20,5 +21,7 @@
(branch
(sub v 1))
(transform:pop))))
(branch 10)
(transform:reset)

View File

@@ -1,19 +1,31 @@
; transforms
(clear)
(transform:move 150 150)
(fill
(circle 0 0 150) theme:b_inv)
(transform:move 300 0)
(transform:rotate
(rad 90))
(fill
(circle 0 0 150) theme:b_high)
(transform:move 300 0)
(transform:rotate
(rad 90))
(fill
(circle 0 0 150) theme:b_med)
(transform:move 300 0)
(fill
(circle 0 0 150) theme:b_low)
(transform:reset)