Advertisement
Guest User

python

a guest
Oct 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1.  
  2. maxSW = 12 # the thickest possible stroke weight
  3. sz = 1 # variable to keep track of the current stroke weight
  4.  
  5. # set up the drawing area
  6. def setup():
  7. size(400,400)
  8. background(200)
  9.  
  10. # define the draw function (always!)
  11. def draw():
  12. pass # do nothing
  13.  
  14. # when the mouse is dragged...
  15. def mouseDragged():
  16. """ Draws lines on the screen.
  17. Slower strokes are fatter and faster ones are thinner. """
  18. global sz # we will be changing the value of sz in this function, so make it global
  19.  
  20. # how far did the mouse move? (minimum of one pixel)
  21. d = max(1, dist(pmouseX, pmouseY, mouseX, mouseY))
  22.  
  23. # the stroke weight is a running average of current and previous stroke weight
  24. sz += maxSW/d
  25. sz /= 1.3
  26. strokeWeight( sz )
  27.  
  28. # draw a line between the previous and current mouse positions
  29. line(pmouseX, pmouseY, mouseX, mouseY)
  30.  
  31. # when a key is pressed...
  32. def keyPressed():
  33. """ when the delete key is pressed, clear the screen """
  34. print(keyCode)
  35. if( keyCode == 8):
  36. background(200)
  37. if(keyCode == 66):
  38. stroke(0,0,255)
  39. if(keyCode == 82):
  40. stroke(255, 10, 10)
  41. if(keyCode == 71):
  42. stroke(173,255,47)
  43. if(keyCode == 61):
  44. strokeWeight( sz )
  45. else:
  46. strokeWeight( sz - 2 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement