Screen buttons
in
Programming Questions
•
1 year ago
Hello to all users,
1. Even if i change the screen to another resolution the rectangles should divide across the screen (that's why i added sizeX and sizeY).
2. Each of the rectangles must store a value of 0 or 1 in the arraylist. So in total 39 values for the 39 rectangles. I really don't know how to do this.(if i go with a separate mouseX and mouseY postions i lose the dynamic sizing of the rectangles).
Rectangles == buttons :)
Thank you for your time.
This is my first post and as you might guess i am sort of new to processing. I made this code which has a array for storing values of 0 and 1 when the rectangle is clicked with the left or right mouse button. Values are added only if the arraylist is empty, but changed if the position has a value. As you might have noticed the rectangle is the entire 640, 480 screen. Here is the code:
- import java.util.Collections;
int value;
int cols = 13;
int rows = 3;
int sizeX, sizeY;
boolean light = false;
ArrayList ledArray;
void setup() {
size(640, 480);
background(255);
smooth();
ledArray = new ArrayList();
sizeX = width/cols;
sizeY = height/rows;
println(sizeX);
}
void draw() {
rect(0, 0, width, height);
}
void mousePressed() {
if (mouseButton == LEFT) {
value = 1;
if (ledArray.isEmpty()) {
ledArray.add(0, value);
}
else {
ledArray.set(0, value);
}
println("Light is on " + value);
fill(255, 0, 0);
}
if (mouseButton == RIGHT) {
value = 0;
if (ledArray.isEmpty()) {
ledArray.add(0, value);
}
else {
ledArray.set(0, value);
}
println("Light is off " + value);
fill(0);
}
else {
}
//inverts the array list
//Collections.reverse(ledArray);
println("Array list:" + ledArray);
println("Array size:" + ledArray.size());
println("------------------------");
}
1. Even if i change the screen to another resolution the rectangles should divide across the screen (that's why i added sizeX and sizeY).
2. Each of the rectangles must store a value of 0 or 1 in the arraylist. So in total 39 values for the 39 rectangles. I really don't know how to do this.(if i go with a separate mouseX and mouseY postions i lose the dynamic sizing of the rectangles).
Rectangles == buttons :)
Thank you for your time.
1