/** * Bryan Corell - Project 1 Intro to Interactivity Makes use of example noiseWave mostly, to create a spacey, color shifting image. Control is given with a mouse click to shift direction, and the movement of the mouse around the screen will change colors */ class noiseObj{ color myColor; int sliderRed,sliderGreen,sliderBlue; int myFrameCount; int randChange; int xspacing; // How far apart should each horizontal location be spaced boolean mouseNotMoving; boolean hasBeenClicked; boolean greying; boolean swap; // THis is for swapping colors back and forth int w; // Width of entire wave int y; float yoff; // 2nd dimension of perlin noise float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) noiseObj(int yin) { myColor = color(int(random(100)), int(random(200)),int(random(255))); y = yin; mouseNotMoving = false; randChange = int(random(1,200)); greying = false; myFrameCount = 0; hasBeenClicked = false; xspacing = int(random(10,30)); yoff = 0.0f; w = width+16; yvalues = new float[w/xspacing]; ellipseMode(CORNER); } void getMouseMovement(boolean test){ if(test) // Mouse is moving mouseNotMoving = false; else mouseNotMoving = true; } void enableClick(){ if(hasBeenClicked) hasBeenClicked = false; else hasBeenClicked = true; } void calcWave() { myFrameCount++; float dx = 0.05f; float dy = 0.01f; float amplitude = 100.0f; // Increment y ('time') yoff += dy; //float xoff = 0.0; // Option #1 float xoff = yoff; // Option #2 for (int i = 0; i < yvalues.length; i++) { // Using 2D noise function //yvalues[i] = (2*noise(xoff,yoff)-1)*amplitude; // Option #1 // Using 1D noise function yvalues[i] = (2*noise(xoff)-1)*amplitude; // Option #2 xoff+=dx; } } void renderWave(int vertLoc, int yIncrem) { // A simple way to draw the wave with an ellipse at each location if(myFrameCount % randChange == 0) // Every 10 seconds { randChange = int(random(175,250)); myFrameCount = 0; greying = true; myColor = randColor2(); swap = !swap; } noStroke(); for (int x = 0; x < yvalues.length; x++) { if((greying && swap)) fill(50,50,50,15); else fill(randColor(),15); if(mouseNotMoving) fill(15,15,15,15); /* also if the mouse has not moved more than about 100 pixels in two seconds, have it begin drawing black again*/ if(hasBeenClicked) { if(x == 0) x = 1; ellipse( random((width-(x*20)),width-(x*20))+yvalues[x] , yIncrem+random(xspacing)*2 , 16, 16); } else ellipse( random(vertLoc-10,vertLoc+10)+yvalues[x] , x*random(xspacing) , 16, 16); } }// end function void setColor(int r, int g, int b) { myColor = color(r,g,b); } color randColor() // This function relies on mouse Input for steady results { updateSliders(); int rT = int(random(sliderRed)); int gT = int(random(sliderGreen)); int bT = int(random(sliderBlue)); color newColor = color(rT,gT,bT); return newColor; } void updateSliders() { sliderRed = int(random(mouseX/(mouseY+1) )); sliderGreen = int(random(mouseY/2))+20; sliderBlue = int(random(mouseX)); } color randColor2() // This function on the other hand, works to purely give a random color { int rT = int(random(175)); int gT = int(random(255)); int bT = int(random(200)); color newColor = color(rT,gT,bT); return newColor; } } // End class