xxxxxxxxxx
117
function setup() {
cnv = createCanvas(800, 80);
angleMode(DEGREES);
}
function draw() {
blendMode(BLEND);
background("red");
drawWave1();
//drawWave2();
blendMode(BLEND);
for (let i = 0; i < 5; i++) {
//drawBoat((frameCount + 100 * i) % width, 15, 0.15, "white", "white");
drawTerrorist((frameCount + 200 * i) % width, 35, 0.2, "red", "black");
drawBomb((frameCount + 200 * i) % width+100, 35, 0.2, "white", "black");
}
}
function drawBoat(x, y, s, c1, c2) {
//tc
push();
translate(x, y);
rotate(sin(frameCount * 4) * 15);
scale(s);
fill(c1);
noStroke();
triangle(212, 22, 64, 231, 206, 232); // left sail
rect(216, 17, 11, 246); // pole
fill(c2);
triangle(236, 26, 348, 239, 231, 230); // right sail
quad(50, 253, 368, 257, 316, 300, 86, 302); // body
pop();
}
function drawWave1() {
beginShape();
fill("black");
noStroke();
vertex(0, height); //lower left
for (let i = 0; i <= width; i++) {
vertex(i, 1/sin(frameCount - i) * 20 + 40);
}
vertex(width, height); // ]lower right
endShape();
}
function keyPressed() {
// this will download the first x seconds of the animation!
if (key == "s") {
saveGif("800x80", 5);
}
if (key == "c") {
saveCanvas(cnv, "myCanvas.png");
}
}
function drawBomb(x,y,s,color1,color2)
{
push();
translate(x, y);
rotate(frameCount * -5);
scale(s);
strokeWeight(20);
stroke(color1);
fill(color2);
circle(0, 0, 100);
line(0, -50,0,-150);
pop();
}
function drawTerrorist(x, y, s, color1, color2) {
//Zhiyi
let xX = (3 * width) / 4;
let yY = height / 2;
xX = 0;
yY = 0;
push();
translate(x, y);
rotate(frameCount * 5);
scale(s);
strokeWeight(10);
stroke(color1);
// Draw the head
fill(255);
circle(xX, yY, 200);
// Draw the body
fill(color2);
rect(xX - 20, yY + 100, 40, 120);
// Draw the arms
line(xX - 70, yY + 120, xX + 70, yY + 120);
// Draw the eyes
circle(xX - 40, yY - 20, 30);
line(xX-80,yY-60, xX - 40, yY - 20);
circle(xX + 40, yY - 20, 30);
line(xX+80,yY-60, xX + 40, yY - 20);
// Draw the bomb
circle(xX - 70, yY + 120, 50);
line(xX - 70, yY + 95, xX - 95, yY + 70);
pop();
}