Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '// Drawing a circle using a point on a x,y coordinate plane.
- '// Assume Slider1.Value is your radii in degrees, and Slider1.Maximum is 360 in degrees.
- '// Also assume the Width/Height to be variable; in my tests, they were w=400 and h=200, giving it an oval effect.
- Sub Paint(g As Graphics)
- Dim p As New Picture(g.Width, g.Height, 24)
- Dim gl As Graphics
- If p = Nil Then gl = g Else gl = p.Graphics
- gl.ForeColor = RGB(255, 255, 255)
- gl.FillRect(0, 0, gl.Width, gl.Height)
- Dim x, y As Double
- Dim pi As Double = 3.1415926535897932384626433832795
- '// note that pi is not a constant, but is rather a variable... RealBasic does
- '// have some limitations, and this helps with using the pi value below:
- x = Cos(Slider1.Value / Slider1.Maximum * 2 * pi) * gl.Width / 2 + gl.Width / 2
- y = Sin(Slider1.Value / Slider1.Maximum * 2 * pi) * gl.Height / 2 + gl.Height / 2
- x = Round(x)
- y = Round(y)
- gl.ForeColor = RGB(0, 0, 0)
- gl.FillOval(x - 2, y - 2, 5, 5) '// draws the point on our x,y plane for this radius
- '// Chr(176) as used below is the degree sign on the Unicode character map
- gl.DrawString("r=" + Str(Slider1.Value / Slider1.Maximum * 2 * pi) + EndOfLine _
- + "r=" + Str(Slider1.Value / Slider1.Maximum * 360) + Chr(176), gl.Width / 2, gl.Height / 2)
- If p <> Nil Then g.DrawPicture(p, 0, 0)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement