We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on making a number pad for what will eventually turn into an alarm clock. I have a bit of code that draws the numbers 1-9 and 0 and also draws boxes around each number. I am trying to make the code scale so that it looks nice no matter what the screen resolution is. I was just wondering if someone knew of a way to make this code look a little bit better. One simple fix I think I am going to do is have variables to represent (height/15)/2, 3*(height/15)/2, and (height/15). but that will still only shorten the code so much. Does anyone know some good reading material that relates to making programs scale well?
int r = 0;
for(int i = 1; i < 10; i++){
if(i%3 == 1){
rect((x-((3*(height/15))/2))-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15))-(height/15)/3, height/15, height/15, 10);
text(i, x-((3*(height/15))/2), (y-((3*(height/15))/2))+(r*(height/15)));
}
else if(i%3 == 2){
rect(x-(height/15)/2-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15))-(height/15)/3, height/15, height/15, 10);
text(i, x-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15)));
}
else if(i%3 == 0){
rect(x+(height/15)/2-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15))-(height/15)/3, height/15, height/15, 10);
text(i, x+(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15)));
r++;
}
}
rect(x-(height/15)/2-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15))-(height/15)/3, height/15, height/15, 10);
text("0", x-(height/15)/2, (y-((3*(height/15))/2))+(r*(height/15)));
Answers
Look at the tutorials
There is one on objects
With oop you can make a list of rects and draw them in a single spot
Their data is stored and then they are shown in a central place
Thanks. I'll take a look.
this is what I meant basically
a class Cell (which is a rect basically) and an array of that (here made as a grid)