Key­b­o­a­r­d Int­e­r­a­c­t­i­o­n

by Travis Low

Use they arrow keys and SHIFT and CONTROL to bring the ellipse to life.

  • Show Code
/** @peep sketch */
float angle = 0;
float x = 100;
float y = 100;
float radius = 20;
 
void setup() {
  size(200, 200);
  strokeWeight(2);
  frameRate(190);
}
 
void draw() {
  background(204);
  if (keyPressed == true) {
    if (key == CODED) {
      if (keyCode == LEFT) {
        x--;
      } else if (keyCode == RIGHT) {
        x++;
      } else if (keyCode == UP) {
        y--;
      } else if (keyCode == DOWN) {
        y++;
      } else if (keyCode == SHIFT) {
        line( x , y, random(width), random(height)); 
      } else if (keyCode == CONTROL) { 
        bezier(x, y, random(width), random(height), random(width), random(height), random(width), random(height));
      }
    } 
  }
  ellipse(x, y, radius*2, radius*2);
}

Comments

Nobody has said anything yet.