// // pixelor.pde // // // Created by Karin Gauch and Fabien Schwartz on 10.06.07. // Copyright 2007 Karin Gauch and Fabien Schwartz. All rights reserved. // ArrayList population = new ArrayList(); // Arraylist for worm type objects // Arrays for backgroundimages and matching backgroundcolors PImage[] img = new PImage[5]; color[] backgroundColor = {color(255),color(255),color(255),color(0),color(255)}; PImage[] imgThumb = new PImage[5]; // Images PImage area = new PImage(500, 500); PImage menu = new PImage(); // Basic settings int speed = 13; int activeImg = 0; boolean outline = true; boolean ai = false; // Artificial intelligence boolean loupe = false; boolean come = false; // magnet boolean showStatistic = false; boolean reproduction = false; int menuWidth = 250; int maxWormLength = 200; int pixelsEaten = 0; // create Sliders slider speedSlider = new slider(531, 415, 186, 1, 4000, 780); slider lengthSlider = new slider(531, 463, 186, 7, 1000, 200); // setup method void setup() { size(500+menuWidth, 500); frameRate(30); stroke(200); loadImages(); background(255); menu = loadImage("menu.png"); menu(); } // draw method void draw() { image(img[activeImg], 0, 0); loadPixels(); // loads pixels for later use in a.draw() img[activeImg].loadPixels(); // loads pixels of background image for later use in a.go() worm tmp; for(int i = 0; i < population.size(); i++) { tmp = (worm)population.get(i); // inizializes new object of type worm referencing the current worm stored in population tmp.go(speed); // makes this worm moving for several pixels (pedending on speed) } img[activeImg].updatePixels(); updatePixels(); if(mouseX > img[activeImg].width || loupe) // redraw menu menu(); stroke(200); line(img[activeImg].width,0,img[activeImg].width,img[activeImg].height); stroke(255); line(width-1,0,width-1,img[activeImg].height); if(loupe) loupe(mouseX,mouseY); if(showStatistic) printStatistic(); } // mehtod to load images void loadImages() { img[0] = loadImage("frut.jpg"); img[1] = loadImage("pattern.png"); img[2] = loadImage("bouquet.jpg"); img[3] = loadImage("susen.jpg"); img[4] = loadImage("tree.jpg"); for(int i = 0; i < img.length; i++) { imgThumb[i] = loadImage("dummy.jpg"); imgThumb[i].copy(img[i], 0, 0, img[i].width, img[i].height, 0, 0, 34, 34); } pixelsEaten = 0; } // method to kill all the worms void killAll() { for(int i = population.size()-1; i >= 0; i--) { population.remove(i); } lengthSlider.active = true; } // method to draw the loupe void loupe(int x, int y) { PImage effect = new PImage(95, 94); PImage loupeImg = loadImage("loupe.jpg"); PImage loupeEffectMask = loadImage("loupe-effect-mask.jpg"); PImage loupeMask = loadImage("loupe-mask.jpg"); loupeImg.mask(loupeMask); for(int i=0; i<50; i++) for(int j=0; j<50; j++) for(int k=0; k<9; k++) effect.set(+i*3+k/3,j*3+k%3,get(x+i-17,y+j-17)); effect.mask(loupeEffectMask); image(effect,x+25,y+25); image(loupeImg,x-25,y-25); }