Processing Forum
public int getRandomWithExclusion(Random rnd, int start, int end, int... exclude) {
int random = start + rnd.nextInt(end - start + 1 - exclude.length);
for (int ex : exclude) {
if (random < ex) {
break;
}
random++;
}
return random;
}
int calculateHeights(int i) { if (x < i && x > i-4) { index = 0; } if (x < i-4 && x > i-8) { index = 1; } if (x < i-8 && x > i-12) { index = 2; } if (x < i-12 && x > i-16) { index = 3; } if (x < i-16 && x > i-20) { index = 4; } if (x < i-20 && x > i-24) { index = 5; } if (x < i-24 && x > i-28) { index = 6; } if (x < i-28 && x > i-32) { index = 7; } if (x < i-32 && x > i-36) { index = 8; } if (x < i-36 && x > i-40) { index = 9; } if (x < i-40 && x > i-44) { index = 10; } if (x < i-44 && x > i-48) { index = 11; } if (x < i-48 && x > i-52) { index = 12; } if (x < i-52 && x > i-56) { index = 13; } if (x < i-56 && x > i-60) { index = 14; } if (x < i-60 && x > i-64) { index = 15; } return heights[index]; }
int offset = 64; int numberOfComponents = 14; int speed = 5; int numImages = 4; PImage[] imgs = new PImage[numImages]; Component[] pointComponents = new Component[numberOfComponents]; float[] yValues = { 0, 64, 128, 192, 256, 320, 384, 0, 64, 128, 192, 256, 320, 384, }; void setup() { size(800, 480, A2D); orientation(LANDSCAPE); for (int i = 0; i < imgs.length; i++) { imgs[i] = loadImage(i+".png"); } for (int i = 0; i < pointComponents.length; i++) { pointComponents[i] = new Component(i*offset, yValues[i]); } } void draw() { background(0); for (int i = 0; i < pointComponents.length; i++) { pointComponents[i].run(); } fill(255); text(frameRate, 40, 400); } class Component { PImage componentGraphic; float x, y; int index; String a; Component(float x, float y) { this.x = x; this.y = y; index = int(random(numImages)); } void run() { display(); move(); cycle(); } void display() { for (int i = 0; i < imgs.length; i++) { image(imgs[index], x, y+(i*offset)); } } void cycle() { if (x <= -60) { x=width; } } void move() { x -= speed; } }