study/p5js/4.风扇.js
2022-12-18 15:56:32 +08:00

32 lines
573 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Circle {
// 构造器。
constructor(x, y, d, c) {
this.x = x;
this.y = y;
this.d = d;
this.c = c;
}
// draw中文画。
draw() {
noStroke();
fill(this.c);
ellipse(this.x, this.y, this.d);
}
}
// 全局常量或变量。
const width = 300;
const height = 500;
let c1, c2;
function setup() {
createCanvas(width, height);
c1 = new Circle(90, 90, 80, "#DDDD00");
c2 = new Circle(90, 180, 80, 'red');
}
function draw() {
background(150);
c1.draw();
c2.draw();
}