Advertisement
Audiation

Sine/Cosine Visualizer

Aug 2nd, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Sine, Cosine Visualizer by TheBaykun.
  2.  
  3. Speed = 0.03 'Lower number: faster.
  4. RETINA off
  5.  
  6. ' Tap and hold screen to pause.
  7.  
  8. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  9.  
  10. BCOLOR 200,255,200
  11. TCOLOR 255,0,0
  12.  
  13. sw=ScreenWidth
  14. sh=ScreenHeight
  15.  
  16. SLEEP 0.1
  17.  
  18. DIM wave(20),waveB(20)
  19. FOR i=1 TO 20
  20.     wave(i)=sh/2
  21.     waveB(i)=sh/2
  22. NEXT
  23.  
  24. SLEEP 0.1
  25.  
  26. COLOR 0,0,0
  27. CIRCLE 30,sh/2,25,3
  28.  
  29. LINE 60,(sh/2)-28,sw-60,(sh/2)-28,3
  30. LINE 60,(sh/2)+28,sw-60,(sh/2)+28,3
  31.  
  32. LINE sw-30,(sh/2)-25,sw-30,(sh/2)+25,3
  33. LINE sw-55,(sh/2),sw-5,(sh/2),3
  34.  
  35. x=55
  36. y=(sh/2)
  37. a=30
  38. b=(sh/2)-25
  39.  
  40. q=0 'Sine angle (red)
  41. w=90 'Cosine angle (blue)
  42.  
  43. p=1
  44. WHILE p=1
  45.     BEGINDRAW
  46.     CLS
  47.     q=q+1
  48.     w=w+1
  49.     IF q>359 THEN
  50.         q=0
  51.     ENDIF
  52.     IF w>359 THEN
  53.         w=0
  54.     ENDIF
  55.     x=30+(25*SIN(q))
  56.     y=(sh/2)+(25*COS(q))
  57.     a=30+(25*SIN(w))
  58.     b=(sh/2)+(25*COS(w))
  59.     GOSUB drawCircle
  60.     GOSUB drawWave
  61.     GOSUB drawCross
  62.     SLEEP speed
  63.     IF q>=267 THEN
  64.         PRINT "Sorry, the math is not accurate."
  65.         PRINT "It will automatically fix itself"
  66.         PRINT "in",1+INT((360-q)/10),"..."
  67.     ENDIF
  68.     WHILE Touch>0
  69.     WEND      
  70.     ENDDRAW
  71. WEND
  72.  
  73. drawCircle:
  74. COLOR 0,0,0
  75. CIRCLE 30,sh/2,25,3
  76. COLOR 255,0,0
  77. CIRCLE x,y,2
  78. COLOR 0,0,255
  79. CIRCLE a,b,2
  80. RETURN
  81.  
  82. drawWave:
  83. GOSUB updateWave
  84. COLOR 0,0,0
  85. LINE 60,(sh/2)-28,sw-60,(sh/2)-28,3
  86. LINE 60,(sh/2)+28,sw-60,(sh/2)+28,3
  87. FOR i=1 TO 19
  88.     COLOR 255,0,0
  89.     LINE (60-((sw-60)/25))+((sw-60)/25)*i,wave(i),(60-((sw-60)/25))+((sw-60)/25)*(i+1),wave(i+1)
  90.     COLOR 0,0,255
  91.     LINE (60-((sw-60)/25))+((sw-60)/25)*i,waveB(i),(60-((sw-60)/25))+((sw-60)/25)*(i+1),waveB(i+1)
  92. NEXT
  93. RETURN
  94.  
  95. drawCross:
  96. COLOR 0,0,0
  97. LINE sw-30,(sh/2)-25,sw-30,(sh/2)+25,3
  98. LINE sw-55,(sh/2),sw-5,(sh/2),3
  99. COLOR 255,0,0
  100. CIRCLE sw-30,y,2
  101. CIRCLE (x-30)+(sw-30),sh/2,2
  102. COLOR 0,0,255
  103. CIRCLE sw-30,b,2
  104. CIRCLE (a-30)+(sw-30),sh/2,2
  105. RETURN
  106.  
  107. updateWave:
  108. FOR i=19 TO 1 STEP -1
  109.     wave(i+1)=wave(i)
  110.     waveB(i+1)=waveB(i)
  111. NEXT
  112. wave(1)=y
  113. waveB(1)=b
  114. RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement