int sizecell = 50;
int cellnumber = 0;
void setup()
{
size(700,700);
draw_cells();
}
void draw_cells()
{
for (int i = 0; i < sizecell; i++)
{
for (int j = 0; j < sizecell; j++)
{
fill(255,255,255);
rect(i*sizecell,j*sizecell,sizecell,sizecell);
}
}
}
void compute_neighbors()
{
fill(255,0,0);
int cellnumber_x = cellnumber%50;
int cellnumber_y = cellnumber/50;
// правая
if (cellnumber_x + 1 < 50)
{
text("text",cellnumber_x*50+75,cellnumber_y*50+25);
}
//нижная
if (cellnumber_y + 1 < 50)
{
text("text",cellnumber_x*50+25,cellnumber_y*50+75);
}
// левая
if (cellnumber_x - 1 >= 0)
{
text("text",cellnumber_x*50-25,cellnumber_y*50+25);
}
// левая верхняя
if (cellnumber_x - 1 >= 0 && cellnumber_y - 1 >= 0)
{
text("text",cellnumber_x*50-25,cellnumber_y*50-25);
}
// левая нижняя
if (cellnumber_x - 1 >= 0 && cellnumber_y + 1 < 50)
{
text("text",cellnumber_x*50-25,cellnumber_y*50+75);
}
// верхняя
if (cellnumber_y - 1 >= 0)
{
text("text",cellnumber_x*50+25,cellnumber_y*50-25);
}
// правая верхняя
if (cellnumber_y - 1 >= 0 && cellnumber_x + 1 < 50)
{
text("text",cellnumber_x*50+75,cellnumber_y*50-25);
}
// правая нижняя
if (cellnumber_y + 1 < 50 && cellnumber_x + 1 < 50)
{
text("text",cellnumber_x*50+75,cellnumber_y*50+75);
}
}
void draw()
{
}
void mousePressed()
{
for (int i = 0; i < sizecell; i++)
{
for (int j = 0; j < sizecell; j++)
{
if (mouseX > i*sizecell && mouseX < i*sizecell + sizecell && mouseY > j*sizecell && mouseY < j*sizecell+sizecell )
{
fill(204, 102, 0);
cellnumber = i + j*50;
}
}
}
draw_cells();
compute_neighbors();
}
|