-
-
Save hanyuone/11f4990d83a0831b96f5e65cbb5d3fe3 to your computer and use it in GitHub Desktop.
Processing Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CentreText { | |
String text; | |
float font_size; | |
float[] coords; | |
float[] dimensions; | |
float text_width; | |
CentreText(String txt, int size, float[] co, float[] dim) { | |
coords = co; | |
text = txt; | |
font_size = size; | |
dimensions = dim; | |
textSize(font_size); | |
text_width = textWidth(text); | |
} | |
void changeFontSize() { | |
textSize(1); | |
font_size = (dimensions[0] - (dimensions[0] / 100)) / textWidth(text); | |
if (font_size > dimensions[1]) { | |
font_size = dimensions[1] - (dimensions[1] / 100); | |
} | |
textSize(font_size); | |
text_width = textWidth(text); | |
} | |
void displayText() { | |
changeFontSize(); | |
fill(#000000); | |
text(text, coords[0] - (text_width / 2), coords[1] + (font_size / 3)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProgressBar { | |
float[] dimensions; | |
float[] coords; | |
int colour; | |
ProgressBar(float[] dim, float[] co, int col) { | |
dimensions = dim; | |
coords = co; | |
colour = col; | |
} | |
void fill_bar() { | |
fill(#ffffff); | |
rect(coords[0], coords[1], dimensions[0], dimensions[1]); | |
} | |
void update(float percent) { | |
float progress_width; | |
float x_axis; | |
String percent_str = Double.toString(Math.ceil(percent * 100)) + "%"; | |
if (percent < 0.5) { | |
progress_width = dimensions[0] * (1 - percent); | |
x_axis = coords[0] + (dimensions[0] * (1 + percent) / 2); | |
} else { | |
progress_width = dimensions[0] * percent; | |
x_axis = coords[0] + (progress_width / 2); | |
} | |
fill_bar(); | |
fill(colour); | |
rect(coords[0], coords[1], dimensions[0] * percent, dimensions[1]); | |
CentreText disp_percent = new CentreText(percent_str, 1, | |
new float[] {x_axis, | |
coords[1] + (dimensions[1] / 2)}, | |
new float[] {progress_width, dimensions[1]}); | |
disp_percent.displayText(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ButtonWindow window = new ButtonWindow(); | |
Button start = new Button(new float[] {10, 10}, | |
new float[] {100, 50}, "Start", | |
new Runnable() { | |
public void run() { | |
progress_inc = 1; | |
} | |
}); | |
Button end = new Button(new float[] {120, 10}, | |
new float[] {100, 50}, "End", | |
new Runnable() { | |
public void run() { | |
progress_inc = 0; | |
} | |
}); | |
ProgressBar other = new ProgressBar(new float[] {200, 20}, | |
new float[] {590, 10}, | |
#ff00ff); | |
float progress = 0; | |
float progress_inc = 0; | |
boolean click = true; | |
long start_time = System.currentTimeMillis(); | |
int start_count = 0; | |
void process_prog() { | |
progress = (progress + progress_inc) % 100; | |
other.update(progress / 100); | |
} | |
void setup() { | |
size(800, 800); | |
start.drawButton(); | |
window.addButton(start); | |
end.drawButton(); | |
window.addButton(end); | |
other.update(0); | |
} | |
void draw() { | |
if (mousePressed && click) { | |
window.checkClick().run(); | |
click = false; | |
} else if (!mousePressed) { | |
click = true; | |
} | |
if ((System.currentTimeMillis() - start_time) / 100 > start_count) { | |
start_count += 1; | |
process_prog(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment