class Wave { int xspacing; //how far should each x point be spaced int w; //width of entire wave int type; //SINE OR COSINE? float theta; //starting angle float amplitude;//height float period; //how many pixels go by before we repeat float dx; //calculated based on period float[] yvalues;//using an array to store height values for the wave //**CONSTRUCTOR INITIALIZES ALL INSTANCE VARIABLES**/ Wave(int t, float a, int xspace, int w_, float p_) { type = t; amplitude = a; xspacing = xspace; w = w_; period = p_; dx = (TWO_PI / period) * xspacing; yvalues = new float[w/xspacing]; //note declaring the array here forces us to have fixed size wave //we would need to redeclare it if we ever change those values } void calcWave() { //increment theta by 0.01 (this should be made into an instance variable); theta += 0.06; //For every x value, calculate a y value based on sine or cosine float x = theta; w = 10 + second()*9; yvalues = new float[(w)/xspacing]; for (int i = 0; i < yvalues.length; i++) { //amplitude = second()*2; if (type == SIN) yvalues[i] = sin(x)*amplitude; if (type == COS) yvalues[i] = cos(x)*amplitude; x+=dx; } } void calcMinWave() { //increment theta by 0.01 (this should be made into an instance variable); theta += 0.05; //For every x value, calculate a y value based on sine or cosine float x = theta; w = 10 + minute()*9; yvalues = new float[(w)/xspacing]; for (int i = 0; i < yvalues.length; i++) { if (type == SIN) yvalues[i] = sin(x)*amplitude; if (type == COS) yvalues[i] = cos(x)*amplitude; x+=dx; } } void renderMin() { //a simple way to draw the wave with an ellipse at each location //this could be improved in so many ways smooth(); float changecolor = minute()/2; for (int x = 0; x < yvalues.length; x++) { //stroke(200); fill(255,255,255,100); ellipseMode(CENTER); ellipse(x*xspacing,yvalues[x],8,8); } } void render() { //a simple way to draw the wave with an ellipse at each location //this could be improved in so many ways //smooth(); float changecolor = second()/2; for (int x = 0; x < yvalues.length; x++) { //stroke(200); fill(200,changecolor/2,changecolor,100); ellipseMode(CENTER); ellipse(x*xspacing,yvalues[x],8,8); } } }