We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there! I'm currently doing an assignment and for this I need to create a 6x6 grid, and then display a random shape (either a rectangle, circle, oval or square) in each grid space once it is clicked on by the mouse. However, I'm not quite sure how to make the shapes random, specifically how to store the shapes, I'm assuming it has something to do with an array, but I'm not confident. The code I have below is very roughly what I've been able to gather so far but doesn't work. Please help :)
interface Shape
{
void draw();
}
Shape [] shapes;
int numShapes=4;
void setup(){
size(400,400);
shapes = new Shape [numShapes];
shapes [0]= new rect(x,y,width/12.0,height/12.0);
}
Answers
have you been told to use interface?
Make
void draw() {}
A function first.
Then do the grid
When you only need to draw the grid to once, just ise noLoop() and draw one item depending on int typeShape=int(random (4));
Then later read the tutorial two dimensional arrays to store this if you must
No we don't have to use interface
this won't work because rect is not an object, it's a method
currently* you only need an array of integers, then fill it with numbers from 0 to 4. these will denote your shapes. 0 for nothing, 1 for a rectangle, 2 for a circle etc. then, in draw, look up what shape you have and draw that object (using a simple switch statement)