import peasy.PeasyCam; import processing.core.PApplet;
import java.util.ArrayList; import java.util.Collections; public class BAYCOFirstHackathonApp extends PApplet { ArrayList bouncingBalls = new ArrayList<>(); ArrayList buttonList = new ArrayList<>(); ArrayList messageList = new ArrayList<>(); //ArrayList options = new ArrayList<>(Arrays.asList("main", "settings", "relax1", "relax2", "message", "message2")); int bSize = 40; int sSize = 10; int keysPressed = 0; int currenttexts = 1; int jump = 50, dragx = 50, scrollx, dragy = 50, scrolly; int colorrx = 50, colorbx = 50, colorgx = 50; float colorr = 1, colorb = 1, colorg = 1; float w, h; PeasyCam camera; boolean main, relax1, relax2, message1, message2, settings; public void settings() { size(450, 800, P2D); } public void setup() { /* String[] fontList = PFont.list(); printArray(fontList); textFont(createFont("Georgia", 100));*/ for (int i = 0; i < width; i += 15) { for (int j = 0; j < height; j += 15) { int color = color(randInt(0, 255), randInt(0, 255), randInt(0, 255)); BouncingBall bb = new BouncingBall(i, j, 0, 0, sSize, color); bouncingBalls.add(bb); } } w = width; h = height; Buttons main = new Buttons(w/2, 150, 200, 100, "Menu"); Buttons settings = new Buttons(400, 50, 70, 20, "Settings"); Buttons relax1 = new Buttons(w/4, h/2, 100, 30, "Relax"); Buttons relax2 = new Buttons(3*w/4, h/2, 100, 30, "Get Help"); Buttons message1 = new Buttons(w/4, 3*h/4, 75, 30, "Talk"); Buttons message2 = new Buttons(3*w/4, 3*h/4, 100, 30, "Blank"); Buttons mainCorner = new Buttons(50, 760, 120, 40, "Return"); Collections.addAll(buttonList, main, settings, relax1, relax2, message1, message2, mainCorner); buttonList.get(0).current = true; buttonList.get(6).current = true; messageList.add(new TextMessage()); messageList.get(0).text = "How are you feeling? 1-5"; messageList.add(new TextMessage());
}
public void draw() {
strokeWeight(0);
if(buttonList.get(0).current || buttonList.get(6).current){ //main
background(177*colorr, 156*colorb, 217*colorg);
fill(0, 255, 0);
textAlign(CENTER);
textSize(50);
text("Breathe", width/2, height/10);
}else {
if(buttonList.get(1).current) { //Settings
background(255, 0, 0);
textSize(24);
textAlign(CENTER);
rectMode(CORNER);
fill(200*colorr, 15*colorb, 15*colorg);
text("Change Color Scheme", w/2, 25);
int sliderballSize = 32;
drawHorizontalSlider(128, 50, 50, 350, 24, 0, sliderballSize, colorrx);
if (mousePressed && mouseX >= 50 && mouseX <= 400 && clickedCircle(mouseX, mouseY, colorrx, 62, sliderballSize/2)) {
colorrx = mouseX;
}
colorr = ((float) colorrx - 25)/25;
drawHorizontalSlider(128, 50, 100, 350, 24, 0, sliderballSize, colorbx);
if (mousePressed && mouseX >= 50 && mouseX <= 400 && clickedCircle(mouseX, mouseY, colorbx, 112, sliderballSize/2)) {
colorbx = mouseX;
}
colorb = ((float) colorbx - 25)/25;
drawHorizontalSlider(128, 50, 150, 350, 24, 0, sliderballSize, colorgx);
if (mousePressed && mouseX >= 50 && mouseX <= 400 && clickedCircle(mouseX, mouseY, colorgx, 162, sliderballSize/2)) {
colorgx = mouseX;
}
colorg = ((float) colorgx-25)/25;
}else if(buttonList.get(2).current){ //Relax
background(255);
for (int i = 0; i < bouncingBalls.size(); i++) {
BouncingBall bb = bouncingBalls.get(i);
fill(bb.color);
ellipse(bb.x, bb.y, bb.size, bb.size);
if (dist(bb.x, bb.y, mouseX, mouseY) <= (double) (bSize + sSize) / 2) {
bb.xSpeed = randInt(-3, 3);
bb.ySpeed = randInt(-3, 3);
}
for (int x = 0; x < bouncingBalls.size(); x++) { //check collision between balls
if (x != i) {
BouncingBall bbx = bouncingBalls.get(x);
double radialdistance = ((double) (bb.size + bbx.size) / 2);
if (collidedCircle(bb.x, bb.y, bbx.x, bbx.y, radialdistance)) {
if (Math.abs(bb.xSpeed) > Math.abs(bbx.xSpeed) && Math.abs(bb.ySpeed) > Math.abs(bbx.ySpeed)) {
float multiple = (float) 0.65;
bb.xSpeed = (bb.ySpeed + bbx.xSpeed)*multiple;
bb.ySpeed = (bb.xSpeed + bbx.ySpeed)*multiple;
bbx.xSpeed = (bb.xSpeed + bbx.ySpeed)*multiple;
bbx.xSpeed = (bb.ySpeed + bbx.xSpeed)*multiple;
}
}
}
}
bb.act();
}
fill(0);
ellipse(mouseX, mouseY, bSize, bSize);
}else if(buttonList.get(3).current){ //Get Help
background(120, 40, 120);
fill(255);
textSize(25);
textAlign(CENTER);
text("Do Not Hide: Get Help", w/2, 50);
fill(0);
textAlign(LEFT);
textSize(20);
fill(225);
text("United States: ", 30-scrollx, 85-scrolly);
text("Canada: ", 30-scrollx, 435-scrolly);
text("UK & Republic of Ireland:", 30-scrollx, 535-scrolly);
text("United States: ", 30-scrollx, 85-scrolly);
fill(0);
textSize(15);
text("Emergency: 911" + '\n' +
"National Domestic Violence Hotline: 1- 800-799-7233" + '\n' +
"National Suicide Prevention Lifeline: 1-800-273-TALK (8255); www.suicidepreventionlifeline.org" + '\n' +
"Suicide Prevention, Awareness, and Support: www.suicide.org" + '\n' +
"Lifeline Crisis Chat: https://www.contact-usa.org/chat.html" + '\n' +
"Crisis Text Line: Text REASON to 741741 (free, confidential and 24/7)" + '\n' +
"Self-Harm Hotline: 1-800-DONT CUT (1-800-366-8288)" + '\n' +
"Family Violence Helpline: 1-800-996-6228" + '\n' +
"Planned Parenthood Hotline: 1-800-230-PLAN (7526)" + '\n' +
"American Association of Poison Control Centers: 1-800-222-1222" + '\n' +
"National Council on Alcoholism & Drug Dependency: 1-800-622-2255" + '\n' +
"GLBT Hotline: 1-888-843-4564" + '\n' +
"The Trevor Project: 1-866-488-7386 or text “START” to 678678.", 30-scrollx, 100-scrolly);
text("Emergency: 911" + '\n' +
"Hotline: 1-888-353-2273" + '\n' +
"YourLifeCounts.org: http://www.yourlifecounts.org/need-help/crisis-lines", 30-scrollx, 450-scrolly);
text("Emergency: 112 or 999" + '\n' , 30-scrollx, 550-scrolly);
stroke(0);
//horizontal scroll
textSize(19);
fill(128);
rectMode(CORNER);
rect(50, 783, 350, 15);
fill(0);
ellipse((float) dragx, (float) 790.5, 15, 15);
if (mousePressed && mouseX >= 50 && mouseX <= 400 && clickedCircle(mouseX, mouseY, dragx, (int) 790.5, 50)) {
dragx = mouseX;
}
scrollx = (int) (1.1*(dragx - 50));
//vertical scroll
fill(128);
rect(425, 50, 15, 700);
fill(0);
ellipse((float) 432.5, (float) dragy, 15, 15);
if (mousePressed && mouseY >= 50 && mouseY <= 750 && clickedCircle(mouseX, mouseY, (int) 432.5, dragy,50)) {
dragy = mouseY;
}
scrolly = (int) (1.1*(dragy - 50));
}else if(buttonList.get(4).current){ //Text
background(0, 200, 255);
for (int i = currenttexts; i < messageList.size(); i+=2) {
TextMessage tm = messageList.get(i);
String text = tm.text;
if(keyPressed && keysPressed == 0){
if(key == '\n'){
if(i % 2 == 1) {
messageList.add(new TextMessage());
String firstBotResponse = "";
/*for(int l = 0; l < text.length(); l++){
if(!isDigit(text.charAt(l))){
tm.text = text.substring(0, l) + text.substring(l+1);
}
}*/
if(i == 1) {
boolean leave1 = false;
do{
if (isNumber(text)) {
int firstresponse = Integer.parseInt(tm.text);
if (firstresponse >= 1 && firstresponse <= 5) {
if (firstresponse <= 2) {
firstBotResponse = "Aww, how come? Try this:";
} else if (firstresponse <= 3) {
firstBotResponse = "Try the balls!";
} else if (firstresponse <= 4) {
firstBotResponse = "Hmm";
} else {
firstBotResponse = "Perfect!";
}
} else {
firstBotResponse = "Please give me between 1-5";
}
leave1 = true;
} else {
firstBotResponse = "Number please!";
messageList.get(i + 1).text = firstBotResponse;
messageList.add(new TextMessage());
}
}while(!leave1);
System.out.println("here");
messageList.get(i + 1).text = "How about now?";
messageList.add(new TextMessage());
}else if(i == 5){
if (isNumber(text)) {
int firstresponse = Integer.parseInt(tm.text);
if (firstresponse >= 1 && firstresponse <= 5) {
if (firstresponse <= 2) {
firstBotResponse = "Still?";
} else if (firstresponse <= 3) {
firstBotResponse = "Try the balls again";
} else if (firstresponse <= 4) {
firstBotResponse = "Glad you liked it!";
} else {
firstBotResponse = "Perfect!";
}
} else {
firstBotResponse = "Please give me between 1-5";
}
} else {
firstBotResponse = "Number please!";
messageList.get(i + 1).text = firstBotResponse;
messageList.add(new TextMessage());
}
}
messageList.get(i + 1).text = firstBotResponse;
messageList.add(new TextMessage());
currenttexts += 2;
}
}else if(keyCode == BACKSPACE && tm.text.length() > 0){
tm.text = tm.text.substring(0, tm.text.length()-1);
}else {
tm.text += key;
}
keysPressed++;
}
}
for (int i = 0; i < messageList.size(); i++) {
TextMessage tm = messageList.get(i);
if(i % 2 == 0){
tm.side = false;
tm.x = 125;
}else{
tm.side = true;
tm.x = 350;
}
tm.y = jump * (i+1);
/*for (int x = 0; x < 5; x++) {
if(messageList.get(messageList.size()-1).y >= height) {
for (int j = 0; j < messageList.size(); j++) {
messageList.get(j).y -= jump;
}
do {
for (int j = 0; j < messageList.size(); j++) {
messageList.get(j).y -= jump;
}
System.out.println(messageList.get(messageList.size() - 1).y);
} while (messageList.get(messageList.size() - 1).y >= height);
}
}*/
if(!tm.side){
fill(160);
}else {
fill(0, 255, 0);
}
tm.width = tm.text.length()*9;
float ellipsestartx = 50, ellipseendx;
if(tm.text.length() > 0) {
if(!tm.side){
fill(160);
ellipsestartx = tm.height;
ellipseendx = tm.height + tm.width;
}else {
fill(0, 255, 0);
ellipsestartx = tm.x - tm.width/2;
ellipseendx = tm.x + tm.width/2;
}
rect(ellipsestartx + tm.width/2, tm.y, tm.width, tm.height);
ellipse(ellipsestartx, tm.y, tm.height, tm.height);
ellipse(ellipseendx, tm.y, tm.height, tm.height);
}
if(!tm.side){
fill(0);
}else {
fill(255);
}
textSize(20);
textAlign(LEFT);
text(tm.text, ellipsestartx-10, tm.y+5);
}
}else if(buttonList.get(5).current){ //Blank
background(150, 0, 255);
}
}
for (int i = 0; i < buttonList.size(); i++) {
Buttons b = buttonList.get(i);
float x = b.x;
float y = b.y;
float width = b.width;
float height = b.height;
if((!buttonList.get(0).current && i == 6) || ((buttonList.get(0).current || buttonList.get(6).current) && i != 6)) {
if (clickedRectangle(mouseX, mouseY, x, y, width, height)) {
b.current = true;
for (int j = 0; j < buttonList.size(); j++) {
if(i == 6){
buttonList.get(0).current = true;
}else if(i != j){
buttonList.get(j).current = false;
}
}
int ballcounter = 0;
for (int a = 0; a < this.width; a += 15) {
for (int c = 0; c < this.height; c += 15) {
bouncingBalls.get(ballcounter).x = a;
bouncingBalls.get(ballcounter).y = c;
bouncingBalls.get(ballcounter).xSpeed = 0;
bouncingBalls.get(ballcounter).ySpeed = 0;
ballcounter++;
}
}
}
if(!buttonList.get(0).current && i == 6){
drawButton(b.x, b.y, b.width, b.height, b.key, color(78, 120, 215));
}else if((buttonList.get(0).current || buttonList.get(6).current) && i != 6){
drawButton(b.x, b.y, b.width, b.height, b.key, color(78, 120, 215));
}
}
} //run through display of all buttons
}
public static int randInt(int lower, int upper) {
int rand;
do {
rand = (int) (Math.random() * (upper - lower + 1) + lower);
} while (rand == 0);
return rand;
}
public static double distance(float x1, float y1, float x2, float y2) {
float xDist = x2 - x1;
float yDist = y2 - y1;
double dist = Math.sqrt(xDist * xDist + yDist * yDist);
return dist;
}
public boolean collidedCircle(float x1, float y1, float x2, float y2, double distance) {
return (distance(x1, y1, x2, y2) <= distance);
}
public boolean clickedCircle(float x1, float y1, float x2, float y2, float distance) {
float xDist = x2 - x1;
float yDist = y2 - y1;
double dist = Math.sqrt(xDist * xDist + yDist * yDist);
return (dist <= distance) && mousePressed;
}
public boolean clickedRectangle(float x1, float y1, float x2, float y2, float width, float height) {
x2 = x2 - width/2;
y2 = y2 - height/2;
return ((x1 > x2) && (x1 < (x2 + width)) && (y1 > y2) && (y1 < (y2 + height)) && mousePressed);
}
public void drawButton(float x, float y, float width, float height, String key, int color){
fill(color);
rectMode(CENTER);
rect(x, y, width, height);
fill(0);
textSize((float) (height*0.8));
textAlign(CENTER);
text(key, x, y+height/4);
}
public void keyReleased(){
keysPressed = 0;
}
public static boolean isNumber(String string) {
if (string == null) {
return false;
}
try {
double d = Double.parseDouble(string);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public void drawHorizontalSlider(int sliderColor, int sliderx, int slidery, int sliderwidth, int sliderheight, int ballColor, int sliderballSize, int variable){
fill(sliderColor);
rect(sliderx, slidery, sliderwidth, sliderheight);
fill(ballColor);
ellipse(variable, slidery+sliderheight/2, sliderballSize, sliderballSize);
}
public static void main(String[] args) {
PApplet.main("BAYCOFirstHackathonApp");
}
}
Log in or sign up for Devpost to join the conversation.