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) => {
|
||||
return arr.reduce(fn, acc)
|
||||
this.reduce = async (fn, arr, 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) => {
|
||||
|
@ -1,12 +1,13 @@
|
||||
; animate
|
||||
|
||||
(
|
||||
(clear)
|
||||
(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))
|
||||
(stroke (square pos) 1 "red")
|
||||
|
||||
(animate)
|
||||
;(animate false) to stop animation
|
||||
; set false to stop
|
||||
(animate true)
|
||||
)
|
@ -2,12 +2,14 @@
|
||||
|
||||
(
|
||||
(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)
|
||||
(rest ((point
|
||||
(add 300 (mul 100 x))
|
||||
(add 400 (mul 100 y))
|
||||
"rgba(255,0,0,0.5)")
|
||||
"red")
|
||||
(add (sin (mul a y)) (mul x (cos (mul b x))))
|
||||
(add (mul x (sin (mul x c))) (cos (mul d y)))
|
||||
))
|
||||
@ -23,5 +25,5 @@
|
||||
(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