//Christina Papandrea CSCI 273 Assignment 6 10/27/09 float radius = 1.0; int h = 0, dimension; float s = 1; PImage img; void setup() { size(600,600); background(0); colorMode(HSB,360,100,100); noStroke(); smooth(); img = loadImage("photo.jpg"); //load space background dimension = img.height * img.width; image(img,0,0); frameRate(10000); } void draw() { //keeps motor running } void keyPressed() { if (key == 'h') { img.loadPixels(); //increments hue 60 degrees // % makes sure hue never grows beyond 360 for (int i=0; i < dimension; i++) { img.pixels[i] = color((hue(img.pixels[i])+60)%360, saturation(img.pixels[i]), brightness(img.pixels[i])); } img.updatePixels(); image(img, 0, 0); } if (key == 't') { img.loadPixels(); //increments saturation of tint by 20 // % makes sure saturation never grows beyond 100 for(int t=0; t < dimension; t++) { tint(300,(random(t)+20)%100,100); } img.updatePixels(); image(img, 0, 0); } } void mousePressed() { //loads the pixels from the display img.loadPixels(); } void mouseDragged(){ int h, s, b, j, i, currentIndex = mouseX-1 + (mouseY-1)*img.width; color currentPixelColor; img.loadPixels(); //sums the nine pixels h,s,b centered at the mouse for (h=0, s=0,b=0,j = 0; j<3; j++) { for (i = 0; i<3; i++) { h += hue(img.pixels[currentIndex+i]); s += saturation(img.pixels[currentIndex+i]); b += brightness(img.pixels[currentIndex+i]); } currentIndex += img.width; } //sets fill to the mean of the 9 pixels fill(color(h/9, s/9,constrain(b/9+20,0,100), 50)); //draws a circle wth the averaged fill at the location ellipse(mouseX, mouseY, 40,40); stroke(2); line((mouseX+5), (mouseY+5), (mouseX-5), (mouseY-5)); } void mouseReleased() { // refreshes the pixels and redraws the image to the display img.updatePixels(); image(img, 0, 0); }