// durch numObjects angegebene Anzahl von Rechtecken (rColor) wird gezeichnet; // mit Linien (lColor) verbunden und gespiegelt (sColor) int breite = 400; // Buehnenbreite int hoehe = 400; // Buehnenhoehe //---- verŠnderbare Variablen ------ int numObjects = 2; // Anzahl der Elemente (Verbindungs-Rechtecke) int accA = 60; // normal-Geschwindigkeit int accB = 80; // Bullettime-Geschwindigkeit int rSize = 6; // SeitenlŠnge der Rechtecke float border = 1; // minimaler Abstand zur Ausgangsposition, bei der das "trailen" noch andauert String whichFont = "Univers75.vlw.gz"; // Name der Schriftart fŸr die Schalterbezeichnung // (gleichnamige Datei muss im Ordner "Data" liegen) color rColorA; // RGB-Wert, Alpha-Wert Rechtecke (Normal) color lColorA; // RGB-Wert, Alpha-Wert Linien (Normal) color sColorA; // RGB-Wert, Alpha-Wert Spiegelung (Normal) color rColorB; // RGB-Wert, Alpha-Wert Rechtecke (Bullet) color lColorB; // RGB-Wert, Alpha-Wert Linien (Bullet) color sColorB; // RGB-Wert, Alpha-Wert Spiegelung (Bullet) //----------------------------------- int acc; boolean pressed = false; // gibt an, ob die Maus momentan gedrŸckt wird boolean firstPressed = false; // wird true, sobald die Maus gedrŸckt wird (und false, falls die Position nicht mit einem der Punkte Ÿbereinstimmt boolean hitPoint = false; // an, ob ein Punkt getroffen wurde boolean dragObject = false; // gibt an, ob irgendein Objekt bewegt wird boolean bullet = false; BFont fontName; // Schriftvariable int sAktiv = 1; // gibt an, welche SchaltflŠche momentan aktiviert ist boolean showOnce = true; // verhindert, dass die SchaltflŠchen stŠndig gezeichnet werden int pointNum = -1; // ist = -1, wŠhrend kein Objekt gezogen / bewegt wird // ------- Arrays ------- // Aktuelle Position float[] koordsX = new float[numObjects]; float[] koordsY = new float[numObjects]; // Ausgangsposition (bevor Punkt versetzt wurde) float[] startX = new float[numObjects]; float[] startY = new float[numObjects]; // Abstand zwischen alter und neuer Position float[] diffX = new float[numObjects]; float[] diffY = new float[numObjects]; // Steigung einer imaginŠren Geraden zwischen alter und neuer Position float[] m = new float[numObjects]; boolean[] trailPoint = new boolean[numObjects]; // gibt an, ob ein Punkt "trailed" // -------------------------------------------------------------- void setup() { size(breite, hoehe); background(255); //---- Arrays und Variablen werden initialisiert ---- //----- Farbwerte ---------- rColorA = color(0,0,100,100); // Rechtecke (Normal) lColorA = color(255,0,0,100); // Linien (Normal) sColorA = color(255,0,100,40); // Spiegelung (Normal) rColorB = color(0,0,100,10); // Rechtecke (Bullet) lColorB = color(255,0,0,10); // Linien (Bullet) sColorB = color(255,0,100,6); // Spiegelung (Bullet) //-------------------------- acc = accA; rSize = rSize/2; int f; int pos = 10; int randX = ( (breite/2)/(numObjects+1) ); int randY = (hoehe/2)/4; // Start-Position der Rechtecke (Zufall) for (f=0;f = 0 ) - das "trailen" aktiviert void mouseReleased() { pressed = false; dragObject = false; if(pointNum >= 0) { if(trailPoint[pointNum] == false) { difference(); } } } //--------------------------------------------------------------- //----- schalter zeichnet die SchaltflŠchen zur Interaktion und den Text -------- //----- wird ganz am Ende von void loop() aufgerufen ---------------------------- void schalter (int s1, int s2, int s3, int s4) { //----- SchaltflŠchen werden gezeichnet ------- stroke(0,0,0,100); fill(s1); rect(5,5,8,8); noFill(); fill(s2); rect(20,5,8,8); noFill(); fill(s3); rect(35,5,8,8); noFill(); fill(s4); rect(50,5,8,8); //---- Schalterbezeichnungen werden dargestellt ----- fontName = loadFont(whichFont); textFont(fontName, 50); textSize(12); fill(0); text("1 2 3 4", 6, 26); // text("1 = normal | 2 = bullet | 3 = bullet & alle bewegen | 4 = normal & alle bewegen", 65, 14); noFill(); } //---------------------------------------------------------------------------------------------------------- //-- allen Objekten werden Zufallsposition zugewiesen und diese in Bewegung versetzt (ohne "Bullettime") --- void moveAll() { bullet = false; acc = accA; sAktiv = 4; int t = 0; for(t=0;t 0 && h < (numObjects-1) ) { line( -1 * koordsX[h-1], koordsY[h-1], -1 * koordsX[h], koordsY[h] ); line( -1 * koordsX[h], koordsY[h], -1 * koordsX[h+1], koordsY[h+1] ); } if( h == (numObjects-1) ) { line( -1 * koordsX[h-1], koordsY[h-1], -1 * koordsX[h], koordsY[h] ); line( -1 * koordsX[h], koordsY[h], -1 * koordsX[0], koordsY[0] ); } //-------------------------------------------------------- //----- Spiegelung aus ----- translate( -1 * breite, 0 ); //-------------------------- //----- Abstand der Formen zu ihrem Ausgangspunkt wird ermittelt ------- diffX[h] = startX[h] - koordsX[h]; diffY[h] = startY[h] - koordsY[h]; //----------- Bewegungsrichtung- und Geschwindigkeit beim "trailen" wird berechnet -------------- if( (abs(diffX[h]) - border > 0) || (abs(diffY[h]) - border > 0) ) { if( abs(diffX[h]) != 0 && diffX[h] > 0) { koordsX[h] = koordsX[h] + ( abs(diffX[h]) / acc ); } if( abs(diffX[h]) != 0 && diffX[h] < 0) { koordsX[h] = koordsX[h] - ( abs(diffX[h]) / acc ); } if( abs(diffY[h]) != 0 && diffY[h] > 0) { koordsY[h] = koordsY[h] + ( abs(diffY[h]) / acc ); } if( abs(diffY[h]) != 0 && diffY[h] < 0) { koordsY[h] = koordsY[h] - ( abs(diffY[h]) / acc ); } } //------------------------------------------------------------------------------------------------ //------ wenn Abstand kleiner als border ist, wird das "trailen" beendet --------- else { trailPoint[h] = false; startX[h] = koordsX[h]; startY[h] = koordsY[h]; } //-------------------------------------- } //------ Spiegelung ein ------ translate(breite,0); //---------------------------- if(bullet == false) { stroke(sColorA); } else { stroke(sColorB); } noFill(); //--------- Gespiegelte Formen, die nicht bewegt werden ------------- //---- Rechteck (gespiegelt + Ruhezustand) ------ rect(-1*koordsX[h]-rSize,koordsY[h]-rSize,2*rSize,2*rSize); //----------------------------------------------- //----- Verbindungslinien (gespiegelt + Ruhezustand) --------- if( h > 0 && h < (numObjects-1) ) { line(-1*koordsX[h-1],koordsY[h-1],-1*koordsX[h],koordsY[h]); line(-1*koordsX[h],koordsY[h],-1*koordsX[h+1],koordsY[h+1]); } if( h == (numObjects-1) ) { line(-1*koordsX[h-1],koordsY[h-1],-1*koordsX[h],koordsY[h]); line(-1*koordsX[h],koordsY[h],-1*koordsX[0],koordsY[0]); } //------------------------------------------------------------- //----- Spiegelung aus ------ translate(-1*breite,0); //--------------------------- //----------- Normale Form (grŸne Linien; blaue Rechtecke), die nicht bewegt werden -------------------- if(bullet == false) { stroke(rColorA); } else { stroke(rColorB); } // ---- Rechteck (ungespiegelt) ------ noFill(); rect(koordsX[h]-rSize,koordsY[h]-rSize,2*rSize,2*rSize); //------------------------------------ if(bullet == false) { stroke(lColorA); } else { stroke(lColorB); } //----- Verbindungslinien (ungespiegelt) --------- if( h > 0 ) { line(koordsX[h-1],koordsY[h-1],koordsX[h],koordsY[h]); } if( h == (numObjects-1) ) { line(koordsX[h],koordsY[h],koordsX[0],koordsY[0]); } //------------------------------------------------ } if(mousePressed == true && pressed == false) { pressed = true; //-------------------- SchaltflŠchen --------------------- /* Button 1 */ if( (mouseX >= 5 && mouseX <= 13) && (mouseY >= 5 && mouseY <= 13) && bullet == true) { stopAll(); } /* Button 2 */ if( (mouseX >= 20 && mouseX <= 28) && (mouseY >= 5 && mouseY <= 13)) { bulletMove(); } /* Button 3 */ if( (mouseX >= 35 && mouseX <= 43) && (mouseY >= 5 && mouseY <= 13)) { bulletAll(); } /* Button 4 */ if( (mouseX >= 50 && mouseX <= 58) && (mouseY >= 5 && mouseY <= 13)) { moveAll(); } //-------------------------------------------------------- int a; int space = 3; // Raum um das Rechteck (+ space / - space) in dem man es greifen kann //-------------------------------------------------------- //--- †berprŸfung, ob einer der Punkte angeklickt wird --- boolean e = false; for(a=0; a < numObjects; a++) { float xA = koordsX[a] - space; float xB = koordsX[a] + space; float yA = koordsY[a] - space; float yB = koordsY[a] + space; if( (mouseX >= xA && mouseX <= xB) && (mouseY >= yA && mouseY <= yB) ) { e = true; pointNum = a; } if(e == true) { hitPoint = true; } else { hitPoint = false; } //-------------------------------------------------- //------ Punkt (Rechteck) wurde getroffen ---------- } if(hitPoint == true) { trailPoint[pointNum] = false; dragObject = true; } //-------------------------------------------------- } //---- das "trailen" wird gestartet ---- if(dragObject == true && pointNum >= 0) { koordsX[pointNum] = pmouseX; koordsY[pointNum] = pmouseY; } //-------------------------------------- //--------- SchaltflŠchen werden je nach Auswahl dargestellt (durch funktion bzw. void "schalter" s.O.) --------------- if(sAktiv == 1) { schalter(50,255,255,255); } if(sAktiv == 2 && showOnce == false) { schalter(255,100,255,255); showOnce = true; } if(sAktiv == 3 && showOnce == false) { schalter(255,255,150,255); showOnce = true; } if(sAktiv == 4) { schalter(255,255,255,200); } //---------------------------------------------------------------------------------------------------------------------- }