mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 11:21:06 +01:00
Examples updates for 2.0
This commit is contained in:
@@ -10,12 +10,11 @@ int unit = 40;
|
||||
int count;
|
||||
Module[] mods;
|
||||
|
||||
|
||||
void setup() {
|
||||
size(320, 240);
|
||||
size(640, 360);
|
||||
background(176);
|
||||
noStroke();
|
||||
|
||||
smooth();
|
||||
int wideCount = width / unit;
|
||||
int highCount = height / unit;
|
||||
count = wideCount * highCount;
|
||||
@@ -24,13 +23,13 @@ void setup() {
|
||||
int index = 0;
|
||||
for (int y = 0; y < highCount; y++) {
|
||||
for (int x = 0; x < wideCount; x++) {
|
||||
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8));
|
||||
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
mods[i].update();
|
||||
mods[i].draw();
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
class Module {
|
||||
int mx, my;
|
||||
int big;
|
||||
int xOffset;
|
||||
int yOffset;
|
||||
float x, y;
|
||||
int xdir = 1;
|
||||
int ydir = 1;
|
||||
int unit;
|
||||
int xDirection = 1;
|
||||
int yDirection = 1;
|
||||
float speed;
|
||||
|
||||
// Contructor (required)
|
||||
Module(int imx, int imy, int ix, int iy, float ispeed) {
|
||||
mx = imx;
|
||||
my = imy;
|
||||
x = ix;
|
||||
y = iy;
|
||||
speed = ispeed;
|
||||
big = unit;
|
||||
// Contructor
|
||||
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
|
||||
xOffset = xOffsetTemp;
|
||||
yOffset = yOffsetTemp;
|
||||
x = xTemp;
|
||||
y = yTemp;
|
||||
speed = speedTemp;
|
||||
unit = tempUnit;
|
||||
}
|
||||
|
||||
// Custom method for updating the variables
|
||||
void update() {
|
||||
x = x + (speed * xdir);
|
||||
if (x >= big || x <= 0) {
|
||||
xdir *= -1;
|
||||
x = x + (1 * xdir);
|
||||
y = y + (1 * ydir);
|
||||
x = x + (speed * xDirection);
|
||||
if (x >= unit || x <= 0) {
|
||||
xDirection *= -1;
|
||||
x = x + (1 * xDirection);
|
||||
y = y + (1 * yDirection);
|
||||
}
|
||||
if (y >= big || y <= 0) {
|
||||
ydir *= -1;
|
||||
y = y + (1 * ydir);
|
||||
if (y >= unit || y <= 0) {
|
||||
yDirection *= -1;
|
||||
y = y + (1 * yDirection);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom method for drawing the object
|
||||
void draw() {
|
||||
stroke(second() * 4);
|
||||
point(mx+x-1, my+y-1);
|
||||
fill(255);
|
||||
ellipse(xOffset + x, yOffset + y, 6, 6);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user