dentonpotter

Processing draw shapes and lines

Aug 9th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /*
  2. * Creative Coding
  3. * Week 1, 03 - Draw your name! (part 3)
  4. * by Indae Hwang and Jon McCormack
  5. * Copyright (c) 2014 Monash University
  6. * Modifications CC-BY Karen Cropper August 2015
  7.  
  8. * This program allows you to draw using the mouse.
  9. * Press 's' to save your drawing as an image.
  10. * Press 'r' to erase all your drawing and start with a blank screen
  11. *
  12. */
  13.  
  14. // variables to store the delay and target counts
  15. int delayCount;
  16. int targetCount;
  17.  
  18. // setup function
  19. void setup() {
  20. size(1200, 675); //altered canvas size from 500,500
  21. background(255); //altered background colour from white 255
  22.  
  23. delayCount = 0; //initialising variable
  24. targetCount = (int) random(5, 50); // set target count to a random integer between 5 and 50
  25. }
  26.  
  27. // draw function
  28. void draw() {
  29.  
  30. /* draw a rectangle on your mouse point while you pressing
  31. the left mouse button*/
  32.  
  33. int style; // defining a variable for style
  34.  
  35. delayCount++; // increment delay count (shorthand for delayCount = delayCount + 1)
  36.  
  37. // changes style if the two variables are equal - random between 0 and 4
  38. if (delayCount == targetCount) {
  39. style = (int) random(4);
  40. targetCount = (int) random(3, 10) ; // random number between 5 and 20 as an integer
  41. delayCount = 0;
  42. }
  43. else {
  44. style = 0;
  45. }
  46.  
  47.  
  48. if (mousePressed) {
  49.  
  50. // to create random colors
  51. int iRed;
  52. int iGreen;
  53. int iBlue;
  54. int iTrans;
  55.  
  56. iRed = (int) random(255);
  57. iGreen = (int) random(255);
  58. iBlue = (int) random(255);
  59. iTrans = (int) random(100, 255);
  60.  
  61. stroke(iRed, iBlue, iGreen); // started as black (0)
  62. fill(iRed, iBlue, iGreen, iTrans); //started as black (0)
  63.  
  64. // switch statement defining the styles for each random number
  65. switch(style) {
  66. case 0:
  67. // draw a point
  68. strokeWeight(5); // added to see line better
  69. point(mouseX, mouseY);
  70. break;
  71.  
  72. case 1:
  73. // draw a circle with random radius
  74. strokeWeight(2); // added to see line better
  75. float esize = random(4, 40); // started at 1, 20
  76. ellipse(mouseX, mouseY, esize, esize);
  77. break;
  78.  
  79. case 2:
  80. // draw a random sized rectangle
  81. strokeWeight(2); // added to see line better
  82. float qsize = random(1, 20); //started at 1, 10
  83. quad(mouseX-qsize, mouseY, mouseX, mouseY-qsize, mouseX+qsize, mouseY, mouseX, mouseY+qsize );
  84. break;
  85.  
  86. case 3:
  87. // draw a triangle with random size
  88. strokeWeight(2); // added to see line better
  89. float tsize = random(1, 10); //started at 1, 5
  90. triangle(mouseX-tsize, mouseY+tsize, mouseX, mouseY-tsize, mouseX+tsize, mouseY+tsize);
  91. break;
  92. } // end of switch statement
  93. }
  94.  
  95.  
  96. // save your drawing when you press keyboard 's'
  97. if (keyPressed == true && key=='s') {
  98. saveFrame("artwork.png");
  99. }
  100.  
  101. // erase your drawing when you press keyboard 'r'
  102. if (keyPressed == true && key == 'r') {
  103. background(255);
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment