Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TullyE authored Apr 26, 2023
1 parent 9b976f8 commit 7ffb8f0
Show file tree
Hide file tree
Showing 6 changed files with 564 additions and 368 deletions.
205 changes: 105 additions & 100 deletions Button.pde
Original file line number Diff line number Diff line change
@@ -1,100 +1,105 @@
/**
*
*
* created by TullyE March 2023
* last updated April 11 2023
*/
class Button {
int bID; // ID of the button
double x, y; // x and y position of the button
double w, h; // width and height of the button
String label; // label of the button
color c; // color of the button
boolean hovered; // whether the mouse is hovering over the button
boolean clicked; // whether the button has been clicked

// Constructor for the button
Button(String label_, double x_, double y_, double w_, double h_, int bID_) {
this.x = x_; // set x position
this.y = y_; // set y position
this.label = label_; // set label
this.w = w_; // set width
this.h = h_; // set height
c = 255; // set initial color to white
bID = bID_; // set button ID
}

// Update the button's color based on whether the mouse is hovering over it or it has been clicked
void update() {
if (touchingMouse()) {
c = 200; // if mouse is hovering, change color to gray
if (clicked) {
c = 100; // if clicked, change color to darker gray
}
} else {
if (clicked && !touchingMouse()) {
c = 200; // if clicked and mouse is not hovering, keep color gray
} else {
c = 255; // otherwise, keep color white
}
}
}

// Display the button on the screen
void show() {
fill(c); // set fill color
stroke(0); // set stroke color to black
rect((float) x, (float) y, (float) w, (float) h); // draw rectangle
fill(0); // set text color to black
textAlign(CENTER); // center text
text(label, (float) (x + w/2), (float) (y + h/2)); // display label inside the button
}

// Check whether the mouse is touching the button
boolean touchingMouse() {
if ((mouseX > this.x && mouseX < this.x + w) && (mouseY > this.y && mouseY < this.y + h)) {
return true;
}
return false;
}

// Set the clicked variable to true if the button is clicked
void mousePressedLogic() {
if (touchingMouse()) {
clicked = true;
}
}

// Perform an action when the button is released
void mouseReleasedLogic() {

if (touchingMouse() && clicked) {
buttonPressed(); // call the buttonPressed() method
clicked = false; // reset clicked variable
}
clicked = false; // reset clicked variable
}

// Perform an action based on the button ID
void buttonPressed() {
if (bID == 0) {
currMass = 1; // set the current mass to 1
} else if (bID == 1) {
currMass = 1000; // set the current mass to 1000
} else if (bID == 2) {
currMass = 10000; // set the current mass to 10000
} else if (bID == 3) {
currMass = 100000; // set the current mass to 100000
} else if (bID == 4) {
currMass = 1000000; // set the current mass to 1000000
} else if (bID == 5) {
currMass = 10000000; // set the current mass to 1000000
} else if (bID == 6) {
particles.removeAll(particles); // remove all of the particles from the screen
} else if (bID == 7) {
println("7"); //generate a protodis
} else if (bID == 8) {
showTrails = !showTrails;
}
}
}
/**
*
*
* created by TullyE March 2023
* last updated April 11 2023
*/
class Button {
int bID; // ID of the button
double x, y; // x and y position of the button
double w, h; // width and height of the button
String label; // label of the button
color c; // color of the button
boolean hovered; // whether the mouse is hovering over the button
boolean clicked; // whether the button has been clicked

// Constructor for the button
Button(String label_, double x_, double y_, double w_, double h_, int bID_) {
this.x = x_; // set x position
this.y = y_; // set y position
this.label = label_; // set label
this.w = w_; // set width
this.h = h_; // set height
c = 255; // set initial color to white
bID = bID_; // set button ID
}

// Update the button's color based on whether the mouse is hovering over it or it has been clicked
void update() {
if (touchingMouse()) {
c = 200; // if mouse is hovering, change color to gray
if (clicked) {
c = 100; // if clicked, change color to darker gray
}
} else {
if (clicked && !touchingMouse()) {
c = 200; // if clicked and mouse is not hovering, keep color gray
} else {
c = 255; // otherwise, keep color white
}
}
}

// Display the button on the screen
void show() {
fill(c); // set fill color
stroke(0); // set stroke color to black
rect((float) x, (float) y, (float) w, (float) h); // draw rectangle
fill(0); // set text color to black
textAlign(CENTER); // center text
text(label, (float) (x + w/2), (float) (y + h/2)); // display label inside the button
}

// Check whether the mouse is touching the button
boolean touchingMouse() {
if ((mouseX > this.x && mouseX < this.x + w) && (mouseY > this.y && mouseY < this.y + h)) {
return true;
}
return false;
}

// Set the clicked variable to true if the button is clicked
void mousePressedLogic() {
if (touchingMouse()) {
clicked = true;
}
}

// Perform an action when the button is released
void mouseReleasedLogic() {

if (touchingMouse() && clicked) {
buttonPressed(); // call the buttonPressed() method
clicked = false; // reset clicked variable
}
clicked = false; // reset clicked variable
}

// Perform an action based on the button ID
void buttonPressed() {
if (bID == 0) {
currMass = 1; // set the current mass to 1
} else if (bID == 1) {
currMass = 1000; // set the current mass to 1000
} else if (bID == 2) {
currMass = 10000; // set the current mass to 10000
} else if (bID == 3) {
currMass = 100000; // set the current mass to 100000
} else if (bID == 4) {
currMass = 1000000; // set the current mass to 1000000
} else if (bID == 5) {
currMass = 10000000; // set the current mass to 1000000
} else if (bID == 6) {
particles.removeAll(particles); // remove all of the particles from the screen
} else if (bID == 7) {
println("7"); //generate a protodis
} else if (bID == 8) {
showTrails = !showTrails;
if (showTrails == false) {
for (sObject o : particles) { //for every particle
o.history.clear(); //clear the history
}
}
}
}
}
138 changes: 69 additions & 69 deletions Hud.pde
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
// Define a class called Hud
class Hud {
// Declare instance variables for x, y, font size, font, and an array of y-values for buttons
double x, y;
double fontSize;
PFont font;
int[] numsYButtonArr = new int[] {10, 9, 8, 7, 6, 5, 5, 1};

// Create an ArrayList to hold buttons and define the constructor for the Hud class
ArrayList<Button> buttons = new ArrayList<Button>();
Hud() {
// Set initial values for font size, font, and y-position
fontSize = 10;
font = createFont("Arial-ItalicMT", 10);
y = 20;
// Add buttons to the ArrayList with specified parameters (name, x-position, y-position, width, height, button number)
buttons.add(new Button("Tiny", 0, height - (10 * y), 50, 20, 0)); // 0
buttons.add(new Button("Small", 0, height - (9 * y), 50, 20, 1)); // 1
buttons.add(new Button("Medium", 0, height - (8 * y), 50, 20, 2)); // 2
buttons.add(new Button("Large", 0, height - (7 * y), 50, 20, 3)); // 3
buttons.add(new Button("Huge", 0, height - (6 * y), 50, 20, 4)); // 4
buttons.add(new Button("OMFG", 0, height - (5 * y), 50, 20, 5)); // 5
buttons.add(new Button("Clear", 100, height - (5 * y), 50, 20, 6)); // 6
//buttons.add(new Button("Paths", 100, height - (4 * y), 50, 20, 8)); // 8
buttons.add(new Button("Generate proto disk (slow start)", 0, height - (1 * y), 150, 20, 7)); // 7
}

// Define a method to update the y-position of the buttons
void update() {
for (int i = 0; i < buttons.size(); i ++) {
buttons.get(i).y = height - numsYButtonArr[i] * 20;
}
}

// Define a method to show the text and buttons on the screen
void show() {
// Set the font and font size for the text
textFont (font);
textSize((float) fontSize);
// Set the initial y-position for the text
y = fontSize;
// Update and show each button in the ArrayList
for (Button b : buttons) {
b.update();
b.show();
}
// Set the fill color to white and the text alignment to left, and display some informational text
fill(255);
textAlign(LEFT);
text("Not to physical scale. Gravitational constant is 1. Particle radius is log of mass. Integration is θ(n^2)Euler.", 0, (float) fontSize);
// Display the current mass and number of particles
text("Mass: " + currMass, 0, height - (10.5 * 20));
text("Particle Num: " + particles.size(), 0, height - (3 * 20));
}

// Define a method to handle logic when the mouse is pressed
void mousePressedLogic() {
for (Button b : buttons) {
b.mousePressedLogic();
}
}

// Define a method to handle logic when the mouse is released
void mouseReleasedLogic() {
for (Button b : buttons) {
b.mouseReleasedLogic();
}
}
}
// Define a class called Hud
class Hud {
// Declare instance variables for x, y, font size, font, and an array of y-values for buttons
double x, y;
double fontSize;
PFont font;
int[] numsYButtonArr = new int[] {10, 9, 8, 7, 6, 5, 5, 4, 1};

// Create an ArrayList to hold buttons and define the constructor for the Hud class
ArrayList<Button> buttons = new ArrayList<Button>();
Hud() {
// Set initial values for font size, font, and y-position
fontSize = 10;
font = createFont("Arial-ItalicMT", 10);
y = 20;
// Add buttons to the ArrayList with specified parameters (name, x-position, y-position, width, height, button number)
buttons.add(new Button("Tiny", 0, height - (10 * y), 50, 20, 0)); // 0
buttons.add(new Button("Small", 0, height - (9 * y), 50, 20, 1)); // 1
buttons.add(new Button("Medium", 0, height - (8 * y), 50, 20, 2)); // 2
buttons.add(new Button("Large", 0, height - (7 * y), 50, 20, 3)); // 3
buttons.add(new Button("Huge", 0, height - (6 * y), 50, 20, 4)); // 4
buttons.add(new Button("OMFG", 0, height - (5 * y), 50, 20, 5)); // 5
buttons.add(new Button("Clear", 100, height - (5 * y), 50, 20, 6)); // 6
buttons.add(new Button("Paths", 100, height - (4 * y), 50, 20, 8)); // 8
buttons.add(new Button("Generate proto disk (slow start)", 0, height - (1 * y), 150, 20, 7)); // 7
}

// Define a method to update the y-position of the buttons
void update() {
for (int i = 0; i < buttons.size(); i ++) {
buttons.get(i).y = height - numsYButtonArr[i] * 20;
}
}

// Define a method to show the text and buttons on the screen
void show() {
// Set the font and font size for the text
textFont (font);
textSize((float) fontSize);
// Set the initial y-position for the text
y = fontSize;
// Update and show each button in the ArrayList
for (Button b : buttons) {
b.update();
b.show();
}
// Set the fill color to white and the text alignment to left, and display some informational text
fill(255);
textAlign(LEFT);
text("Not to physical scale. Gravitational constant is 1. Particle radius is log of mass. Integration is θ(n^2)Euler.", 0, (float) fontSize);
// Display the current mass and number of particles
text("Mass: " + currMass, 0, height - (10.5 * 20));
text("Particle Num: " + particles.size(), 0, height - (3 * 20));
}

// Define a method to handle logic when the mouse is pressed
void mousePressedLogic() {
for (Button b : buttons) {
b.mousePressedLogic();
}
}

// Define a method to handle logic when the mouse is released
void mouseReleasedLogic() {
for (Button b : buttons) {
b.mouseReleasedLogic();
}
}
}
Loading

0 comments on commit 7ffb8f0

Please sign in to comment.