Digital Bauhaus Vorkurs/Projekte/Linie/Programmierung1

From Medien Wiki

Linien zufälliger Länge aus den vier Ecken

boolean aON=false;
boolean bON=false;
boolean cON=false;
boolean dON=false;
boolean eON=false;


void setup() {
  size(500,500);
  background(255); 
  smooth(); 
}

void draw() {
  if(aON) {
    drawLine1();
  }
  if(bON) {
    drawLine2();
  }
  if(cON) {
    drawLine3();
  }
  if(dON) {
    drawLine4();
  }
  if(eON) {
    background(255);
  }    
  if(aON = true) {
    aON = false;
  }
  if(bON = true) {
    bON = false;
  }
  if(cON = true) {
    cON = false;
  }
  if(dON = true) {
    dON = false;
  }
  if(eON = true) {
    eON = false;
  }
}

void keyTyped() {
  if(keyPressed) {
    if (key == '1') {
      aON = true;
    } else {
      aON = false;
    }
  }
  if(keyPressed) {
    if (key == '2') {
      bON = true;
    } else {
      bON = false;
    }
  }
  if(keyPressed) {
    if (key == '3') {
      cON = true;
    } else {
      cON = false;
    }
  }
  if(keyPressed) {
    if (key == '4') {
      dON = true;
    } else {
      dON = false;
    }
  }
  if(keyPressed) {
    if (key == '5') {
      eON = true;
    } else {
      eON = false;
    }
  }
}

void drawLine1() {
  int x2=(int)random(500);
  int y2=(int)random(500);
  stroke(0);
  line(0,0,x2,y2);
}
void drawLine2() {
  int x2=(int)random(500);
  int y2=(int)random(500);
  stroke(0);
  line(500,0,x2,y2);
}
void drawLine3() {
  int x2=(int)random(500);
  int y2=(int)random(500);
  stroke(0);
  line(500,500,x2,y2);
}
void drawLine4() {
  int x2=(int)random(500);
  int y2=(int)random(500);
  stroke(0);
  line(0,500,x2,y2);
}