How to make wave form/shape in my code go up and down with mouseX and MouseY ???

edited March 2015 in How To...

Baaically I put together a code for a project. When the user clicks the screen the eyes change and go move around with Mouse X & Mouse Y. I also have a wave like form in there that is suppose to represent water.. What my aim is to do is when the user clicks on the eyes and moves the eyes around, I guess I want the eyes to act as a controller for the waves and make the waves go up and down.. Anyone know how I would go about doing that? I am also very new to Processing! Only been trying to learn it for the past 3 weeks. Any help would be much appreciated! Thanks :) Here is my code:

`

//variables for wave
float time = 0;
int w = 900;
int h = 700;
int r=0;
int g=0;
int b=0;
int i=0; 

//variables for eyes
int pupilsize1= 80;
int pupilsize2= 80;
int blackpupilsize= 80; // int= whole numbers 
float x = 271.869; // float= decimals
float y = 415;
float xx = 656.904;
float yy = 415;



float easing = 0.5; // easing= make it move= higher number faster it goes 

void setup(){
  smooth();
 background(0); 

  size(900,900);
  stroke(1,111);
  fill(1,111);
}
float wave = 100;

void draw(){



 if (mousePressed) {



    // draw white part of eyes // left eye
    noStroke ();
    fill (255);
    ellipse(269.806, 300, 300, 300);
    //right eye
    ellipse(656.903, 300, 300, 300);

    //eye color
    float speed = dist (mouseX, mouseY, pmouseX, pmouseY);
    strokeWeight (10);
    stroke (119, 136, 153, speed * 10);



    //lefthand pupil
    float mx = constrain (mouseX, 200, 320); //uses mouse x coordinate, but only constrained within x=200-320

    float my = constrain (mouseY, 220, 350); //uses mouse x coordinate, but only constrained within x=220-350
    x += (mx-x) * easing; // use easing to make pupil of eye move 
    y += (my-y) * easing;
    fill (0);
    ellipse (x, y, pupilsize1, pupilsize2);

    //righthand pupil
    float mxx = constrain (mouseX, 580, 690); //uses mouse x coordinate, but only constrained within x=580-690
    float myy = constrain (mouseY, 270, 360); //uses mouse x coordinate, but only constrained within x=270-360
    xx += (mxx-xx) * easing; // use easing to make pupil of eye move 
    yy += (myy-yy) * easing;
    fill (0);
    ellipse (xx, yy, pupilsize1, pupilsize2);

    //grey eyes
    stroke (0);
    fill (0);

          //wave 

  fill(255);
  float x =0;
 for(int i=0; i<height; i++)
  while (x<w){

    float k = wave*noise(x/100,time);
    noStroke();
    ellipse(x,200+(k),3,3);
   stroke(#659298);
  line(x,200+(k),x,h);
    x++;

  }

  time = time+.02;

  } else { // if user does not click, pupils remain the same and move around within the constrains of the white circles/eyes

    //big circle white
    fill(255);
    //left
    ellipse(269.806, 300, 300, 300);
    //right
    ellipse(656.903, 300, 300, 300);

    //lefthand pupil
    float mx = constrain (mouseX, 200, 320);
    float my = constrain (mouseY, 220, 350);
    x += (mx-x) * easing;
    y += (my-y) * easing;
    fill (0);
    ellipse (x, y, pupilsize1, pupilsize2);

    //righthand pupil
    float mxx = constrain (mouseX, 580, 690);
    float myy = constrain (mouseY, 270, 360);
    xx += (mxx-xx) * easing;
    yy += (myy-yy) * easing;
    fill (0);
    ellipse (xx, yy, pupilsize1, pupilsize2);
  }
}

`

Sign In or Register to comment.