Digital Bauhaus Vorkurs/Projekte/Linie/Programmierung2

From Medien Wiki

Linien aus den vier Ecken

Endpunkt am Mauszeiger

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

boolean aON=false; boolean bON=false;

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;
 }
 if (mousePressed == true) {
   aON = true;
   } 
   else {
     aON = false;
   }
 }
 

void keyTyped() {

 if(keyPressed) {
   if (key == '5') {
     bON = true;
   } 
   else {
     bON = false;
   }
 }

}

void drawLine1() {

 stroke(0);
 if (key == '1') {
   line(mouseX,mouseY,0,0);
 }
 if (key == '2') {
   line(mouseX,mouseY,500,0);
 }
 if (key == '3') {
   line(mouseX,mouseY,0,500);
 }
 if (key == '4') {
   line(mouseX,mouseY,500,500);
 }   

}