Add transform, transform example.
This commit is contained in:
parent
605dd1fb9e
commit
1ca2f9776c
@ -17,6 +17,41 @@ function Library (ronin) {
|
||||
return ronin.surface.open(path)
|
||||
}
|
||||
|
||||
// Transforms
|
||||
|
||||
this.move = (x, y) => {
|
||||
ronin.surface.context.translate(x, y)
|
||||
}
|
||||
|
||||
this.rotate = (angle) => {
|
||||
ronin.surface.context.rotate(angle)
|
||||
}
|
||||
|
||||
this.scale = (x, y) => {
|
||||
ronin.surface.context.scale(x, y === undefined ? x : y)
|
||||
}
|
||||
|
||||
this.transform = (a, b, c, d, e, f) => {
|
||||
// a:hscale b:hskew c:vskew d:vscale e:hmove f:vmove
|
||||
ronin.surface.context.transform(a, b, c, d, e, f)
|
||||
}
|
||||
|
||||
this.setTransform = (a, b, c, d, e, f) => {
|
||||
ronin.surface.context.setTransform(a, b, c, d, e, f)
|
||||
}
|
||||
|
||||
this.resetTransform = () => {
|
||||
ronin.surface.context.resetTransform()
|
||||
}
|
||||
|
||||
this.pushTransform = () => {
|
||||
ronin.surface.context.save()
|
||||
}
|
||||
|
||||
this.popTransform = () => {
|
||||
ronin.surface.context.restore()
|
||||
}
|
||||
|
||||
// Shapes
|
||||
|
||||
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
||||
@ -241,7 +276,10 @@ function Library (ronin) {
|
||||
// Arrays
|
||||
|
||||
this.map = async (fn, arr) => {
|
||||
return Promise.all(arr.map(fn))
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const arg = arr[i];
|
||||
await fn(arg)
|
||||
}
|
||||
}
|
||||
|
||||
this.filter = (fn, arr) => {
|
||||
|
25
examples/transform.lisp
Normal file
25
examples/transform.lisp
Normal file
@ -0,0 +1,25 @@
|
||||
(resetTransform)
|
||||
(clear)
|
||||
|
||||
(defn branch
|
||||
(v)
|
||||
(if
|
||||
(gt v 0)
|
||||
(
|
||||
(scale 0.95)
|
||||
(stroke
|
||||
(line (pos 0 0) (pos 100 100))
|
||||
10 "white")
|
||||
(move 100 100)
|
||||
(pushTransform)
|
||||
(rotate (div v 50))
|
||||
(branch (sub v 1))
|
||||
(popTransform)
|
||||
(pushTransform)
|
||||
(rotate (div v -50))
|
||||
(branch (sub v 1))
|
||||
(popTransform)
|
||||
)
|
||||
)
|
||||
)
|
||||
(branch 10)
|
Loading…
x
Reference in New Issue
Block a user