Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draw canvas #7

Open
Yang03 opened this issue Jun 28, 2019 · 0 comments
Open

draw canvas #7

Yang03 opened this issue Jun 28, 2019 · 0 comments

Comments

@Yang03
Copy link
Owner

Yang03 commented Jun 28, 2019

}
drawCircle(color, percent) {
this.ctx.beginPath()
this.ctx.setLineCap('round')
this.ctx.setStrokeStyle(color)
this.ctx.setLineWidth(5)
this.ctx.arc(100, 100, 90, Math.PI * 1, Math.PI * percent, 0)
this.ctx.stroke()
this.ctx.closePath()
}
drawPercent(percent = 1) {
const { homeStore: { homeState }} = this.props
const nowSteps = parseInt(homeState.step, 10)
const userTarget = parseInt(homeState.targetStep, 10)
let max = nowSteps / userTarget + 1
max = max >= 2 ? 2 : max
if (this.cacheStep === nowSteps) return
const timer = setInterval(() => {
if (percent < max) {
percent += 0.01
this.drawCircle('#dedede', 2)
this.drawCircle('#15CD8D', percent)
this.ctx.draw()
} else {
clearInterval(timer)
}
}, 1000 / 60)
if (this.cacheStep != nowSteps) {
this.cacheStep = nowSteps
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant