Sie sind auf Seite 1von 4

// Final Project // Love in Letters PFont font = createFont("Calibri-LightItalic", 48); PFont font2 = createFont("Gabriola", 48); //color backgroundColor = color(245,

212, 146); color backgroundColor = color(5, 2, 0); TextAnalyzer myAnalyzer; Word[] theCircles; String testFile = "test letter.txt"; //Word[] testCircles; // Toolbar and Buttons int offset = 10; int toolBarW = 75; boolean letterButton = false; boolean circlesButton = true; int buttonsX = toolBarW/2; int buttonW = toolBarW - 2*offset; int buttonH = 2*buttonW; int buttonStrokeWeight = 3; int buttonCornerR = 2; int textSize = 20; color buttonC = color(245, 212, 146); // cream int letterButtonY = 300; String letterWriter = "Ludwig"; int circleButtonD = 55; int circleButtonY = 450; color circleButtonC = color(196, 14, 47); color letterColor = color(245, 212, 146); // cream int letterTextSize = 20; int textBoxW = 625; int textBoxH = 500; void setup() { size(800, 600); smooth(); myAnalyzer = new TextAnalyzer(testFile); // // // // // testCircles = new Word[100]; for(int i = 0; i < testCircles.length; i++) { testCircles[i] = new Word("test"); }

//noLoop(); myAnalyzer.Parse(); myAnalyzer.Count();

theCircles = new Word[myAnalyzer.words.size()]; for (int i = 0; i < theCircles.length; i++) { theCircles[i] = new Word(myAnalyzer.words.get(i).word, toolBarW); theCircles[i].UpdateCount(myAnalyzer.words.get(i).count); } for (int i = 0; i < theCircles.length; i++) { //println("got to the first of the reset loops"); // check for collisions and reset circle positions necessary for (int j = 0; j < theCircles.length; j++) { println("i: " + i + " and j: " + j); if (theCircles[i] != theCircles[j]) { println("Now comparing '" + theCircles[i].word + "' and '" + theCircles[ j].word + "'"); println("x: " + theCircles[i].x + " vs " + theCircles[j].x); println("y: " + theCircles[i].y + " vs " + theCircles[j].y); if (theCircles[i].Collision(theCircles[j])) { println("the if statement works"); theCircles[i].ResetPosition(); println("position has been reset to (" + theCircles[i].x + ", " + theC ircles[i].y + ")"); } } } } } void draw() { background(backgroundColor); if (letterButton) { rectMode(CORNER); fill(letterColor); noStroke(); rect(toolBarW, 0, width-toolBarW, height); textFont(font2, letterTextSize); textAlign(LEFT, CENTER); fill(backgroundColor); // This works better // text(myAnalyzer.oneLongString, toolBarW + 5*offset, 5*offset, textBoxW , textBoxH); String finalText = ""; for (int i = 0; i < myAnalyzer.linesFromLetters.length; i++) { finalText += myAnalyzer.linesFromLetters[i] + "\n"; } rectMode(CORNER); text(finalText, 100, 50, textBoxW, textBoxH); DrawToolbar();

DrawLetterButtons(buttonC, letterButtonY, letterWriter); DrawCircleButton(); } else if (circlesButton) { for (int i = 0; i < theCircles.length; i++) { theCircles[i].DrawWords(); } DrawToolbar(); DrawLetterButtons(buttonC, letterButtonY, letterWriter); DrawCircleButton(); } else { // nothing } DrawToolbar(); DrawLetterButtons(buttonC, letterButtonY, letterWriter); DrawCircleButton(); } void { // // if { mousePressed() Buttons! the right and left sides of the buttons (mouseX <= offset + buttonW && mouseX >= offset) // the bottoms and tops of the buttons // Letter Button if (mouseY <= letterButtonY + (buttonH/2) && mouseY >= letterButtonY - (buttonH/2)) { letterButton = true; circlesButton = false; println("Show Letter"); } // Circles Button else if (mouseY <= circleButtonY + (circleButtonD/2) && mouseY >= circleButtonY - (circleButtonD/2)) { letterButton = false; circlesButton = true; println("Show Circles"); } else { // nothing } } } void DrawToolbar() { noStroke(); fill(backgroundColor); rect(0, 0, toolBarW, height); }

void DrawLetterButtons(color strokeC, int centerY, String name) { strokeWeight(buttonStrokeWeight); // to be able to add an "active" letter stroke later for more letters stroke(strokeC); fill(buttonC); // school computers require one more buttonCornerR parameter rectMode(CENTER); rect(buttonsX, centerY, buttonW, buttonH, buttonCornerR); // println(centerY); // text on the button textFont(font2, textSize); textAlign(CENTER); fill(backgroundColor); text(name, buttonsX, centerY); } void DrawCircleButton() { // println("DRAWING CIRCLE BUTTON"); strokeWeight(buttonStrokeWeight); stroke(circleButtonC); noFill(); ellipseMode(CENTER); ellipse(buttonsX, circleButtonY, circleButtonD, circleButtonD); }

Das könnte Ihnen auch gefallen