Sunday, 17 August 2014

Processing final

"Snake Evolution"

The concept is of a snake that follows the mouse and changes colour whenever the mouse is clicked. There are 3 parts to this code: creation of the "snake", the colour changing system, and the mouse-pressed trigger.

The "snake" is created using the storing input function. As I understand it, the shape of the circles drawn using the mouse is remembered by the program and displayed as a trail, fading away only after a certain distance/time instead of immediately. 

I first developed a colour changing "system" based on the position of the mouse and set the background to black for better viewing. 

At the same time, I incorporated the mouse-pressed function with the colour change, so that it would only happen when the mouse is pressed.

Code:

int barWidth = 1;
int lastBar = 1;
int num = 50;
  float mx[]= new float[num];
  float my[]= new float[num];

void setup(){
  size(1000,1000);
  colorMode(HSB,height,height,height);
  noStroke();
  background(0);
}

void draw(){
  background(5);

  int which = frameCount % num;
  mx[which]=mouseX;
  my[which]=mouseY;

  for (int i=0; i<num; i++){
    int index = (which+1 + i) % num;
     ellipse(mx[index],my[index],i,i);
  }

  int whichBar = mouseX/barWidth;
  if (whichBar != lastBar)
{
  if (mousePressed) {

  int barX = whichBar * barWidth;
  fill(mouseX,mouseY,width,50);
   lastBar = whichBar;

  }
  else {

  }
}
}

No comments:

Post a Comment