update examples to use defn
This commit is contained in:
		@@ -5,6 +5,6 @@
 | 
				
			|||||||
(def t (sin (div (time) 100)))
 | 
					(def t (sin (div (time) 100)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(def pos (add 200 (mul 30 t)))
 | 
					(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")
 | 
					(stroke (square pos) 1 "red")
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -1,18 +1,19 @@
 | 
				
			|||||||
 | 
					; dejong attractor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(
 | 
					(
 | 
				
			||||||
  (clear)
 | 
					  (clear)
 | 
				
			||||||
  (def point (lambda (x y color) (stroke (circle x y 0.1) 1 color)))
 | 
					  (defn point (x y color) (fill (circle x y 0.1) color))
 | 
				
			||||||
  (def _dejong (lambda (x y a b c d)
 | 
					  (defn _dejong (x y a b c d)
 | 
				
			||||||
    (rest ((point 
 | 
					    (rest ((point 
 | 
				
			||||||
      (add 700 (mul 100 x))
 | 
					      (add 300 (mul 100 x))
 | 
				
			||||||
      (add 400 (mul 100 y))
 | 
					      (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 (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)
 | 
				
			||||||
  (def dejong (lambda (r a b c d)
 | 
					 | 
				
			||||||
    (reduce  
 | 
					    (reduce  
 | 
				
			||||||
      (lambda (acc val)
 | 
					      (lambda (acc val)
 | 
				
			||||||
        (first (
 | 
					        (first (
 | 
				
			||||||
@@ -21,6 +22,6 @@
 | 
				
			|||||||
      (range 0 r)
 | 
					      (range 0 r)
 | 
				
			||||||
      (2 1)
 | 
					      (2 1)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  ))
 | 
					  )
 | 
				
			||||||
  (dejong 32000 1.4 -2.3 2.4 -2.1)
 | 
					  (dejong 128000 1.4 -2.3 2.4 -2.1)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,16 @@
 | 
				
			|||||||
 | 
					; recursive
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(
 | 
					(
 | 
				
			||||||
  (clear)
 | 
					  (clear)
 | 
				
			||||||
  (def rec 
 | 
					  (defn rec 
 | 
				
			||||||
    (lambda (v)
 | 
					    (v)
 | 
				
			||||||
      (if (gt v 0)
 | 
					      (if (gt v 0)
 | 
				
			||||||
        (
 | 
					        ((stroke (circle
 | 
				
			||||||
          (stroke (circle
 | 
					 | 
				
			||||||
                  (mul 5 v)
 | 
					                  (mul 5 v)
 | 
				
			||||||
                  (mul 5 v)
 | 
					                  (mul 5 v)
 | 
				
			||||||
                  (mul 5 v)) 1 "red")
 | 
					                  (mul 5 v)) 1 "red")
 | 
				
			||||||
          (rec (sub v 5))
 | 
					        (rec (sub v 5))))
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
        (echo "done"))))
 | 
					        
 | 
				
			||||||
  (rec 100)
 | 
					  (rec 100)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user