## WAVE

2011-10-31 10:53  【当耐特】  阅读(3507)  评论(9编辑  收藏

# 二.实现

       var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
var angel = 2 * Math.PI;
var step = Math.PI / 10;
function draw() {
cxt.clearRect(0, 0, 1000, 1000);
for (var i = 0; i < 600; i += 10) {
cxt.fillStyle = randomColor();
cxt.beginPath();
angel -= step;
cxt.arc(i, 100, 7, 0, Math.PI * 2, true);
cxt.closePath();
cxt.fill();
}
}
draw();
function randomColor() {
var arrHex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; var strHex = "#";
var index;
for (var i = 0; i < 6; i++) {
index = Math.round(Math.random() * 15);
strHex += arrHex[index];
}
return strHex;
} 

       var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
var angel = 2 * Math.PI;
var step = Math.PI / 10;
function draw() {
cxt.clearRect(0, 0, 1000, 1000);
for (var i = 0; i < 600; i += 10) {
cxt.fillStyle = randomColor();
cxt.beginPath();
angel -= step;
cxt.arc(i, 150 + 100 * Math.cos(angel), 7, 0, Math.PI * 2, true);
cxt.closePath();
cxt.fill();
}
}
draw();

       var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
var angel = 2 * Math.PI;
var step = Math.PI / 10;
function draw() {
cxt.clearRect(0, 0, 1000, 1000);
for (var i = 0; i < 600; i += 10) {
cxt.fillStyle = randomColor();
cxt.beginPath();
angel -= step;
cxt.arc(i, 150 + 100 * Math.cos(angel), 7, 0, Math.PI * 2, true);
cxt.closePath();
cxt.fill();
}
}
var step2 = 0.2;
var waveAsync = eval(Jscex.compile("async", function () {
while (true) {
angel = 2 * Math.PI;
angel -= step2;
step2 += 0.1;
\$await(Jscex.Async.sleep(100))
draw();
}
}))
waveAsync().start();