求助,救救孩子把这个js的改成Java的
processing吧
全部回复
仅看楼主
level 1
let p = [];
let n;
let img;
function setup() {
createCanvas(600, 750);
background(255);
img = loadImage('pintura.png');
n = 500;
for(let i = 0; i < n; i++) {
p.push(new Pincel());
}
}
function draw() {
for(let i = 0; i < n; i++) {
p[i].display();
p[i].move();
p[i].checkEdges();
}
}
class Pincel {
constructor() {
this.pos = createVector(width/2, height/2);
this.vel = createVector();
this.acel = createVector();
}
move() {
this.acel = p5.Vector.random2D();
this.acel.mult(0.02);
this.vel.add(this.acel);
this.vel.limit(5);
this.pos.add(this.vel);
}
display() {
let c = img.get(this.pos.x, this.pos.y);
noFill();
stroke(c);
strokeWeight(3);
rectMode(CENTER);
rect(this.pos.x, this.pos.y, 10, 10);
}
checkEdges() {
if(this.pos.x < 0 || this.pos.x > width)
this.vel.x *= -1;
if(this.pos.y < 0 || this.pos.y > height)
this.vel.y *= -1;
}
}
2021年06月18日 04点06分 1
1