Add ellipse shape
This commit is contained in:
parent
7d153fb3f1
commit
2eafa354bb
@ -53,6 +53,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(size w h)` Returns a size shape.
|
- `(size w h)` Returns a size shape.
|
||||||
- `(rect x y w h)` Returns a rect shape.
|
- `(rect x y w h)` Returns a rect shape.
|
||||||
- `(circle cx cy r)` Returns a circle shape.
|
- `(circle cx cy r)` Returns a circle shape.
|
||||||
|
- `(ellipse cx cy rx ry)` Returns an ellipse shape.
|
||||||
- `(line ax ay bx by)` Returns a line shape.
|
- `(line ax ay bx by)` Returns a line shape.
|
||||||
- `(text x y p t ~a ~f)` Returns a text shape.
|
- `(text x y p t ~a ~f)` Returns a text shape.
|
||||||
- `(svg x y d)` Returns a svg shape.
|
- `(svg x y d)` Returns a svg shape.
|
||||||
|
@ -70,6 +70,10 @@ function Library (ronin) {
|
|||||||
return { cx, cy, r }
|
return { cx, cy, r }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ellipse = (cx, cy, rx, ry) => { // Returns a ellipse shape.
|
||||||
|
return { cx, cy, rx, ry }
|
||||||
|
}
|
||||||
|
|
||||||
this.line = (ax, ay, bx, by) => { // Returns a line shape.
|
this.line = (ax, ay, bx, by) => { // Returns a line shape.
|
||||||
return { a: this.pos(ax, ay), b: this.pos(bx, by) }
|
return { a: this.pos(ax, ay), b: this.pos(bx, by) }
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,8 @@ function Surface (ronin) {
|
|||||||
}
|
}
|
||||||
if (isCircle(shape)) {
|
if (isCircle(shape)) {
|
||||||
this.traceCircle(shape, context)
|
this.traceCircle(shape, context)
|
||||||
|
} else if (isEllipse(shape)) {
|
||||||
|
this.traceEllipse(shape, context)
|
||||||
} else if (isText(shape)) {
|
} else if (isText(shape)) {
|
||||||
this.traceText(shape, context)
|
this.traceText(shape, context)
|
||||||
} else if (isSvg(shape)) {
|
} else if (isSvg(shape)) {
|
||||||
@ -122,6 +124,10 @@ function Surface (ronin) {
|
|||||||
context.arc(circle.cx, circle.cy, circle.r, 0, 2 * Math.PI)
|
context.arc(circle.cx, circle.cy, circle.r, 0, 2 * Math.PI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.traceEllipse = function (ellipse, context) {
|
||||||
|
context.ellipse(ellipse.cx, ellipse.cy, ellipse.rx, ellipse.ry, 0, 2 * Math.PI, false)
|
||||||
|
}
|
||||||
|
|
||||||
this.traceText = function (text, context) {
|
this.traceText = function (text, context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -287,6 +293,9 @@ function Surface (ronin) {
|
|||||||
function isCircle (shape) {
|
function isCircle (shape) {
|
||||||
return !isNaN(shape.cx) && !isNaN(shape.cy) && !isNaN(shape.r)
|
return !isNaN(shape.cx) && !isNaN(shape.cy) && !isNaN(shape.r)
|
||||||
}
|
}
|
||||||
|
function isEllipse (shape) {
|
||||||
|
return !isNaN(shape.cx) && !isNaN(shape.cy) && !isNaN(shape.rx) && !isNaN(shape.ry)
|
||||||
|
}
|
||||||
function isPos (shape) {
|
function isPos (shape) {
|
||||||
return !isNaN(shape.x) && !isNaN(shape.y)
|
return !isNaN(shape.x) && !isNaN(shape.y)
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,8 @@
|
|||||||
; draw line
|
; draw line
|
||||||
(stroke
|
(stroke
|
||||||
(line (sub center-w rad) center-h (add center-w rad) center-h))
|
(line (sub center-w rad) center-h (add center-w rad) center-h))
|
||||||
(stroke (text 10 170 200 "HELL") "pink" 2)
|
(stroke (text 10 170 200 "HELL") "pink" 2)
|
||||||
|
|
||||||
|
; draw ellipse
|
||||||
|
(stroke
|
||||||
|
(ellipse center-w center-h rad (div rad 2)) "white" 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user