html5 canvas circle,HTML5 canvas 创意:飞翔的凤凰

当我看到这件作品的时候,我表示非常喜欢。这个作品的产生不仅仅需要编程和算法,作者肯定是个充满了艺术细胞的人。倘若有什么canvas艺术作品比赛的话,我想它就是获奖的那个。

先观赏下演示吧。注意,要看到效果,请确保你的浏览器支持 HTML 5。如果你还在使用旧版 IE,请更换新版浏览器。

效果演示

代码如下:

function fillCircle(ctx, r)

{

ctx.beginPath();

ctx.moveTo(r, 0);

ctx.fillStyle = 'rgb(245,50,50)';

ctx.arc(0,0,r,0,Math.PI*2,true);

ctx.fill();

}

function branch(ctx, r, d, t, a)

{

ctx.save();

ctx.rotate(t*a);

ctx.translate(0, -r*(1+d));

wing(ctx, r*d, a);

ctx.restore();

}

function feather(ctx, r)

{

if ( r < 3 ) return;

var d = 0.85;

ctx.rotate(-0.03*Math.PI);

ctx.translate(0, -r*(1+d));

fillCircle(ctx, r);

feather(ctx, r*d);

}

function wing(ctx, r, a)

{

if ( r < 2.9 ) return;

fillCircle(ctx, r);

branch(ctx, r, 0.9561, 0.03*Math.PI, a);

ctx.save();

ctx.rotate(0.55*Math.PI);

feather(ctx, 0.8*r);

ctx.restore();

}

function tail(ctx, s, a)

{

if ( s < 0.5 ) return;

var d = 0.98; // decay

fillCircle(ctx, s);

ctx.rotate(-0.15*a);

ctx.translate(0, s*(1+d));

tail(ctx, s*d, a);

}

function head(ctx)

{

fillCircle(ctx, 22);

// mouth

ctx.save();

ctx.translate(-15, -3);

ctx.beginPath();

ctx.fillStyle = "white";

ctx.arc(0,0,10,0,Math.PI*2,true);

ctx.fill();

ctx.restore();

// eye

ctx.translate(9, -4);

ctx.beginPath();

ctx.fillStyle = "black";

ctx.arc(0,0,5,0,Math.PI*2,true);

ctx.fill();

// horn

ctx.translate(6, -8);

ctx.rotate(0.6*Math.PI);

wing(ctx, 5.5, 1.8);

}

function neck(ctx, s)

{

if ( s < 10 ) { head(ctx); return; }

var d = 0.85;

fillCircle(ctx, s);

ctx.save();

ctx.rotate(-Math.PI/2);

ctx.translate(0, s);

fillCircle(ctx, s/2);

ctx.restore();

ctx.rotate(-0.15);

ctx.translate(0, -s*(1+d));

neck(ctx, s*d);

}

function loop(ctx, i) {

var inner = function() {

i++;

ctx.fillStyle = "white";

ctx.fillRect(-1500,-1500,3000,3000);

ctx.save();

ctx.translate(0, Math.cos(i*0.1)*40);

var a = Math.sin(i*0.1);

// right wing

ctx.save();

ctx.rotate(Math.PI*0.4);

wing(ctx, 18, a);

ctx.restore();

// left wing

ctx.save();

ctx.scale(-1, 1);

ctx.rotate(Math.PI*0.4);

wing(ctx, 18, a);

ctx.restore();

// tail

ctx.save();

tail(ctx, 20, Math.sin(i*0.05));

ctx.restore();

// head

neck(ctx, 22);

ctx.restore();

setTimeout(inner, 35); // change speed here

};

return inner;

}

function draw() {

var canvas = document.getElementById("canvas");

var ctx = canvas.getContext("2d");

ctx.translate(490, 410);

ctx.scale(0.4,0.4);

setTimeout(loop(ctx, 1), 1);

}

HTML

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值