update reduce and examples
This commit is contained in:
parent
521ece7937
commit
50e13e932d
@ -90,8 +90,13 @@ function Library (ronin) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reduce = (fn, arr, acc = 0) => {
|
this.reduce = async (fn, arr, acc) => {
|
||||||
return arr.reduce(fn, acc)
|
const length = arr.length
|
||||||
|
let result = acc === undefined ? subject[0] : acc
|
||||||
|
for (let i = acc === undefined ? 1 : 0; i < length; i++) {
|
||||||
|
result = await fn(result, arr[i], i, arr)
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.len = (item) => {
|
this.len = (item) => {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
; animate
|
; animate
|
||||||
|
|
||||||
(
|
(
|
||||||
|
(clear)
|
||||||
(def t (sin (div (time) 100)))
|
(def t (sin (div (time) 100)))
|
||||||
|
|
||||||
(def pos (add 200 (mul 30 t)))
|
(def pos (add 200 30 (mul 30 t)))
|
||||||
(defn square (a) (rect a a a a))
|
(defn square (a) (rect a a a a))
|
||||||
(stroke (square pos) 1 "red")
|
(stroke (square pos) 1 "red")
|
||||||
|
|
||||||
(animate)
|
; set false to stop
|
||||||
;(animate false) to stop animation
|
(animate true)
|
||||||
)
|
)
|
@ -1,13 +1,15 @@
|
|||||||
; dejong attractor
|
; dejong attractor
|
||||||
|
|
||||||
(
|
(
|
||||||
(clear)
|
(clear)
|
||||||
(defn point (x y color) (fill (circle x y 0.1) color))
|
(defn point (x y 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))
|
||||||
"rgba(255,0,0,0.5)")
|
"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)))
|
||||||
))
|
))
|
||||||
@ -23,5 +25,5 @@
|
|||||||
(2 1)
|
(2 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(dejong 128000 1.4 -2.3 2.4 -2.1)
|
(dejong 1280 1.6 -2.3 2.4 -2.1)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user