More Processing Examples

General posts about art, interactivity, programming - Processing, OpenFrameworks, Arduino, Pure Data, Max/MSP, etc

More Processing Examples

Code: Select all
`/* 1 to 1 mapping */void setup (){  size (600,600);    }void draw (){  background(255);  fill(0);    ellipse(mouseX, mouseY, 30,30);}`

Code: Select all
`/* mouse position controls direction */float x;float y;void setup (){  size (600,600);    x=300;  y=300;  }void draw (){  background(255);  fill(0);    if (mouseX > 400)    x++;  if (mouseX < 200)    x--;  ellipse (x,y,20,20);    line (200,0,200,600);  line (400,0,400,600);}`

Code: Select all
`/* mouse position controls velocity */float x;float y;float dx;float dy;float lastTime;void setup (){  size (600,600);    x=300;  y=300;    dx=0;  dy=0;    lastTime=0;}void draw (){  background(255);  fill(0);  float currentTime = millis();    float dt = (currentTime - lastTime) / 1000.0;    dx = mouseX - 300;    line (0,10,mouseX,10);  line (0,20,dx,20);    x = x + dx * dt;  y += dy;  // += is a shortcut for y=y+dy    if ( x > 600)    x=0;      if ( x < 0)    x=600;  ellipse(x,y,20,20);    lastTime = currentTime;  // store this time for the next draw call}` BenChang

Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm 