Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
geometric_separators/geometric_separators.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (55 sloc)
1.32 KB
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
// Reset Button | |
int reset_x = 100; | |
int reset_y = 450; | |
int reset_w = 100; | |
int reset_h = 25; | |
// Calculate Button | |
int calc_x = 250; | |
int calc_y = 450; | |
int calc_w = 100; | |
int calc_h = 25; | |
// Button Shapes | |
PShape reset; | |
PShape calculate; | |
// Input list | |
ArrayList<PVector> input = new ArrayList<PVector>(); | |
// Setup | |
void setup() { | |
background(255); | |
size(500,500,P2D); | |
// Create buttons | |
reset = createShape(RECT, reset_x, reset_y, reset_w, reset_h); | |
calculate = createShape(RECT, calc_x, calc_y, calc_w, calc_h); | |
noLoop(); | |
} | |
// On mouse press | |
void mousePressed() { | |
// If mouse presses reset button | |
if ((mouseX >= reset_x && mouseX <= (reset_x + reset_w)) && | |
(mouseY >= reset_y && mouseY <= (reset_y + reset_h))) { | |
// Reset input and background | |
input.clear(); | |
} | |
// If mouse presses calculate button | |
else if ((mouseX >= reset_x && mouseX <= (reset_x + reset_w)) && | |
(mouseY >= reset_y && mouseY <= (reset_y + reset_h))) { | |
// Get sorted input points | |
} | |
else { | |
PVector new_point = new PVector(mouseX, mouseY); | |
input.add(new_point); | |
} | |
redraw(); | |
} | |
// Draw | |
void draw() { | |
background(255); | |
shape(reset); | |
shape(calculate); | |
text("Reset.", reset_x + 25, reset_y - 10); | |
text("Calculate.", calc_x + 25, calc_y - 10); | |
for (PVector point : input) { | |
strokeWeight(4); | |
point(point.x, point.y); | |
} | |
} |