var
canvas=document.getElementById(
"ballBroad"
);
var
context=canvas.getContext(
"2d"
);
var
angle=0;
var
speedAngle=0.1;
var
frames=1000/60;
var
Ball=
function
(radius,color,x,y)
{
this.radius=radius;
this.color=color;
this.x=x;
this.y=y;
}
var
centerX=canvas.width/2;
var
centerY=canvas.height/2;
var
points=[];
var
newBall=
new
Ball(20,
"#ff000"
,0,centerY);
var
drawAsync =
eval
(Jscex.compile(
"async"
,
function
() {
while
(true)
{
newBall.y=centerY+Math.sin(angle)*(centerY/2+20);
newBall.x=centerX+Math.
cos
(angle)*centerX;
angle+=speedAngle;
DrawBall(newBall);
points.push({x:newBall.x,y:newBall.y});
DrawBallLine();
DrawText(
"蛋疼"
,centerX-50,centerY);
$await
(Jscex.Async.sleep(frames));
}
}));
drawAsync().start();
function
DrawBall(ball)
{
context.clearRect(0, 0, canvas.width, canvas.height);
context.beginPath();
context.arc(ball.x, ball.y, newBall.radius, 0, 2 * Math.PI, false);
context.fillStyle = ball.color;
context.fill();
context.lineWidth = 5;
context.strokeStyle =
"#ff0000"
;
context.stroke();
}
function
DrawBallLine()
{
for
(
var
i=0;i<points.length;i++)
{
if
(i==0)
{
context.moveTo(points[i].x,points[i].y)
}
context.lineTo(points[i].x,points[i].y)
context.stroke();
}
}
function
DrawText(text,x,y)
{
context.font =
"40pt Arial"
;
context.fillText(text, x, y);
}