Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int i, j, n, m;
- void setup()
- {
- size(500,500);
- n = width/20;
- m = height/20;
- for(i=0; i<n; i++)
- {
- for(j=0; j<m; j++)
- {
- rect(i*20,j*20, 25,25);
- }
- }
- }
- void draw()
- {
- if(mousePressed)
- {
- for(i=0; i<24; i++)
- {
- for(j=0; j<24; j++)
- {
- if(mouseInBox(i,j) == true)
- {
- drawPattern(mouseX,mouseY);
- }
- }
- }
- }
- //println("mouseX = " + mouseX +", mouseY = "+mouseY);
- }
- void keyPressed()
- {
- for(i=0; i<n; i++)
- {
- for(j=0; j<m; j++)
- {
- fill(255);
- rect(i*20,j*20, 25,25);
- }
- }
- }
- boolean mouseInBox(int i, int j)
- {
- if((mouseX > i*20) && (mouseX < (i+1)*20) && (mouseY > j*20) && (mouseY < (j+1)*20))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void drawPattern(int i, int j)
- {
- fill(0);
- rect(i, j, 20, 20);
- rect(i+20, j+20, 20,20);
- rect(i+20, j-20, 20,20);
- rect(i-20, j+20, 20,20);
- rect(i-20, j-20, 20,20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement