Added star example
This commit is contained in:
parent
3093a74d57
commit
0b72893ae9
@ -33,6 +33,7 @@ function Commander (ronin) {
|
|||||||
|
|
||||||
this.run = (txt = this._input.value) => {
|
this.run = (txt = this._input.value) => {
|
||||||
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
|
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
|
||||||
|
ronin.surface.maximize()
|
||||||
ronin.interpreter.run(txt)
|
ronin.interpreter.run(txt)
|
||||||
ronin.always === true && requestAnimationFrame(() => this.run(txt))
|
ronin.always === true && requestAnimationFrame(() => this.run(txt))
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ function Library (ronin) {
|
|||||||
return { x, y, w, h, t }
|
return { x, y, w, h, t }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.circle = (x, y, r, t = 'circle') => { // Returns a circle shape.
|
this.circle = (cx, cy, r, t = 'circle') => { // Returns a circle shape.
|
||||||
return { x, y, r, t }
|
return { cx, cy, r, t }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.line = (a, b, t = 'line') => { // Returns a line shape.
|
this.line = (a, b, t = 'line') => { // Returns a line shape.
|
||||||
@ -345,6 +345,11 @@ function Library (ronin) {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.table = (arg) => {
|
||||||
|
console.table(arg)
|
||||||
|
return arg
|
||||||
|
}
|
||||||
|
|
||||||
this.time = (rate = 1) => { // Returns timestamp in milliseconds.
|
this.time = (rate = 1) => { // Returns timestamp in milliseconds.
|
||||||
return (Date.now() * rate)
|
return (Date.now() * rate)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ function Surface (ronin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.traceCircle = function (circle, context) {
|
this.traceCircle = function (circle, context) {
|
||||||
context.arc(circle.x, circle.y, circle.r, 0, 2 * Math.PI)
|
context.arc(circle.cx, circle.cy, circle.r, 0, 2 * Math.PI)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.traceText = function (text, context) {
|
this.traceText = function (text, context) {
|
||||||
|
51
examples/stars.lisp
Normal file
51
examples/stars.lisp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
; stars
|
||||||
|
(clear)
|
||||||
|
;
|
||||||
|
(defn deg-rad
|
||||||
|
(deg)
|
||||||
|
(mul deg
|
||||||
|
(div PI 180)))
|
||||||
|
;
|
||||||
|
(defn circle-pos
|
||||||
|
(cx cy r a) {:x
|
||||||
|
(add cx
|
||||||
|
(mul r
|
||||||
|
(cos a))) :y
|
||||||
|
(add cy
|
||||||
|
(mul r
|
||||||
|
(sin a)))})
|
||||||
|
;
|
||||||
|
(defn draw-spoke
|
||||||
|
(cx cy r a)
|
||||||
|
(
|
||||||
|
(stroke
|
||||||
|
(line
|
||||||
|
(pos cx cy)
|
||||||
|
(circle-pos cx cy r a)) 2 "white")))
|
||||||
|
;
|
||||||
|
(defn draw-star
|
||||||
|
(cx cy r c)
|
||||||
|
(
|
||||||
|
(times c
|
||||||
|
(lambda
|
||||||
|
(i)
|
||||||
|
(
|
||||||
|
(draw-spoke cx cy r
|
||||||
|
(deg-rad
|
||||||
|
(mul i
|
||||||
|
(div 360 c)))))))))
|
||||||
|
; main
|
||||||
|
(times 100
|
||||||
|
(λ
|
||||||
|
()
|
||||||
|
(
|
||||||
|
(draw-star
|
||||||
|
(random 100
|
||||||
|
(of
|
||||||
|
(frame) :w))
|
||||||
|
(random 100
|
||||||
|
(of
|
||||||
|
(frame) :h))
|
||||||
|
(random 10 100)
|
||||||
|
(floor
|
||||||
|
(random 3 32))))))
|
Loading…
x
Reference in New Issue
Block a user