Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

random() function and loops

23. September 2013

I wrote a little application that creates random arcs that are generated in a while-loop. On each mouse click it empties the background and redraws at the current mouse position. Try deleting "noFill()" in the setup and you'll get interesting kind of pie chart shapes. Bildschirmfoto 2013-09-23 um 21.11.40 Bildschirmfoto 2013-09-23 um 21.11.52

float arcsize;
float startrad = 0;
float endrad = 0.5;
int arccount;

void setup() {
  frameRate(60);
  size(600, 600);
  background(33, 69, 95);
  noFill();
  strokeWeight(1);
  stroke(255);
  translate(width/2, height/2);
}

void draw() {
  translate(mouseX, mouseY);
}

void arcs() {
  arcsize = random(10, 590);
  rotate(random(0, TWO_PI));
  arc(0, 0, arcsize, arcsize, startrad, endrad);
}

void mousePressed() {
  background(33, 69, 95);
  while (arccount <= 80)
  {
    arcs();
    arccount++;
  }

  arccount = 0;
}