This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
dwelibs/src/context.js

45 lines
949 B
JavaScript

DWE.context = function (ctx) {
ctx.star = function (cx, cy, spikes, outerRadius, innerRadius) {
var rot=Math.PI/2*3
var x=cx
var y=cy
var step=Math.PI/spikes
ctx.beginPath()
ctx.moveTo(cx,cy-outerRadius)
for(let i=0;i<spikes;i++){
x=cx+Math.cos(rot)*outerRadius
y=cy+Math.sin(rot)*outerRadius
ctx.lineTo(x,y)
rot+=step
x=cx+Math.cos(rot)*innerRadius
y=cy+Math.sin(rot)*innerRadius
ctx.lineTo(x,y)
rot+=step
}
ctx.lineTo(cx,cy-outerRadius)
ctx.closePath()
}
ctx.fillStar = function (cx, cy, spikes, outerRadius, innerRadius) {
ctx.star(cx, cy, spikes, outerRadius, innerRadius)
ctx.fill()
}
ctx.circle = function (x, y, r, d) {
if (!d) d = 0
ctx.beginPath()
ctx.arc(x, y, r, d, Math.PI * 2, true)
ctx.closePath()
}
ctx.fillCircle = function (x, y, r, d) {
ctx.circle(x, y, r, d)
ctx.fill()
}
return ctx
}