xxxxxxxxxx
float xInit, yInit, xPlus, yPlus, xWidth, yHeight;
color [] colors = new color [2];
color Green = color(0, 144, 58);
color Lightgreen = color(142, 194, 31);
boolean goDir = true;
PImage img;
void setup() {
size(640, 360);
background(255);
smooth();
colors[0] = Green;
colors[1] = Lightgreen;
fill(colors[int(round(random(1)))]);
noStroke();
img = loadImage("test.jpg");
aPattern();
}
void draw() {
}
void keyPressed() {
if (key == '1') {
aPattern();
}
if (key == '2') {
bPattern();
}
if (key == '3') {
cPattern();
}
}
void allShapes(float _x, float _y, float _w, float _h) {
float x = _x;
float y = _y;
float w = _w;
float h = _h;
int numbers = 10;
int yAdd = 12;
int yMinus = 1;
for (int i = 0; i < yMinus * numbers; i += yMinus) {
beginShape();
vertex(x, y + i*yAdd);
vertex(x + w, y - h + i*yAdd);
vertex(x + w, y - i + i*yAdd);
vertex(x, y + h - i + i*yAdd);
endShape(CLOSE);
}
fill(colors[int(round(random(1)))]);
}
void aPattern() {
background(255);
xInit = 0;
yInit = 10.0 * random(-10, 10);
xPlus = 20.0;
yPlus = 160.0;
xWidth = 20.0;
yHeight = 10.0;
float y = yInit;
float x = xInit;
while (x < width) {
allShapes(x, y, xWidth, yHeight);
y += yPlus;
if (y > height) {
y = yInit * random(-20, 10);
x += xPlus;
}
}
}
void bPattern() {
background(255);
xInit = 0;
yInit = height - 10;
xPlus = 20.0;
yPlus = 15.0;
xWidth = 20.0;
yHeight = 10.0;
float y = yInit;
float x = xInit;
while (x < width) {
allShapes(x, y, xWidth, yHeight);
x += xPlus;
if (goDir == true) {
y -= yPlus * random(1, 2);
}
if (goDir == false) {
y += yPlus * random(1, 2);
}
if (y < 50) {
goDir = false;
}
if (y > height - 20) {
goDir = true;
}
}
}
void cPattern() {
background(255);
int steps = 10;
xWidth = 10.0;
yHeight = 5.0;
float w = xWidth;
float h = yHeight;
for (int x = 0; x < img.width; x += steps) {
for (int y = 0; y < img.height; y += steps) {
color c = img.pixels[y * img.width + x];
float b = brightness(c);
if (b < 200) {
int yAdd = 12;
beginShape();
vertex(x, y + yAdd);
vertex(x + w, y - h + yAdd);
vertex(x + w, y + yAdd);
vertex(x, y + h + yAdd);
endShape(CLOSE);
fill(colors[int(round(random(1)))]);
}
}
}
}