//Config Section: //Welt ist rund: true = Blöcke fahren um die Welt, false: Blöcke kehren am Rand der Welt um, da sie sich vor den Ungeheuern fürchten... boolean WeltIstRund = true; //Bereich in Pixeln, in der smoothes bremsen verwendet werden soll. Nur bei flacher Welt. int iSmoothRegionPix = 100; //Wo erscheint der Schnipsel? true = Random, false = am Ort, wo man klickt. Ist noch witzig, wenn der bereich von der Aktuellen Position her losflitzt. boolean bolRandomAppearing = true; //Debug Informationen ausgeben oder nicht? boolean bolPrintDebugInfo = false; //Was bewirkt die linke Maustaste? true=EinObjektFilterwechsel, false=dragAlle boolean bolLeftClickOneObject = false; //Zoomen beim Mauszeiger boolean bolZoom = false; //Globale Variablen int iMax = 10; //Maximale Anzahl der Schnipsel PImage a; //BG Image PImage b[] = new PImage[iMax]; //Array für Schnipsel int bDir[] = new int[iMax]; //Array für die Richtung, die die Schnipsel einschlagen. int bSpeed[] = new int[iMax]; //Array für die Geschwindigkeit, in der die Schnipsel fahren. int bCurPos[] = new int[iMax]; //Array für die aktuelle Position der Schnipsel int bTrans[] = new int[iMax]; //Array für die Transparenz der Schnipsel int NumOfPics = 0; //Anzahl der Schnipsel int AreaWidth; //Breite der Schnipsel //Variablen für Dragging boolean bolMousePressed = false; // Information ob linker MausButton gerade gedrückt ist... int iMousePosOnDragStart = 0; // Letzte Mausposition int iMousePosOffset = 0; // Aktuelles MausOffset int iCurrentManPic = -1; // Aktuelles Bild für EinzelDragModus //Start Routine void setup() { a = loadImage("img.JPG"); //BG Image laden size(800, 531); //Grösse des Programmfensters = Grösse des BG Image. frameRate(40); AreaWidth = a.width/10; //Breite der Schnipsel = 1/10 des BG Image } //draw Routine void draw() { float Zoom = 1; float Smooth = 1; //Faktor fürs abbremsen // image (a, 0, 0); //BG Image setzen background(a); for (int i = 0; i= width) { bCurPos[i] = b[i].width*-1; } else if (bCurPos[i] < b[i].width*-1) { bCurPos[i] = width; } } else // if (WeltIstRund) { //Positionsberechnung if (bCurPos[i] > (width-AreaWidth)) { bDir[i] = -1; } else if (bCurPos[i] <= 0) { bDir[i] = 1; } else if (bCurPos[i] (width-AreaWidth-iSmoothRegionPix)) { //Für smoothes abbremsen rechts: Smooth = float(width - AreaWidth - bCurPos[i]) / float(iSmoothRegionPix); println2(str(Smooth)); } } // Neue Position anwenden (nicht drag Modus oder EinzelBildDrag Modus) if (!bolMousePressed && !(iCurrentManPic == i)) { bCurPos[i] += (bSpeed[i] * bDir[i] * Smooth) + (1 * bDir[i]); } // Neue Position anwenden (drag Modus) else { iMousePosOffset = mouseX - iMousePosOnDragStart; bCurPos[i] += iMousePosOffset; } //Zoomfaktor berechnen if (bolZoom) { Zoom = 1.5-1.5/width/1.5*(abs(mouseX-bCurPos[i])); println2(str(Zoom)); if (Zoom<1) { Zoom=1; } } tint(255, bTrans[i]); // Transparenz image(b[i], bCurPos[i], (height*Zoom-height)/2*-1, AreaWidth*Zoom, height*Zoom); // Schnipsel positionieren // if (i==2) {filter(INVERT);} else {filter(GRAY);} // filtering test... klappt leider nicht, da der filter auf das gesamte bild appliziert wird. } iMousePosOnDragStart = mouseX; // Aktuelle Mausposition speichern } void mouseReleased() { if (mouseButton==37)//left mouseButton. Drag. { // Nicht mehr Drag Modus, daten zurücksetzen. if (iCurrentManPic != -1) { if (bolLeftClickOneObject) { bSpeed[iCurrentManPic] = abs(iMousePosOffset); if (iMousePosOffset > 0) { bDir[iCurrentManPic] = 1; } else { bDir[iCurrentManPic] = -1; } } } bolMousePressed = false; iMousePosOffset = 0; iCurrentManPic = -1; } } void mousePressed() { // Zoomfaktor bestimmen für EinzelBildCatch float ZoomFactor; if (bolZoom) { ZoomFactor = 1.4; } else { ZoomFactor = 1; } // Drag if (mouseButton==37)//left mouseButton. Drag. { // einzelbild Drag if (bolLeftClickOneObject) { for (int i = 0; i bCurPos[i] && mouseX < bCurPos[i]+AreaWidth*ZoomFactor) { iCurrentManPic = i; } } } // normaler Drag else { bolMousePressed = true; iMousePosOnDragStart = mouseX; } } else if (mouseButton==39)//right mouseButton. Neuer Schnipsel... { // Wenn Max Schnitzel erreicht, alle eins nach vorne schieben (ältestes fällt weg) if (NumOfPics == iMax) { for (int i = 0; i2) { bDir[NumOfPics-1] = 1; } else { bDir[NumOfPics-1] = -1; } println("Anzahl Schnipsel: " + NumOfPics); bTrans[NumOfPics-1] = int(random(100,255)); } } //Konfiguration void keyPressed() { println2(str(keyCode)); switch(keyCode) { //w case 87: WeltIstRund = !WeltIstRund; println("Welt ist rund: " + WeltIstRund); break; //r 82 case 82: bolRandomAppearing = !bolRandomAppearing; println("RandomAppearing: " + bolRandomAppearing); break; //d 68 case 68: bolPrintDebugInfo = !bolPrintDebugInfo; println("PrintDebugInfo: " + bolPrintDebugInfo); break; //+ case 107: iSmoothRegionPix += 1; println("SmoothRegionPix: " + iSmoothRegionPix); break; //- case 45: iSmoothRegionPix -= 1; println("SmoothRegionPix: " + iSmoothRegionPix); break; //l case 76: bolLeftClickOneObject = !bolLeftClickOneObject; println("LeftClickOneObject: " + bolLeftClickOneObject); break; //z case 90: bolZoom = !bolZoom; println("Zoom: " + bolZoom); break; } } void println2(Object Text) { if (bolPrintDebugInfo) { println(Text); } }