3 oktober 2009

Three in one

Below the code of a file which covers the first three lessons.

int rectSize = 300;
/**
 * Everything up to now in one sketch
 */
void setup() {
  size(400, 400);
}

void draw() {
  // print mouseposition to console
  println("x: " + mouseX + " y:" + mouseY);
  // set framerate
  frameRate(30);
  // set background color
  background(233, 212, 123);

  // two colored square
  fill(157, 214, 45);
  stroke(212, 194, 44);
  strokeWeight(8);
  rect(20, 20, rectSize, rectSize);

  strokeWeight(1);
  // draw a set of lines to create a gradient
  for (int i = 0; i < 120; i = i +1) {
    stroke(255 - i, 0, 255 - i);
    float ypos = 150 + i;
    line(200, ypos, 350, ypos);
  }

  // mouse interactive ellipse
  noStroke();
  fill(231, 12, 43);

  int myx = 0;
  if (mouseX > 250) {
    myx = 250;
    fill(0,255,0);
  } else {
    myx = mouseX;
    fill(0,0,255);
  }
  println(myx);
  ellipse(myx, mouseY, 60, 50);
}

Geen opmerkingen:

Een reactie posten