Sure, here we are, t3h c0d3z for everyone!
The example makes a circle with the origin at the center of the screen. It then draws a line from the origin, to the cursors location. If the cursor is outside the circle, the line is halted on the line edge.
Cool notes: includes pythagoreans distance code, and finds the angle between two points using ATanFull(distanceX, distanceY)
`This program will create a circle with the center at the center of the screen, then draw a line with one
`point in the center of the screen, and the other at the cursors location. If the location of the cursor is
`OUTSIDE the circle, the line will STOP at the edge of the circle.
`Make some needed variables
winWidth = Screen Width()
winHeight = Screen Height()
radius = winWidth/4
Do
Cls
`Draw circle
Circle winWidth/2, winHeight/2, radius
`Draw the line
angle# = ATanFull(MouseX()-winWidth/2, MouseY()-WinHeight/2)-90 `Get the angle between the point of the cursor and the origin
distanceBetweenPoints = Sqrt((MouseX()-winWidth/2)^2 + (MouseY()-WinHeight/2)^2) `Use pythagoreans theorom to find distance
`Decide if the cursor is inside the circle or not. If it is, only draw the line to the cursor, not to the edge of the circle
If distanceBetweenPoints <= radius
x = winWidth/2 + Cos(angle#)*distanceBetweenPoints `Multiply by the distance. This gives us a length of the distance, which is what we want
y = winHeight/2 + Sin(angle#)*distanceBetweenPoints*-1 `Same here as above
Else
x = winWidth/2 + Cos(angle#)*radius `Multiply by the radius. This gives us a length of the radius, which is what we want
y = winHeight/2 + Sin(angle#)*radius*-1 `Same here as above
EndIf
Line winWidth/2, winHeight/2, x, y
`note: I mulitpilied Sin by -1, and subtracted 90 from the angle# to get the cursor to be in FRONT of the line
Loop
This sample creates a circle at the center of the screen. It then randomly generates 1000 dots INSIDE the circle each frame. Try it out, if you don't understand whats going on, try switching a few values.
`This program will create a circle with the center at the center of the screen, then randomly draw dots inside the circle
`Perform necessary setup stuff
Randomize Timer()
Sync On : Sync Rate 60
`Make some needed variables
winWidth = Screen Width()
winHeight = Screen Height()
radius = winWidth/4
Do
Cls
`Draw circle
Circle winWidth/2, winHeight/2, radius
`Draw a dot
For i =1 To 1000
angle = Rnd(359) `Don't randomize 360, as this really equals 0 degrees, so meh
x = winWidth/2 + Cos(angle)*Rnd(radius)
y = winHeight/2 + Sin(angle)*Rnd(radius)
Dot x, y
Next i
`FUN FACT: Try randomizeing two angles, the first to be inputted in the Cos command,
`and the second to go inside the Sin command. You will see that it actually draws within a square. meh.
Sync
Loop
This example is the same as the last one, only the circle will slowly grow, but the code will function normally. The same technique could be applied to the first example easily
`This program will create a circle with the center at the center of the screen, then randomly draw dots inside the circle
`Also, every 500 ms the circle will grow by one pixel. This is acheived by simply incrementing the radius variable every
`500 ms.
`Perform necessary setup stuff
Randomize Timer()
Sync On : Sync Rate 60
`Make some needed variables
winWidth = Screen Width()
winHeight = Screen Height()
radius = winWidth/4
Do
Cls
`Grow the radius of the circle one pixel every 500 millisecons
If Timer() >= growTime#
Inc radius
growTime# = Timer()+500.0
EndIf
`Draw circle
Circle winWidth/2, winHeight/2, radius
`Draw a dot
For i =1 To 1000
angle = Rnd(359) `Don't randomize 360, as this really equals 0 degrees, so meh
x = winWidth/2 + Cos(angle)*Rnd(radius)
y = winHeight/2 + Sin(angle)*Rnd(radius)
Dot x, y
Next i
`HELPFUL HINT: Try randomizeing two angles, the first to be inputted in the Cos command,
`and the second to go inside the Sin command. You will see that it actually draws within a square. meh.
Sync
Loop
EDIT: Forgot to give a general apology for my lacking Trig. I just started class two days ago, and am LOVING it!! It's a gamers dream really... That and Physics.
Mountain Dew, happyness in a bottle.