c.moveto html,HTML5 Canvas的使用

测试

window.onload = function () {

C = Math.cos;

S = Math.sin;

U=0;

canvas = document.getElementById("myCanvas");

c = canvas.getContext("2d");

var W = canvas.width = window.innerWidth;

var H = canvas.height = window.innerHeight;

var U=180>>0;

c.fillRect(0, 0, W, H); // resize and draw black rect (default)

c.globalCompositeOperation = "lighter"; // switch to additive color application

c.lineWidth = 10.0;//设置画笔的大小

c.lineCap = "round";//设置圆滑

t = 0;

var bool = 0;

canvas.onmousemove = function (e) {

if(window.T) {

if(D==0) {

D=Math.random()*15;}

clearTimeout(T);

}

X = e.pageX; // grab mouse pixel coords

Y = e.pageY;

R = e.pageX/W

r = e.pageY/H

a=0; // previous coord.x

b=0; // previous coord.y

A = X, // original coord.x

B = Y; // original coord.y

U=e.pageX/H * 360 >>0;

D=0;

g = Math.PI/180;

T = setInterval(f = function (e) {

c.save();

c.globalCompositeOperation = "source-over";

if(e!=1) {

c.fillStyle = "rgba(0,0,0,0.1)";

c.fillRect(0, 0, W, H);

}

c.restore();

i = 30;

while(i --) {

c.beginPath();

if(D > 200 || bool) { // decrease diameter

if(!bool) { // has hit maximum

bool = 1;

}

if(D < 0.1) { // has hit minimum

bool = 0;

}

t -= g; // decrease theta

D -= 0.1; // decrease size

}

if(!bool) {

t += g; // increase theta

D += 0.1; // increase size

}

x = D*C(t)+X;

y = D*S(t)+Y;

if (a) {

c.moveTo(a, b);

c.lineTo(x, y);

}

c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; // draw rainbow hypotrochoid

c.stroke();

a = x; // set previous coord.x

b = y; // set previous coord.y

U -= 0.5; // increment hue

A = X; // set original coord.x

B = Y; // set original coord.y

}

},20);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值