HTML5 canvas绘制图形实例


HTML5绘制圆形

HTML5 canvas绘制图形实例_第1张图片
12-1.png



    
    绘制圆形
    


    



HTML5 moveTo与lineTo

HTML5 canvas绘制图形实例_第2张图片
12-2.png




    
    moveTo与lineTo
    


    



使用bezierCurveTo绘制贝塞尔曲线

HTML5 canvas绘制图形实例_第3张图片
12-3.png





    
    BezierCurveTo贝塞尔曲线
    


    



HTML5 Canvas 绘制渐变图形

HTML5 canvas绘制图形实例_第4张图片
13-1.png




    
    绘制渐变图形
    


绘制渐变图形,createLinearGradient(起始坐标点,结束坐标点)
addColorStop(offset,color)设定颜色,offset颜色距离起始点的偏移量





HTML5 Canvas 绘制径向渐变

HTML5 canvas绘制图形实例_第5张图片
13-3.png



    
    绘制径向渐变图形
    






HTML5 Canvas 绘制变形图形

HTML5 canvas绘制图形实例_第6张图片
13-2.png




    
    绘制变形图形
    






Canvas 使用图像

HTML5 canvas绘制图形实例_第7张图片
微信截图.png




    
    Title
    







HTML5 Canvas 给图形绘制阴影

HTML5 canvas绘制图形实例_第8张图片
Stars in the sky



    
    Title
    






认识CreateJS

html部分:



    
    认识createjs
    


    
    


js部分:
/**
 * Created by Administrator on 2018/1/8 0008.
 */

let canvas,stage,txt
let count = 0
window.onload = function () {
    canvas = document.getElementById("canvas")
    stage = new createjs.Stage(canvas)

    txt = new createjs.Text("number->","20px Arial","#ff7700")
    stage.addChild(txt)
    //设置监听,用来显示
    createjs.Ticker.setFPS(30)
    createjs.Ticker.addEventListener("tick",tick)

}
    function tick(e){
        count++
        txt.text = "bumber->" + count + "!"
        stage.update()
    }


使用Canvas制作炫酷的效果

HTML:



    
    使用Canvas制作炫酷的效果


    
    


JS:
/**
 * Created by Administrator on 2018/1/8 0008.
 */


let canvas,stage
let img = new Image()
let sprite

window.onload = function () {
    canvas = document.getElementById("canvas")
    stage = new createjs.Stage(canvas)

    stage.addEventListener("stagemousedown",clickCanvas)
    stage.addEventListener("stagemousemove",moveCanvas)

    let data = {
        images:["2.png"],
        frames:{width:20,height:20,regX:10,regY:10}
    }
    sprite = new createjs.Sprite(new createjs.SpriteSheet(data))
    createjs.Ticker.setFPS(20)
    createjs.Ticker.addEventListener("tick",tick)
}
function tick(e){
    let t = stage.getNumChildren()
    for(let i = t-1;i>0;i--){
        let s = stage.getChildAt(i)

        s.vY+=2
        s.vX+=1
        s.x += s.vX
        s.y += s.vY

        s.scaleX = s.scaleY = s.scaleX+s.vS
        s.alpha+=s.vA

        if(s.alpha<= 0|s.y>canvas.height){
            stage.removeChildAt(i)
        }
    }
    stage.update()
}

function clickCanvas(e){
    adds(Math.random()*200+100,stage.mouseX,stage.mouseY,2)

}

function moveCanvas(e){
    adds(Math.random()*2+1,stage.mouseX,stage.mouseY,1)
}

function adds(count,x,y,speed){
    for(let  i =0;i

你可能感兴趣的:(HTML5 canvas绘制图形实例)