int matrix[][] = new int[11][11];
int rcolor = 0;
int Stop()
{
int counter = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (matrix[i][j] == 1) counter++;
}
}
return counter;
}
boolean GetField(int x,int y)
{
if (matrix[x][y] == 1) return true;
return false;
}
void SetFour()
{
int vertical = 0;
int horizontal = 0;
while (true)
{
vertical = (int)random(0,10);
horizontal = (int)random(0,10);
if (!GetField(vertical,horizontal)) break;
if (Stop() == 100) break;
}
matrix[vertical][horizontal] = 1;
}
void setup()
{
size(600,600);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
matrix[i][j] = 0;
}
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
fill(255,255,255);
rect(i*50,j*50,50,50);
}
}
}
void draw()
{
fill(204, rcolor, 0);
rect(150,550,250,50);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (matrix[i][j] == 1) rect(i*50,j*50,50,50);
}
}
}
void mousePressed()
{
SetFour();
if (mouseX > 150 && mouseX < 400 && mouseY > 550 && mouseY < 600 )
{
rcolor = (int)random(255);
fill(204, rcolor, 0);
rect(150,550,250,50);
}
}
|