update examples with no global ( )

This commit is contained in:
Quentin Leonetti 2019-07-20 17:13:40 +02:00
parent 7624bef7f9
commit 143a45807e
24 changed files with 279 additions and 304 deletions

View File

@ -146,7 +146,7 @@ function Lisp (input, lib) {
} }
this.parse = function (input) { this.parse = function (input) {
return parenthesize(tokenize(input)) return parenthesize(tokenize(`(${input})`))
} }
this.toPixels = async function () { this.toPixels = async function () {

View File

@ -1,5 +1,5 @@
; animate ; animate
(
(clear) (clear)
(def t (def t
(sin (sin
@ -14,4 +14,4 @@
(stroke (stroke
(square pos) 1 "red") (square pos) 1 "red")
; set false to stop ; set false to stop
(animate true)) (animate true)

View File

@ -1,9 +1,7 @@
(echo (map (lambda (a) (add a 1)) (1 2 3))) (echo (map (lambda (a) (add a 1)) (1 2 3)))
(
(echo (first (1 2 3))) (echo (first (1 2 3)))
(echo (rest (1 2 3))) (echo (rest (1 2 3)))
)
(echo (echo
(filter (filter
@ -11,16 +9,12 @@
(1 2 3 4 5)) (1 2 3 4 5))
) )
(
(clear) (clear)
(map (lambda (a) (map (lambda (a)
(stroke (rect (mul a 30) 20 50 50) (stroke (rect (mul a 30) 20 50 50)
1 "red")) 1 "red"))
(range 0 20 5)) (range 0 20 5))
)
(
(clear)
(map (lambda (a) (map (lambda (a)
(stroke (stroke
(rect (rect
@ -28,4 +22,4 @@
(add 50 (mul (sin a) 40)) (add 50 (mul (sin a) 40))
a a
(add 20 (mul (cos a) 50))) 1 "red")) (add 20 (mul (cos a) 50))) 1 "red"))
(range 0 200 5))) (range 0 200 5))

View File

@ -1,9 +1,9 @@
; basics ; basics
(
; define a variable ; define a variable
(def a 25) (def a 25)
(echo a) (echo a)
; define a function ; define a function
(defn add-two (a) (add 2 a)) (defn add-two (a) (add 2 a))
(echo (add-two 4))) (echo (add-two 4))

View File

@ -1,5 +1,5 @@
; filesystem ; filesystem
(
; print path ; print path
(echo (echo
(filepath)) (filepath))
@ -11,4 +11,4 @@
(file)) (file))
; print folder content ; print folder content
(echo (echo
(dir))) (dir))

View File

@ -1,6 +1,5 @@
; benchmark ; benchmark
(
; Basics ; Basics
(test "add" (add 8 4 2) 14) (test "add" (add 8 4 2) 14)
@ -58,4 +57,3 @@
; Interop ; Interop
(test "interop" ((of (of (js) "Math") "max") 2 4) 4) (test "interop" ((of (of (js) "Math") "max") 2 4) 4)
(test "recursive key selector" ((of (js) "Math" "max") 2 4) 4) (test "recursive key selector" ((of (js) "Math" "max") 2 4) 4)
)

View File

@ -1,7 +1,5 @@
; crop ; crop
(
(clear) (clear)
(open "../static/crystal.jpg") (open "../static/crystal.jpg")
(crop (rect 100 100 400 400)) (crop (rect 100 100 400 400))
)

View File

@ -1,6 +1,5 @@
; dejong attractor ; dejong attractor
(
(clear) (clear)
(defn point (x y color) (defn point (x y color)
(fill (rect x y 1 1) color)) (fill (rect x y 1 1) color))
@ -32,4 +31,3 @@
(random -2 2) (random -2 2)
(random -2 2) (random -2 2)
)) ))
)

View File

@ -1,10 +1,7 @@
; pixels
(
(clear)
; Glitch ; Glitch
(clear)
(defn glitch (defn glitch
(rec) (rec)
(if (gt rec 1) (if (gt rec 1)
@ -15,11 +12,8 @@
(glitch (sub rec 1)))) (glitch (sub rec 1))))
) )
; Draw photo
(import (import
"../static/crystal.jpg" "../static/crystal.jpg"
(rect 0 0 400 400)) (rect 0 0 400 400))
(glitch 500) (glitch 500)
)

View File

