Advertisement
Jailout2000

Realbasic Sine/Cosine Test

Feb 7th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '// Drawing a circle using a point on a x,y coordinate plane.
  2. '// Assume Slider1.Value is your radii in degrees, and Slider1.Maximum is 360 in degrees.
  3. '// Also assume the Width/Height to be variable; in my tests, they were w=400 and h=200, giving it an oval effect.
  4.  
  5. Sub Paint(g As Graphics)
  6.  
  7.   Dim p As New Picture(g.Width, g.Height, 24)
  8.   Dim gl As Graphics
  9.   If p = Nil Then gl = g Else gl = p.Graphics
  10.  
  11.   gl.ForeColor = RGB(255, 255, 255)
  12.   gl.FillRect(0, 0, gl.Width, gl.Height)
  13.  
  14.   Dim x, y As Double
  15.   Dim pi As Double = 3.1415926535897932384626433832795
  16.  
  17.   '// note that pi is not a constant, but is rather a variable... RealBasic does
  18.  '// have some limitations, and this helps with using the pi value below:
  19.  
  20.   x = Cos(Slider1.Value / Slider1.Maximum * 2 * pi) * gl.Width / 2 + gl.Width / 2
  21.   y = Sin(Slider1.Value / Slider1.Maximum * 2 * pi) * gl.Height / 2 + gl.Height / 2
  22.  
  23.   x = Round(x)
  24.   y = Round(y)
  25.  
  26.   gl.ForeColor = RGB(0, 0, 0)
  27.   gl.FillOval(x - 2, y - 2, 5, 5) '// draws the point on our x,y plane for this radius
  28.  
  29.   '// Chr(176) as used below is the degree sign on the Unicode character map
  30.  gl.DrawString("r=" + Str(Slider1.Value / Slider1.Maximum * 2 * pi) + EndOfLine _
  31.   + "r=" + Str(Slider1.Value / Slider1.Maximum * 360) + Chr(176), gl.Width / 2, gl.Height / 2)
  32.  
  33.   If p <> Nil Then g.DrawPicture(p, 0, 0)
  34.  
  35. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement