Processing 在处理草图时向下移动生成的图像

Processing 在处理草图时向下移动生成的图像,processing,processing.js,Processing,Processing.js,我是处理新手,希望让下面的草图向下移动图像,而不是向上移动。我尝试过调整y到y+=虚空移动速度,这样做了,但图像不会重新加载,它们只执行一个周期,屏幕变为空白 您的帮助将不胜感激:- Spot[] sp = new Spot[60]; PImage myImage; /* @pjs preload="http://mathatelle.appspot.com/imgs/drawing_circle.png"; */ void setup() { size(800, 400); imageMod

我是处理新手,希望让下面的草图向下移动图像,而不是向上移动。我尝试过调整y到y+=虚空移动速度,这样做了,但图像不会重新加载,它们只执行一个周期,屏幕变为空白

您的帮助将不胜感激:-

Spot[] sp = new Spot[60];
PImage myImage;
/* @pjs preload="http://mathatelle.appspot.com/imgs/drawing_circle.png"; */

void setup() {
size(800, 400);
imageMode(CENTER);
myImage = loadImage("http://mathatelle.appspot.com/imgs/drawing_circle.png"); //100x100px
for (int i = 0; i < sp.length; i++) {
sp[i] = new Spot(random(width), random(height), random(0.2,1.0), random(0.1,1.0));
}
}

void draw() {
background(0);
for (int i = 0; i < sp.length; i++) {
sp[i].move();
sp[i].display();
}
}

class Spot {
float x, y, diameter, speed; // x座標, y座標, 直径, 速さ

Spot(float _x, float _y, float _diameter, float _speed) {
x = _x;
y = _y;
diameter = _diameter;
speed = _speed;
}

void move() {
speed *= 1.01;
y -= speed;
if (y < - myImage.width*diameter/2) {
x = random(width);
y = height + myImage.width*diameter/2;
speed = random(0.5,3);
}
}

void display() {
pushMatrix();
translate(x, y);
rotate(TWO_PI*diameter);
scale(diameter);
//tint(255, 255, 255, 153);
image(myImage, 0, 0);
popMatrix();
}
}

逻辑已经颠倒了,但只要再颠倒一下:

代码中有以下注释:

Spot[]sp=新Spot[60]; PImage myImage; /*@pjs预载=http://mathatelle.appspot.com/imgs/drawing_circle.png; */ 无效设置{ 尺寸800400; 图像处理中心; myImage=loadImagehttp://mathatelle.appspot.com/imgs/drawing_circle.png;//100x100px 对于int i=0;i高度+我的图像。宽度*直径/2{ x=宽度; y=高度+我的图像。宽度*直径/2; 速度=0.5,3; } } 空白显示{ pushMatrix; translatex,y; 旋转至π*直径; 刻度流量计; //tint255、255、255、153; imagemyImage,0,0; popMatrix; } }
一位朋友帮了我的忙,这是解决我问题的方法:-

Spot[] sp = new Spot[60];
PImage myImage;
/* @pjs preload="http://mathatelle.appspot.com/imgs/drawing_circle.png"; */

void setup() {
size(800, 400);
imageMode(CENTER);
myImage = loadImage("http://mathatelle.appspot.com/imgs/drawing_circle.png"); //100x100px
for (int i = 0; i < sp.length; i++) {

// a little change where spots are created...
sp[i] = new Spot(random(width), random(-myImage.height, height - 100), random(0.2, 1.0),        random(0.1, 1.0));
}
}

void draw() {
background(0);
for (int i = 0; i < sp.length; i++) {
sp[i].move();
sp[i].display();
}
}

class Spot {
float x, y, diameter, speed; // x座標, y座標, 直径, 速さ

Spot(float _x, float _y, float _diameter, float _speed) {
x = _x;
y = _y;
diameter = _diameter;
speed = _speed;
}

void move() {
speed *= 1.01;

y += speed;

// change y = 0 - ...
if (y > height + myImage.width*diameter/2) {
  x = random(width);
  y = 0 - myImage.width*diameter/2;
  speed = random(0.5, 3);
}
}

void display() {
pushMatrix();
translate(x, y);
rotate(TWO_PI*diameter);
scale(diameter);
//tint(255, 255, 255, 153);
image(myImage, 0, 0);
popMatrix();
}
}

我以前试过这样做,但是图像只下了一次雨,然后屏幕变成空白,而在另一个版本中,它们不断生成。