Changing objects into arrays?
in
Programming Questions
•
7 months ago
Hey folks,
I'm a very new programmer at the end of my intro programming course. My project is creating a guitar tuner in Processing that uses a lot of objects in specific places. I've posted an excerpt that includes the ellipse class and all the object stuff to give you an idea of what I'm doing.
My professor suggested using arrays to shorten my overall code. I've used arrays before, and used one in my complete sketch to load sounds for minim.
Arrays seem to be really non-user friendly for someone not good at programming, haha, unless you are a mathematician and use complex multiplication and division in a for loop!
Still, I'm dedicated to at least attempting to shorten my code if I can. Below is an example of some of my code and I'm really curious to see how I can make it more efficient!
//Guitar Body Variables:
Ellipses BigGuitarCircle; //Big Guitar Circle
Ellipses SmallGuitarCircle; //Small Guitar Circle
Ellipses SoundHole; //Guitar Sound Hole
void setup() {
size(1000,700);
//Guitar Body Setups:
BigGuitarCircle = new Ellipses(200,485,350,310); //Big guitar circle
SmallGuitarCircle = new Ellipses(400,390,280,280); //Small guitar circle
SoundHole = new Ellipses(320,430,170,170); // Guitar sound hole
}
void draw() {
smooth();
background(#9E9E9E);
//Guitar Body Draws:
BigGuitarCircle.bodyEllipses(); //Big Guitar Circle
SmallGuitarCircle.bodyEllipses(); //Small Guitar Circle
SoundHole.bodyEllipses(); // Guitar Sound Hole
}
//Ellipse Class:
class Ellipses {
int x;
int y;
int width;
int height;
Ellipses(int tempX,int tempY,int tempWidth, int tempHeight) {
x = tempX;
y = tempY;
width = tempWidth;
height = tempHeight;
}
void shadowEllipses() {
noStroke();
fill(0);
ellipse(x,y,width,height);
}
void bodyEllipses() {
strokeWeight(5);
if ((width<=170) || (height<=170)) {
fill(#644133);
stroke(0);
}else{
fill(#D3CE6B);
stroke(#E5E4C9);
}
ellipse(x,y,width,height);
}
}
I'm a very new programmer at the end of my intro programming course. My project is creating a guitar tuner in Processing that uses a lot of objects in specific places. I've posted an excerpt that includes the ellipse class and all the object stuff to give you an idea of what I'm doing.
My professor suggested using arrays to shorten my overall code. I've used arrays before, and used one in my complete sketch to load sounds for minim.
Arrays seem to be really non-user friendly for someone not good at programming, haha, unless you are a mathematician and use complex multiplication and division in a for loop!
Still, I'm dedicated to at least attempting to shorten my code if I can. Below is an example of some of my code and I'm really curious to see how I can make it more efficient!
//Guitar Body Variables:
Ellipses BigGuitarCircle; //Big Guitar Circle
Ellipses SmallGuitarCircle; //Small Guitar Circle
Ellipses SoundHole; //Guitar Sound Hole
void setup() {
size(1000,700);
//Guitar Body Setups:
BigGuitarCircle = new Ellipses(200,485,350,310); //Big guitar circle
SmallGuitarCircle = new Ellipses(400,390,280,280); //Small guitar circle
SoundHole = new Ellipses(320,430,170,170); // Guitar sound hole
}
void draw() {
smooth();
background(#9E9E9E);
//Guitar Body Draws:
BigGuitarCircle.bodyEllipses(); //Big Guitar Circle
SmallGuitarCircle.bodyEllipses(); //Small Guitar Circle
SoundHole.bodyEllipses(); // Guitar Sound Hole
}
//Ellipse Class:
class Ellipses {
int x;
int y;
int width;
int height;
Ellipses(int tempX,int tempY,int tempWidth, int tempHeight) {
x = tempX;
y = tempY;
width = tempWidth;
height = tempHeight;
}
void shadowEllipses() {
noStroke();
fill(0);
ellipse(x,y,width,height);
}
void bodyEllipses() {
strokeWeight(5);
if ((width<=170) || (height<=170)) {
fill(#644133);
stroke(0);
}else{
fill(#D3CE6B);
stroke(#E5E4C9);
}
ellipse(x,y,width,height);
}
}
1