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) {
return parenthesize(tokenize(input))
return parenthesize(tokenize(`(${input})`))
}
this.toPixels = async function () {

View File

@ -1,17 +1,17 @@
; animate
(
(clear)
(def t
(sin
(div
(time) 100)))
(def pos
(add 200 30
(mul 30 t)))
(defn square
(a)
(rect a a a a))
(stroke
(square pos) 1 "red")
; set false to stop
(animate true))
(clear)
(def t
(sin
(div
(time) 100)))
(def pos
(add 200 30
(mul 30 t)))
(defn square
(a)
(rect a a a a))
(stroke
(square pos) 1 "red")
; set false to stop
(animate true)

View File

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

View File

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

View File

@ -1,14 +1,14 @@
; filesystem
(
; print path
(echo
(filepath))
; print folder path
(echo
(dirpath))
; print file content
(echo
(file))
; print folder content
(echo
(dir)))
; print path
(echo
(filepath))
; print folder path
(echo
(dirpath))
; print file content
(echo
(file))
; print folder content
(echo
(dir))

View File

@ -1,6 +1,5 @@
; benchmark
(
; Basics
(test "add" (add 8 4 2) 14)
@ -57,5 +56,4 @@
; Interop
(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
(
(clear)
(open "../static/crystal.jpg")
(crop (rect 100 100 400 400))
)
(clear)
(open "../static/crystal.jpg")
(crop (rect 100 100 400 400))

View File

@ -1,35 +1,33 @@
; dejong attractor
(
(clear)
(defn point (x y color)
(fill (rect x y 1 1) color))
(clear)
(defn point (x y color)
(fill (rect x y 1 1) color))
(defn _dejong (x y a b c d)
(rest ((point
(add 300 (mul 100 x))
(add 400 (mul 100 y))
"red")
(add (sin (mul a y)) (mul x (cos (mul b x))))
(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 (x y a b c d)
(rest ((point
(add 300 (mul 100 x))
(add 400 (mul 100 y))
"red")
(add (sin (mul a y)) (mul x (cos (mul b x))))
(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)
))

View File

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

View File

@ -1,4 +1,3 @@
(
; gradients
(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
(gradient
(50 0 180 0)
("black" "white" "blue" "green")))
)
("black" "white" "blue" "green")))

View File

@ -1,57 +1,56 @@
; guides
(
(clear)
(stroke
(frame) 1 "red")
(stroke
(line
(pos 0 0)
(pos
(clear)
(stroke
(frame) 1 "red")
(stroke
(line
(pos 0 0)
(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
(frame) "w")
(frame) "w") 2) 0)
(pos
(div
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(frame) "w") 2)
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos 0
(div
(of
(frame) "w") 0)
(pos 0
(frame) "h") 2))
(pos
(div
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(div
(of
(frame) "w") 2) 0)
(pos
(div
(of
(frame) "w") 2)
(frame) "w") 2)
(of
(frame) "h"))) 1 "#72dec2")
(stroke
(line
(pos
(div
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos 0
(div
(of
(frame) "h") 2))
(pos
(div
(of
(frame) "w") 2)
(frame) "w") 2) 0)
(pos
(of
(frame) "w")
(div
(of
(frame) "h"))) 1 "#72dec2")
(stroke
(line
(pos
(div
(of
(frame) "w") 2) 0)
(pos
(of
(frame) "w")
(div
(of
(frame) "h") 2))) 1 "#72dec2"))
(frame) "h") 2))) 1 "#72dec2")

View File

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

View File

@ -1,4 +1,3 @@
; include
(
(include "../examples/recursive.lisp")
(echo line-color))
(include "../examples/recursive.lisp")
(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")
(pixels
(frame)
saturation
12)
)
(open "../static/crystal.jpg")
(pixels
(frame)
saturation
12)

View File

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

View File

@ -1,14 +1,14 @@
; filesystem
(
; get files
(def files
(dir
(dirpath)))
; pick a random file
(def random-index
(floor
(random
(len files))))
; print random file name
(echo
(get files random-index)))
; get files
(def files
(dir
(dirpath)))
; pick a random file
(def random-index
(floor
(random
(len files))))
; print random file name
(echo
(get files random-index))

View File

@ -1,17 +1,17 @@
; random
(
(clear)
(defn place
(rec)
(if
(gt rec 0)
(
(import "../static/crystal.jpg"
(rect
(random 200)
(random 200)
(random 200)
(random 200)))
(place
(sub rec 1)))))
(place 30))
(clear)
(defn place
(rec)
(if
(gt rec 0)
(
(import "../static/crystal.jpg"
(rect
(random 200)
(random 200)
(random 200)
(random 200)))
(place
(sub rec 1)))))
(place 30)

View File

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

View File

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

View File

@ -1,25 +1,24 @@
; Shapes
((clear)
(clear)
; variables
(def center-w (div (of (frame) "w") 2))
(def center-h (div (of (frame) "h") 2))
(def rad (div (of (frame) "h") 4))
; draw circle
(stroke
(circle center-w center-h rad) 2 "white")
; variables
(def center-w (div (of (frame) "w") 2))
(def center-h (div (of (frame) "h") 2))
(def rad (div (of (frame) "h") 4))
; draw rect
(stroke
(rect
(sub center-w rad) (sub center-h rad) center-h center-h) 2 "white")
; draw circle
(stroke
(circle center-w center-h rad) 2 "white")
; 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")
)
; draw rect
(stroke
(rect
(sub center-w rad) (sub center-h rad) center-h center-h) 2 "white")
; 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
; by @local_guru
(
(clear)
(defn rec
(v)
@ -27,4 +27,4 @@
(sub v 0.3)))))
; set false to stop
(animate true)
(rec 300))
(rec 300)

View File

@ -1,8 +1,8 @@
(
(clear)
; ronin path
(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")
; outline
(stroke
(svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555"))
(clear)
; ronin path
(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")
; outline
(stroke
(svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555")

View File

@ -1,38 +1,38 @@
; theme
(
(clear)
(def col
(lambda
(i)
(of
(
(theme "f_high")
(theme "f_med")
(theme "f_low")
(theme "f_inv")
(theme "b_high")
(theme "b_med")
(theme "b_low")
(theme "b_inv"))
(mod i 8))))
(def rec
(lambda
(v i)
(if
(gt v 0)
(
(fill
(circle
(add
(div
(of
(frame) "w") 1.6)
(mul 1.5 v))
(mul 10 v)
(mul v
(div v 5)))
(col i))
(rec
(sub v 3)
(add i 1))))))
(rec 40 0))
(clear)
(def col
(lambda
(i)
(of
(
(theme "f_high")
(theme "f_med")
(theme "f_low")
(theme "f_inv")
(theme "b_high")
(theme "b_med")
(theme "b_low")
(theme "b_inv"))
(mod i 8))))
(def rec
(lambda
(v i)
(if
(gt v 0)
(
(fill
(circle
(add
(div
(of
(frame) "w") 1.6)
(mul 1.5 v))
(mul 10 v)
(mul v
(div v 5)))
(col i))
(rec
(sub v 3)
(add i 1))))))
(rec 40 0)