码迷,mamicode.com
首页 > 其他好文 > 详细

【canvas】圆弧运动

时间:2014-11-25 18:08:58      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   on   

bubuko.com,布布扣

var canvas = document.getElementById(‘canvas‘)
var context = canvas.getContext(‘2d‘)

var angle = 0

function move() {
    context.clearRect(0,0,canvas.width,canvas.height)

    context.save()
    context.beginPath()
    context.lineWidth = 0.5
    context.strokeStyle = ‘red‘
    context.arc(canvas.width / 2, canvas.height / 2, 200, 0, Math.PI*2, false)
    context.stroke()
    context.restore()

    context.save()
    context.beginPath()
    context.fillStyle = ‘green‘
    context.strokeStyle = ‘green‘
    context.arc(canvas.width / 2 + Math.cos(angle) * 200, canvas.height / 2 + Math.sin(angle) * 200, 5, 0, Math.PI*2, false)
    angle += Math.PI * 2 / 360
    context.stroke()
    context.fill()
    context.restore()

    window.requestAnimationFrame(move)
}

window.requestAnimationFrame(move)

 

【canvas】圆弧运动

标签:style   blog   http   io   ar   color   os   sp   on   

原文地址:http://www.cnblogs.com/jzm17173/p/4121238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!