/**************************************
波浪正方形
1.(x,y)代表圆心所在的位置
2.omega代表开始的角度
**************************************/
function WaveRect(x,y,omega)
1.2.2 调用方法案例(demo)
var rot =0, rotSpeed =.04;
function setup(){createCanvas(500,500);noFill();stroke(0);strokeWeight(2);}
function draw(){background(255);translate(width/2, height/2);
rot += rotSpeed;
rot %= TWO_PI;WaveRect(20,20,frameCount/20.0);WaveRect(20,20,frameCount/20.0+PI/2);WaveRect(20,20,frameCount/20.0+3*PI/2);}
2 宇宙长方形
2.1 效果展示
2.2 波浪圆函数调用方法
2.2.1 函数参数解释
/**************************************
宇宙正方形
1.Star是组成方形的粒子
**************************************/
class Star {constructor(){}}
2.2.2 调用方法案例(demo)
let stars =[];
function setup(){createCanvas(windowWidth, windowHeight);background(0);for(let i =0; i <2000; i++){
stars.push(new Star());}
mouseX =0.7* width;}
function draw(){background(0);translate(width/2, height/2);for(let i =0; i < stars.length; i++){
stars[i].update();
stars[i].show();}}
//大小改变的例子
var n =1;
p =[];
function setup(){createCanvas(500,500);noFill();rectMode(CENTER);
n =1;for(var i =0; i < n; i++){
var d =random(10.0,100.0);
p.push(new MovingBounceRectChangeSize(random(d /2, width - d /2),random(d /2, width - d /2),
d,random(1.0,5.0),random(1.0,5.0),1));}}
function draw(){background(255);stroke(0);for(var i =0; i < n; i++){
p[i].update();
p[i].display();}}
3.3 弹跳正方形作图
var n =50;
p =[];
function setup(){createCanvas(500,500);noFill();rectMode(CENTER);for(var i =0; i < n; i++){
var d =random(10.0,100.0);
p.push(new MovingBounceRectChangeSize(random(d /2, width - d /2),random(d /2, width - d /2),
d,random(1.0,5.0),random(1.0,5.0),1));}}
function draw(){background(255);stroke(0);for(var i =0; i < n; i++){
p[i].update();
p[i].display();}}