Answer the question
In order to leave comments, you need to log in
How to split a canvas into paintable segments in Processing?
I have been studying the Processing environment for half a year, but recently I stalled on one task: to write a program that divides the canvas into equal cells, on which you can draw.
Below is a program that "pixel by pixel" determines where the mouse is.
int r = 25; // Размер пикселя, на который будем делить холст
void setup() {
size(251,251);
noStroke();
cursor(CROSS);
}
void draw() {
background(255);
for(int x = 0; x<width; x+=r) { // Для каждого r(эр)-ного х...
for(int y = 0; y<height; y+=r) { // ...рисуем столбец квадратов
if((mouseX>x)&&(mouseX<x+r)&&(mouseY>y)&&(mouseY<y+r)) // Проверка на то, находится ли мышь внутри квадрата
{ fill(255,0,0); } // И, в соответствии с результатом выше, закрашиваем квадраты в красный...
else { fill(255); } // ...или белый
rect(x,y,r,r);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question