study/p5js/4.风扇.js

32 lines
573 B
JavaScript
Raw Normal View History

2022-12-18 07:56:32 +00:00
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();
}