int RED = 0; int GREEN = 1; int BLUE = 2; int A = 3; class Pixorg { PGraphics flower; float fitness = 0; float waterLevel = 100f; Vector3D pos; float theta; float osc = 0; float stalkHeight = 32; float r = 32; Pixorg(PGraphics f, float x, float y, float theta_) { flower = f; pos = new Vector3D(x, y); osc = theta_; } // random flower Pixorg(float x, float y, float theta_) { pos = new Vector3D(x, y); osc = theta_; flower = createGraphics(32, 32, JAVA2D); float z = random(10000); flower.beginDraw(); flower.background(255); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { int r = (int)(noise(i/17f, j/19f, z) * 256); int g = (int)(noise(i/19f, j/16f, z+1) * 256); int b = (int)(noise(j/18f, i/11f, z+2) * 256); //int a = 192 + (int)(noise(i*2, j, z) * 64); color c = color(r, g, b, 255); flower.set(i, j, c); } } flower.endDraw(); } void render() { osc += 0.05; theta = sin(osc) + PI; float x = r * sin(theta); float y = r * cos(theta); y -= stalkHeight; noStroke(); fill(32, 128, 32); pushMatrix(); translate(pos.x, pos.y); beginShape(); vertex(10, 0); bezierVertex(5, -stalkHeight * 0.75, 5, -stalkHeight, x, y); bezierVertex(-5, -stalkHeight * 0.75, -5, -stalkHeight, -10, 0); endShape(); fill(255); translate(x, y); rotate(radians(45)); image(flower, -16, -16); popMatrix(); } float getFitness() { return fitness; } void setFitness(float f) { fitness = f; } PGraphics getFlower() { return flower; } void mutate(float t) { if (random(1) < t) { float f = random(1); Mutation m; if (f < 0.1) { m = new HorizontalMirrorMutation(); } else if (f < 0.25) { m = new VerticalMirrorMutation(); } else if (f < 0.5) { m = new PosterizeMutation(); } else if (f < 0.75) { m = new BlurMutation(); } else if (f < 1) { m = new ReddenMutation(); } else { m = new Mutation(); } m.mutate(flower); } } }