/* Copyright <2018> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ import processing.serial.*; //import the Serial library private static final String PORT = "COM8"; //Check the COM before playing and change if needed Serial myPort; // Create object from Serial class char val; // Data received from the serial port int circleX, circleY; // Position of circle button int circleSize = 60; // Diameter of circle int firstPetalX, firstPetalY; // Position of first petal button int PetalSize = 60; // Diameter of petal button int rectWidth = 350; int rectHeight = 50; int secondPetalX, secondPetalY; // Position of second petal button int thirdPetalX, thirdPetalY; // Position of third petal button int fourthPetalX, fourthPetalY; // Position of third petal button int fifthPetalX, fifthPetalY; // Position of third petal button int rectX, rectY; // Position of third petal button color circleColor; color firstPetalColor; color secondPetalColor; color thirdPetalColor; color fourthPetalColor; color fifthPetalColor; color ColorHighlight; color rectColor; color basePetalColor; color currentPetalColor; color petalColor; color highlightPetalColor; boolean circleOver = false; boolean firstPetalOver = false; boolean secondPetalOver = false; boolean thirdPetalOver = false; boolean fourthPetalOver = false; boolean fifthPetalOver = false; boolean rectOver = false; int countSelectedPetals = 0; Button centerFlowerButton; Button firstPetalButton; Button secondPetalButton; Button thirdPetalButton; Button fourthPetalButton; Button fifthPetalButton; Button rectButton; String [] studentNames = { "Ari", "Behnaz", "Heidi", "Jari", "Kati", "Marta", "Megumi", "Mikko", "Peetu" }; //Added code for multi page static final int MAX = 1, GAP = 15, DIM = 120, RAD = DIM >> 1; //MAX is for the maximum number of pages int page, cx, cy; //Added code for multi page pageButton back, next; //Added code for multi page void setup() { size(375, 667); basePetalColor = color (#ffffff); highlightPetalColor = color (#FFd1dc); petalColor = color (#FF1493); circleColor = color(#ffff00); firstPetalColor = color(#ffffff); secondPetalColor = color(#ffffff); thirdPetalColor = color(#ffffff); fourthPetalColor = color(#ffffff); fifthPetalColor = color(#ffffff); rectColor = color(#00b200); currentPetalColor = basePetalColor; circleX = width/2; circleY = height/2; firstPetalX = width/2; firstPetalY = height/2-50; secondPetalX = width/2+45; secondPetalY = height/2-12; thirdPetalX = width/2+22; thirdPetalY = height/2+41; fourthPetalX = width/2-35; fourthPetalY = height/2+40; fifthPetalX = width/2-48; fifthPetalY = height/2-15; rectX = width/2-rectWidth/2; rectY = height/2+174; println("Port Name "+ PORT); myPort = new Serial(this, PORT, 9600); // Open the port that the board is connected to and use the same speed (9600 bps) firstPetalButton = new Button(width/2, height/2-60, 60); secondPetalButton = new Button(width/2, height/2-90, 60); thirdPetalButton = new Button(width/2, height/2-90, 60); fourthPetalButton = new Button(width/2, height/2-90, 60); fifthPetalButton = new Button(width/2, height/2-90, 60); centerFlowerButton = new Button(width/2, height/2, 60); rectButton = new Button(-width/3, -height/3, 90); //Added code for multi page rectMode(CORNER); textAlign(CENTER, CENTER); stroke(0); strokeWeight(1.5); cx = width >> 1; cy = height >> 1; back = new pageButton("BACK", GAP, height - pageButton.H - GAP); next = new pageButton("NEXT", width - pageButton.W - GAP, height - pageButton.H - GAP); }//End of setup() void draw() { background(#ffcc00); noStroke(); if (rectOver) { rectColor = color(#57f267); } else { rectColor = color(#00b200); } if (countSelectedPetals >= 3) { circleSize = 70 ; } else if (countSelectedPetals < 3) { circleSize = 60 ; } //Added code for multi page textSize(0100); textSize(pageButton.TXTSZ); if (page > 0) back.display(); if (page < MAX) next.display(); //method("page" + page); // Java only! pageSelector(); // For JS! } //End of draw() void serialEvent(Serial p) { String c = p.readString(); print(c); } void mouseClicked() { if (firstPetalOver) { if (firstPetalColor == color(#FF1493)) { firstPetalColor = color (#ffffff); countSelectedPetals --; println("Petal1 Button Clicked: "); } else if (firstPetalColor == color(#ffffff)) { firstPetalColor = color (#FF1493); countSelectedPetals ++; println(countSelectedPetals); } } else if (secondPetalOver) { if (secondPetalColor == color(#FF1493)) { secondPetalColor = color (#ffffff); countSelectedPetals --; println("Petal2 Button Clicked: "); } else if (secondPetalColor == color(#ffffff)) { secondPetalColor = color (#FF1493); countSelectedPetals ++; println(countSelectedPetals); } } else if (thirdPetalOver) { if (thirdPetalColor == color(#FF1493)) { thirdPetalColor = color (#ffffff); countSelectedPetals --; println(countSelectedPetals); println("Petal3 Button Clicked: "); } else if (thirdPetalColor == color(#ffffff)) { thirdPetalColor = color (#FF1493); countSelectedPetals ++; println(countSelectedPetals); } } else if (fourthPetalOver) { if (fourthPetalColor == color(#FF1493)) { fourthPetalColor = color (#ffffff); countSelectedPetals --; println(countSelectedPetals); println("Petal4 Button Clicked: "); } else if (fourthPetalColor == color(#ffffff)) { fourthPetalColor = color (#FF1493); countSelectedPetals ++; println(countSelectedPetals); } } else if (fifthPetalOver) { if (fifthPetalColor == color(#FF1493)) { fifthPetalColor = color (#ffffff); countSelectedPetals --; println(countSelectedPetals); println("Petal5 Button Clicked: "); } else if (fifthPetalColor == color(#ffffff)) { fifthPetalColor = color (#FF1493); countSelectedPetals ++; println(countSelectedPetals); } } else if (rectOver) { if (countSelectedPetals >= 3) { myPort.write('H'); // send H to indicate when rating is >=3 and the mouse is over the rate button and pressed println("H"); } else if (countSelectedPetals < 3) { myPort.write('L'); // Otherwise, send L println("L"); } } //Added code for multi page if (page > 0 && back.isHovering) --page; else if (page < MAX && next.isHovering) ++page; redraw(); } //End of mousePressed() void update(int x, int y) { if ( centerFlowerButton.overCircle(circleX, circleY, circleSize) ) { circleOver = true; firstPetalOver = false; } else if ( firstPetalButton.overFirstPetal(firstPetalX, firstPetalY, PetalSize) ) { firstPetalOver = true; circleOver = false; } else if ( secondPetalButton.overSecondPetal(secondPetalX, secondPetalY, PetalSize) ) { secondPetalOver = true; firstPetalOver = false; circleOver = false; } else if ( thirdPetalButton.overThirdPetal(thirdPetalX, thirdPetalY, PetalSize) ) { thirdPetalOver = true; secondPetalOver = false; firstPetalOver = false; circleOver = false; } else if ( fourthPetalButton.overFourthPetal(fourthPetalX, fourthPetalY, PetalSize) ) { fourthPetalOver = true; thirdPetalOver = false; secondPetalOver = false; firstPetalOver = false; circleOver = false; } else if ( fifthPetalButton.overFifthPetal(fifthPetalX, fifthPetalY, PetalSize) ) { fifthPetalOver = true; fourthPetalOver = false; thirdPetalOver = false; secondPetalOver = false; firstPetalOver = false; circleOver = false; } else if ( rectButton.overRect(rectX, rectY, rectWidth, rectHeight) ) { rectOver = true; fifthPetalOver = false; fourthPetalOver = false; thirdPetalOver = false; secondPetalOver = false; firstPetalOver = false; circleOver = false; } else { circleOver = firstPetalOver = secondPetalOver = thirdPetalOver = fourthPetalOver = fifthPetalOver = rectOver = false; } } // the Button class class Button { int x; int y; int s; // constructor Button(int xpos, int ypos, int sz) { x = xpos; y = ypos; s = sz; } //end of constructor void drawCenter() { stroke(255); stroke(0); fill(circleColor); ellipse(circleX, circleY, circleSize, circleSize); } //end of draw void drawFirstPetal() { stroke(255); stroke(0); fill(firstPetalColor); ellipse(firstPetalX, firstPetalY, PetalSize, PetalSize); } //end of draw void drawSecondPetal() { stroke(255); stroke(0); fill(secondPetalColor); ellipse(secondPetalX, secondPetalY, PetalSize, PetalSize); } //end of draw void drawThirdPetal() { stroke(255); stroke(0); fill(thirdPetalColor); ellipse(thirdPetalX, thirdPetalY, PetalSize, PetalSize); } //end of draw void drawFourthPetal() { stroke(255); stroke(0); fill(fourthPetalColor); ellipse(fourthPetalX, fourthPetalY, PetalSize, PetalSize); } //end of draw void drawFifthPetal() { stroke(255); stroke(0); fill(fifthPetalColor); ellipse(fifthPetalX, fifthPetalY, PetalSize, PetalSize); } //end of draw void drawRect() { noStroke(); fill(rectColor); rect(rectX, rectY, rectWidth, rectHeight); fill(#ffffff); text("L I G T H U P", width/2, 540); textAlign(CENTER); textSize(10); } //end of draw boolean overCircle(int x, int y, int diameter1) { float disX1 = x - mouseX; float disY1 = y - mouseY; if (sqrt(sq(disX1) + sq(disY1)) < diameter1/2 ) { return true; } else { return false; } } //End of MouseIsOver boolean overFirstPetal(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } boolean overSecondPetal(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } boolean overThirdPetal(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } boolean overFourthPetal(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } boolean overFifthPetal(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } } //End of button class //Added code for multi page void mouseMoved() { back.isInside(); next.isInside(); } void page0() { fill(#05a8bf); textAlign(CENTER); textSize(30); text("Welcome to rate:", cx, GAP*10); fill(0); textSize(50); text("MAKER", cx, GAP*20); fill(#FF1493); textSize(30); text("Ava", cx, GAP*23); rectMode(CORNER); textAlign(CENTER, CENTER); } void page1() { update(mouseX, mouseY); fill(#05a8bf); textAlign(CENTER); textSize(30); text("Ava's 3D Design Skills", width/2, 180); firstPetalButton.drawFirstPetal(); secondPetalButton.drawSecondPetal(); thirdPetalButton.drawThirdPetal(); fourthPetalButton.drawFourthPetal(); fifthPetalButton.drawFifthPetal(); centerFlowerButton.drawCenter(); textSize(22); rectButton.drawRect(); rectMode(CORNER); textAlign(CENTER, CENTER); } void pageSelector() { switch(page) { case 0: page0(); break; case 1: page1(); break; } } class pageButton { static final int W = 60, H = 40, TXTSZ = 020; static final color BTNC = #00A0A0, HOVC = #00FFFF, TXTC = #FFFFFF; final String label; final short x, y, xW, yH; boolean isHovering; pageButton(String txt, int xx, int yy) { label = txt; x = (short) xx; y = (short) yy; xW = (short) (xx + W); yH = (short) (yy + H); } void display() { fill(isHovering? HOVC:BTNC); rect(x, y, W, H); fill(TXTC); text(label, x + W/2, y + H/2); } boolean isInside() { return isHovering = mouseX > x & mouseX < xW & mouseY > y & mouseY < yH; } }