Digital Bauhaus Vorkurs/Projekte/Linie/Programmierung5

From Medien Wiki

Linien mit begrenzter Länge aus dem Mittelpunkt

<source lang="Java" highlight="14">

boolean aON=false; boolean bON=false;

int x2; int y2; float distance = 201;

void setup() {

 size(500,500);
 background(255); 
 smooth();

}

void draw() {

 if(aON) {
   drawLine1();
 }
 if(bON) {
   background(255);
 }
 if(aON = true) {
   aON = false;
 }
 if(bON = true) {
   bON = false;
 }

}

void keyTyped() {

 if(keyPressed) {
   if (key == '1') {
     aON = true;
   } 
   else {
     aON = false;
   }
 }
 if(keyPressed) {
   if (key == '2') {
     bON = true;
   } 
   else {
     bON = false;
   }
 }

}

void drawLine1() {

 while(distance > 200) {
   x2=(int)random(500);
   y2=(int)random(500);
   distance=dist(250,250,x2,y2);
 }
 stroke(0);
 line(250,250,x2,y2);
 distance = 201;

}