@ -1,4 +1,3 @@
(
; gradients ; gradients
(clear) (clear)
@ -13,4 +12,3 @@
(gradient (gradient
(50 0 180 0) (50 0 180 0)
("black" "white" "blue" "green"))) ("black" "white" "blue" "green")))
)

View File

@ -1,5 +1,4 @@
; guides ; guides
(
(clear) (clear)
(stroke (stroke
(frame) 1 "red") (frame) 1 "red")
@ -54,4 +53,4 @@
(frame) "w") (frame) "w")
(div (div
(of (of
(frame) "h") 2))) 1 "#72dec2")) (frame) "h") 2))) 1 "#72dec2")

View File

@ -1,5 +1,5 @@
( (clear)
(def a (import (def a (import
"../static/crystal.jpg" "../static/crystal.jpg"
(rect 0 0 400 400))) (rect 0 0 400 400)))
(echo a)) (echo a)

View File

@ -1,4 +1,3 @@
; include ; include
(
(include "../examples/recursive.lisp") (include "../examples/recursive.lisp")
(echo line-color)) (echo line-color)

View File

@ -1,6 +1,6 @@
( (
(echo (map '(echo 1 2 3) (4 5 6)) (echo (map '(add 1 2) (4 5 6))
) )

View File

@ -1,9 +1,7 @@
; scale file ; saturate image
(
(open "../static/crystal.jpg") (open "../static/crystal.jpg")
(pixels (pixels
(frame) (frame)
saturation saturation
12) 12)
)

View File

@ -1,7 +1,7 @@
; pixels ; pixels
(
(clear) (clear)
(import "../../PREVIEW.jpg" (import "../../PREVIEW.jpg"
(frame)) (frame))
(pixels (pixels
(rect 0 0 500 500) saturation 0.5)) (rect 0 0 500 500) saturation 0.5)

View File

@ -1,5 +1,5 @@
; filesystem ; filesystem
(
; get files ; get files
(def files (def files
(dir (dir
@ -11,4 +11,4 @@
(len files)))) (len files))))
; print random file name ; print random file name
(echo (echo
(get files random-index))) (get files random-index))

View File

@ -1,5 +1,5 @@
; random ; random
(
(clear) (clear)
(defn place (defn place
(rec) (rec)
@ -14,4 +14,4 @@
(random 200))) (random 200)))
(place (place
(sub rec 1))))) (sub rec 1)))))
(place 30)) (place 30)

View File

@ -1,5 +1,5 @@
; recursive ; recursive
(
(clear) (clear)
(defn rec (defn rec
(v) (v)
@ -13,4 +13,4 @@
(mul 5 v)) 1 "red") (mul 5 v)) 1 "red")
(rec (rec
(sub v 5))))) (sub v 5)))))
(rec 100)) (rec 100)

View File

@ -1,5 +1,5 @@
; resize ; resize
(
(clear) (clear)
(open "../../PREVIEW.jpg") (open "../../PREVIEW.jpg")
(resize 0.5 0.5)) (resize 0.5 0.5)

View File

@ -1,6 +1,6 @@
; Shapes ; Shapes
((clear) (clear)
; variables ; variables
(def center-w (div (of (frame) "w") 2)) (def center-w (div (of (frame) "w") 2))
@ -22,4 +22,3 @@
(pos (sub center-w rad) center-h) (pos (sub center-w rad) center-h)
(pos (add center-w rad) center-h))) (pos (add center-w rad) center-h)))
(stroke (text 10 170 200 "HELL") 2 "pink") (stroke (text 10 170 200 "HELL") 2 "pink")
)

View File

@ -1,6 +1,6 @@
; animated recusive spiral ; animated recusive spiral
; by @local_guru ; by @local_guru
(
(clear) (clear)
(defn rec (defn rec
(v) (v)
@ -27,4 +27,4 @@
(sub v 0.3))))) (sub v 0.3)))))
; set false to stop ; set false to stop
(animate true) (animate true)
(rec 300)) (rec 300)

View File

@ -1,8 +1,8 @@
(
(clear) (clear)
; ronin path ; ronin path
(stroke (stroke
(svg "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 2 "white") (svg "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 2 "white")
; outline ; outline
(stroke (stroke
(svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555")) (svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555")

View File

@ -1,5 +1,5 @@
; theme ; theme
(
(clear) (clear)
(def col (def col
(lambda (lambda
@ -35,4 +35,4 @@
(rec (rec
(sub v 3) (sub v 3)
(add i 1)))))) (add i 1))))))
(rec 40 0)) (rec 40 0)