Storing shapes in an array
in
Programming Questions
•
2 years ago
I woud like to store a shape I have drawn in a class into an array, so later when it comes to drawing them (having them fill the screen) I don't have to go out and keep declaring a "bah1... 2... 3... 4... ect = new blah" but I'm not sure how to go about storing the 'shape' in an array. I think I might just be having a mental block atm, but here is my class:
class dangerBlock
{
float reda = 0;
float redb = 0;
float redValue;
float greenValue;
dangerBlock()
{
for (int i = 0; i < block.length; i++)
{
block[i] = drawBlock;
}
}
void colourChange()
{
float r = random(.009, .1);
reda = reda + r;
redb = cos (reda);
redValue = redb;
greenValue = redb;
redValue = map (redValue, -1, 1, 0, 255);
greenValue = map (greenValue, 1, -1, 0, 255);
}
void drawBlock()
{
colourChange();
rectMode (RADIUS);
fill(redValue, greenValue, 0);
rect(0, 0, 25, 25);
}
}
{
float reda = 0;
float redb = 0;
float redValue;
float greenValue;
dangerBlock()
{
for (int i = 0; i < block.length; i++)
{
block[i] = drawBlock;
}
}
void colourChange()
{
float r = random(.009, .1);
reda = reda + r;
redb = cos (reda);
redValue = redb;
greenValue = redb;
redValue = map (redValue, -1, 1, 0, 255);
greenValue = map (greenValue, 1, -1, 0, 255);
}
void drawBlock()
{
colourChange();
rectMode (RADIUS);
fill(redValue, greenValue, 0);
rect(0, 0, 25, 25);
}
}
as I have said, the idea is to now store it so later I can just use a for loop and translate it to cover the screen, cheers.
1