Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. t = 0
  2. v = 0
  3.  
  4. setup do
  5. title "Ballerina"
  6. smoothing true
  7. framerate 60
  8. end
  9.  
  10. update do
  11. v += 0.005
  12. t = sin(v)*100
  13. end
  14.  
  15. def trig w, n
  16. sin(2*n+w*0.05)*40*sin(n/50.0)
  17. end
  18.  
  19. draw do
  20. color 240
  21.  
  22. near = []
  23. far = []
  24.  
  25. # determine x's
  26. 158.times do |n|
  27. x = trig(t, n)
  28. nx = trig(t+1, n)
  29. p = x.abs/(40*sin(n/50.0))
  30. p = 0.0 if p.nan?
  31.  
  32. # determine color and size
  33. if nx > x
  34. # far
  35. c = 64 * (1-p) + 200*p
  36. r = 0.5 + 0.5 * p
  37.  
  38. far << [x, n-160/2, r, c]
  39. else
  40. # near
  41. c = 240 * (1-p) + 200*p
  42. r = 1.5 - 0.5 * p
  43.  
  44. near << [x, n-160/2, r, c]
  45. end
  46. end
  47.  
  48. # draw points
  49. matrix do
  50. translate width/2, height/2
  51. scale width/180.0, height/180.0
  52. rotate 15
  53.  
  54. far.each do |point|
  55. x, y, r, c = point
  56. color c
  57. circle x, y, r
  58. end
  59. near.each do |point|
  60. x, y, r, c = point
  61. color c
  62. circle x, y, r
  63. end
  64. end
  65. end
Add Comment
Please, Sign In to add comment