Advertisement
Guest User

Untitled

a guest
Nov 11th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. int i, j, n, m;
  2.  
  3. void setup()
  4. {
  5. size(500,500);
  6. n = width/20;
  7. m = height/20;
  8.  
  9. for(i=0; i<n; i++)
  10. {
  11. for(j=0; j<m; j++)
  12. {
  13. rect(i*20,j*20, 25,25);
  14. }
  15. }
  16. }
  17.  
  18. void draw()
  19. {
  20. if(mousePressed)
  21. {
  22. for(i=0; i<24; i++)
  23. {
  24. for(j=0; j<24; j++)
  25. {
  26. if(mouseInBox(i,j) == true)
  27. {
  28. drawPattern(mouseX,mouseY);
  29. }
  30. }
  31. }
  32. }
  33. //println("mouseX = " + mouseX +", mouseY = "+mouseY);
  34. }
  35.  
  36. void keyPressed()
  37. {
  38. for(i=0; i<n; i++)
  39. {
  40. for(j=0; j<m; j++)
  41. {
  42. fill(255);
  43. rect(i*20,j*20, 25,25);
  44. }
  45. }
  46. }
  47.  
  48. boolean mouseInBox(int i, int j)
  49. {
  50. if((mouseX > i*20) && (mouseX < (i+1)*20) && (mouseY > j*20) && (mouseY < (j+1)*20))
  51. {
  52. return true;
  53. }
  54. else
  55. {
  56. return false;
  57. }
  58. }
  59.  
  60. void drawPattern(int i, int j)
  61. {
  62. fill(0);
  63. rect(i, j, 20, 20);
  64. rect(i+20, j+20, 20,20);
  65. rect(i+20, j-20, 20,20);
  66. rect(i-20, j+20, 20,20);
  67. rect(i-20, j-20, 20,20);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement