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,17 +1,17 @@
; animate ; animate
(
(clear) (clear)
(def t (def t
(sin (sin
(div (div
(time) 100))) (time) 100)))
(def pos (def pos
(add 200 30 (add 200 30
(mul 30 t))) (mul 30 t)))
(defn square (defn square
(a) (a)
(rect a a a a)) (rect a a a a))
(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,21 +9,17 @@
(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))
)
( (map (lambda (a)
(clear) (stroke
(map (lambda (a) (rect
(stroke (mul a 10)
(rect (add 50 (mul (sin a) 40))
(mul a 10) a
(add 50 (mul (sin a) 40)) (add 20 (mul (cos a) 50))) 1 "red"))
a (range 0 200 5))
(add 20 (mul (cos a) 50))) 1 "red"))
(range 0 200 5)))

View File

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

View File

@ -1,14 +1,14 @@
; filesystem ; filesystem
(
; print path ; print path
(echo (echo
(filepath)) (filepath))
; print folder path ; print folder path
(echo (echo
(dirpath)) (dirpath))
; print file content ; print file content
(echo (echo
(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)
@ -57,5 +56,4 @@
; 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,35 +1,33 @@
; 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))
(defn _dejong (x y a b c d) (defn _dejong (x y a b c d)
(rest ((point (rest ((point
(add 300 (mul 100 x)) (add 300 (mul 100 x))
(add 400 (mul 100 y)) (add 400 (mul 100 y))
"red") "red")
(add (sin (mul a y)) (mul x (cos (mul b x)))) (add (sin (mul a y)) (mul x (cos (mul b x))))
(add (mul x (sin (mul x c))) (cos (mul d y))) (add (mul x (sin (mul x c))) (cos (mul d y)))
))
)
(defn dejong (r a b c d)
(reduce
(lambda (acc val)
(first (
(_dejong (first acc) (last acc) a b c d)
)))
(range 0 r)
(2 1)
)
)
(benchmark
'(dejong 12800
(random -2 2)
(random -2 2)
(random -2 2)
(random -2 2)
)) ))
) )
(defn dejong (r a b c d)
(reduce
(lambda (acc val)
(first (
(_dejong (first acc) (last acc) a b c d)
)))
(range 0 r)
(2 1)
)
)
(benchmark
'(dejong 12800
(random -2 2)
(random -2 2)
(random -2 2)
(random -2 2)
))

View File

@ -1,25 +1,19 @@
; pixels ; Glitch
( (clear)
(clear)
; Glitch (defn glitch
(rec)
(defn glitch (if (gt rec 1)
(rec) ((clone
(if (gt rec 1) (rect (random 400) (random 400) 2 2)
((clone (rect (random 400) (random 400)
(rect (random 400) (random 400) 2 2)
(rect (random 400) (random 400)
(random 10) (random 30))) (random 10) (random 30)))
(glitch (sub rec 1)))) (glitch (sub rec 1))))
) )
; Draw photo (import
"../static/crystal.jpg"
(import (rect 0 0 400 400))
"../static/crystal.jpg"
(rect 0 0 400 400))
(glitch 500) (glitch 500)
)

View File

@ -1,4 +1,3 @@
(
; gradients ; gradients
(clear) (clear)
@ -12,5 +11,4 @@
(svg "M255,60 L255,60 L135,180 L75,60 L195,210 L120,225 L105,225 L165,255 L225,195 L255,135 L285,150") 1 (svg "M255,60 L255,60 L135,180 L75,60 L195,210 L120,225 L105,225 L165,255 L225,195 L255,135 L285,150") 1
(gradient (gradient
(50 0 180 0) (50 0 180 0)
("black" "white" "blue" "green"))) ("black" "white" "blue" "green")))
)

View File

@ -1,57 +1,56 @@
; guides ; guides
( (clear)
(clear) (stroke
(stroke (frame) 1 "red")
(frame) 1 "red") (stroke
(stroke (line
(line (pos 0 0)
(pos 0 0) (pos
(pos (of
(frame) "w")
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(of
(frame) "w") 0)
(pos 0
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(div
(of (of
(frame) "w") (frame) "w") 2) 0)
(pos
(div
(of (of
(frame) "h"))) 1 "red") (frame) "w") 2)
(stroke (of
(line (frame) "h"))) 1 "red")
(pos (stroke
(line
(pos 0
(div
(of (of
(frame) "w") 0) (frame) "h") 2))
(pos 0 (pos
(div
(of (of
(frame) "h"))) 1 "red") (frame) "w") 2)
(stroke (of
(line (frame) "h"))) 1 "#72dec2")
(pos (stroke
(div (line
(of (pos
(frame) "w") 2) 0) (div
(pos
(div
(of
(frame) "w") 2)
(of (of
(frame) "h"))) 1 "red") (frame) "w") 2) 0)
(stroke (pos
(line (of
(pos 0 (frame) "w")
(div (div
(of
(frame) "h") 2))
(pos
(div
(of
(frame) "w") 2)
(of (of
(frame) "h"))) 1 "#72dec2") (frame) "h") 2))) 1 "#72dec2")
(stroke
(line
(pos
(div
(of
(frame) "w") 2) 0)
(pos
(of
(frame) "w")
(div
(of
(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,14 +1,14 @@
; filesystem ; filesystem
(
; get files ; get files
(def files (def files
(dir (dir
(dirpath))) (dirpath)))
; pick a random file ; pick a random file
(def random-index (def random-index
(floor (floor
(random (random
(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,17 +1,17 @@
; random ; random
(
(clear) (clear)
(defn place (defn place
(rec) (rec)
(if (if
(gt rec 0) (gt rec 0)
( (
(import "../static/crystal.jpg" (import "../static/crystal.jpg"
(rect (rect
(random 200) (random 200)
(random 200) (random 200)
(random 200) (random 200)
(random 200))) (random 200)))
(place (place
(sub rec 1))))) (sub rec 1)))))
(place 30)) (place 30)

View File

@ -1,16 +1,16 @@
; recursive ; recursive
(
(clear) (clear)
(defn rec (defn rec
(v) (v)
(if (if
(gt v 0) (gt v 0)
( (
(stroke (stroke
(circle (circle
(mul 5 v) (mul 5 v)
(mul 5 v) (mul 5 v)
(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,25 +1,24 @@
; Shapes ; Shapes
((clear) (clear)
; variables ; variables
(def center-w (div (of (frame) "w") 2)) (def center-w (div (of (frame) "w") 2))
(def center-h (div (of (frame) "h") 2)) (def center-h (div (of (frame) "h") 2))
(def rad (div (of (frame) "h") 4)) (def rad (div (of (frame) "h") 4))
; draw circle
(stroke
(circle center-w center-h rad) 2 "white")
; draw rect ; draw circle
(stroke (stroke
(rect (circle center-w center-h rad) 2 "white")
(sub center-w rad) (sub center-h rad) center-h center-h) 2 "white")
; draw line ; draw rect
(stroke (stroke
(line (rect
(pos (sub center-w rad) center-h) (sub center-w rad) (sub center-h rad) center-h center-h) 2 "white")
(pos (add center-w rad) center-h)))
(stroke (text 10 170 200 "HELL") 2 "pink") ; draw line
) (stroke
(line
(pos (sub center-w rad) center-h)
(pos (add center-w rad) center-h)))
(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,38 +1,38 @@
; theme ; theme
(
(clear) (clear)
(def col (def col
(lambda (lambda
(i) (i)
(of (of
( (
(theme "f_high") (theme "f_high")
(theme "f_med") (theme "f_med")
(theme "f_low") (theme "f_low")
(theme "f_inv") (theme "f_inv")
(theme "b_high") (theme "b_high")
(theme "b_med") (theme "b_med")
(theme "b_low") (theme "b_low")
(theme "b_inv")) (theme "b_inv"))
(mod i 8)))) (mod i 8))))
(def rec (def rec
(lambda (lambda
(v i) (v i)
(if (if
(gt v 0) (gt v 0)
( (
(fill (fill
(circle (circle
(add (add
(div (div
(of (of
(frame) "w") 1.6) (frame) "w") 1.6)
(mul 1.5 v)) (mul 1.5 v))
(mul 10 v) (mul 10 v)
(mul v (mul v
(div v 5))) (div v 5)))
(col i)) (col i))
(rec (rec
(sub v 3) (sub v 3)
(add i 1)))))) (add i 1))))))
(rec 40 0)) (rec 40 0)