hey guys. i want to locate a location on using sin,cos....
I am not good a math.
i want it to give me the cords of a given center x,y (center of circle) with location as 360deg from center as in l = 360d input at x,y
so lets say x=200, y=200,l=90 so it returns x,y position - 50pixel from center to l degrees of circle
: x = 150
:
O-----------y = 150
if any one can help thank you...
i need to be able to pick a number from the circle at any one time and have an x,y location. i send x,y,d and it returns x,y from center of x,y circle minus distance in deg.....
time = 3 ' due East degrees = 0
radius = 200
xo = _Width / 2
yo = _Height / 2
For angle = 0 To 359 Step 30
orbit xo, yo, radius, angle, x, y
_PrintString (x, y), Str$(time)
time = time + 1
If time = 13 Then time = 1
Next
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
time = 3 ' due East degrees = 0
radius = 200
xo = _Width / 2
yo = _Height / 2
angle = 0
radius = 30
While radius < 400
orbit xo, yo, radius, angle, x, y
_PrintString (x, y), Str$(time)
time = time + 1
If time = 13 Then time = 1
radius = radius + 5
angle = angle + 30
_Limit 5
Wend
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
time = 3 ' due East degrees = 0
radius = 200
xo = _Width / 2
yo = _Height / 2
For angle = 0 To 359 Step 30
orbit xo, yo, radius, angle, x, y
Circle (x, y), 10, &HFF0000FF
label x, y, _Trim$(Str$(time)) ' don't forget to remove left hand space with _trim$
time = time + 1
If time = 13 Then time = 1
Next
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
Sub label (xc, yc, text$)
th2 = _FontHeight / 2
pw2 = _PrintWidth(text$) / 2
_PrintString (xc - pw2 + 1.25, yc - th2 + .5), text$
End Sub
05-08-2024, 05:54 PM (This post was last modified: 05-08-2024, 06:01 PM by pmackay.)
instead of making data and reading it into memory i would like to use sin and cos to create the data so i can vary the size of the circle. there are three in the dimension which circloop1(x,y,show yes/no and explosion in progress status) not programed. but this is only a test so far.
SCREEN _NEWIMAGE(1366, 768, 32): DIM CIRCLOOP1(17, 3)
DIM SHARED SPRITES AS LONG
SPRITES = _LOADIMAGE("inva.png")
FOR I = 1 TO 16: READ CIRCLOOP1(I, 1), CIRCLOOP1(I, 2): NEXT I
DATA 3,1,4,1,5,1,6,2,7,3,7,4,7,5,6,6,5,7,4,7,3,7,2,6,1,5,1,4,1,3,2,2
CLS , _RGB32(&H39, &H2A, &H02)
frame = 1
RR% = 60: XX% = 8
DO
FOR I = 1 TO 16
SELECT CASE frame
CASE 1
_PUTIMAGE (CIRCLOOP1(I, 1) * 64 + RR%, CIRCLOOP1(I, 2) * 64), SPRITES, , (0, 0)-(63, 63)
CASE 2
_PUTIMAGE (CIRCLOOP1(I, 1) * 64 + RR%, CIRCLOOP1(I, 2) * 64), SPRITES, , (64, 0)-(127, 63)
END SELECT
NEXT I
_DISPLAY
CLS , _RGB32(&H39, &H2A, &H02)
_LIMIT 10
frame = frame + 1: IF frame > 2 THEN frame = 1: PLAY "T255L32O1G" ELSE PLAY "T255L32O1C"
i$ = INKEY$
RR% = RR% + XX%
IF RR% > 700 THEN XX% = -8
IF RR% < 50 THEN XX% = 8
LOOP WHILE i$ <> " "
05-08-2024, 07:57 PM (This post was last modified: 05-08-2024, 07:58 PM by bplus.)
i will explain orbit when i get some time but long story short, the last 2 variable you supply the sub come back with the x, y coordinate that want that is radius away from xo, yo origin at the degree you request.
Really no need to save data for circle coordinates, it just is extra clutter.
Screen _NewImage(1280, 720, 32)
_ScreenMove 0, 0
'Dim CIRCLOOP1(17, 3)
Dim Shared SPRITES As Long
SPRITES = _LoadImage("inva.png")
_PutImage , SPRITES, 0
_ClearColor _RGB32(&H39, &H2A, &H02), SPRITES
'For I = 1 To 16: Read CIRCLOOP1(I, 1), CIRCLOOP1(I, 2): Next I
'Data 3,1,4,1,5,1,6,2,7,3,7,4,7,5,6,6,5,7,4,7,3,7,2,6,1,5,1,4,1,3,2,2
'Cls , _RGB32(&H39, &H2A, &H02)
frame = 1
RR% = 400: XX% = 8
Do
'For I = 1 To 16
' Select Case frame
' Case 1
' _PutImage (CIRCLOOP1(I, 1) * 64 + RR%, CIRCLOOP1(I, 2) * 64), SPRITES, , (0, 0)-(63, 63)
' Case 2
' _PutImage (CIRCLOOP1(I, 1) * 64 + RR%, CIRCLOOP1(I, 2) * 64), SPRITES, , (64, 0)-(127, 63)
' End Select
'Next I
'Cls , _RGB32(&H39, &H2A, &H02)
Cls , _RGB32(0, 48, 20)
For a = 0 To 359 Step 360 / 16
orbit RR%, _Height / 2, 310, a + da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 2, y - _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 2, y - _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 220, a - da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 2, y - _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 2, y - _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
Next
_Display
_Limit 5
da = da + 2
frame = frame + 1
If frame > 2 Then frame = 1: Play "T255L32O1G" Else Play "T255L32O1C"
i$ = InKey$
RR% = RR% + XX%
If RR% > _Width - 320 Then XX% = -8
If RR% < 380 Then XX% = 8
Loop While i$ <> " "
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
05-10-2024, 02:47 AM (This post was last modified: 05-10-2024, 02:48 AM by bplus.)
oh I forgot the width of inva.png was 2 frames wide. that's why i could not repeat the pattern over and over like this:
Code: (Select All)
Screen _NewImage(1280, 720, 32)
_ScreenMove 0, 0
Dim Shared SPRITES As Long
SPRITES = _LoadImage("inva.png")
_PutImage , SPRITES, 0
_ClearColor _RGB32(&H39, &H2A, &H02), SPRITES
frame = 1
RR% = 400: XX% = 8
Do
Cls , _RGB32(0, 48, 20)
For a = 0 To 359 Step 360 / 16
orbit RR%, _Height / 2, 320, a + da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 4, y - _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 4, y - _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 240, a - da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 4, y - _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 4, y - _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 180, a + da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 8, y - _Height(SPRITES) / 4)-Step(_Width(SPRITES) / 4, _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 8, y - _Height(SPRITES) / 4)-Step(_Width(SPRITES) / 4, _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 140, a - da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 8, y - _Height(SPRITES) / 4)-Step(_Width(SPRITES) / 4, _Height(SPRITES) / 2), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 8, y - _Height(SPRITES) / 4)-Step(_Width(SPRITES) / 4, _Height(SPRITES) / 2), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 110, a + da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 90, a - da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 70, a + da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (64, 0)-(127, 63)
End Select
orbit RR%, _Height / 2, 50, a - da, x, y
Select Case frame
Case 1
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (0, 0)-(63, 63)
Case 2
_PutImage (x - _Width(SPRITES) / 16, y - _Height(SPRITES) / 8)-Step(_Width(SPRITES) / 8, _Height(SPRITES) / 4), SPRITES, , (64, 0)-(127, 63)
End Select
Next
_Display
_Limit 5
da = da + 2
frame = frame + 1
If frame > 2 Then frame = 1: Play "T255L32O1G" Else Play "T255L32O1C"
i$ = InKey$
RR% = RR% + XX%
If RR% > _Width - 320 Then XX% = -8
If RR% < 380 Then XX% = 8
Loop While i$ <> " "
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
05-10-2024, 03:13 AM (This post was last modified: 05-10-2024, 03:23 AM by bplus.)
Code: (Select All)
Sub orbit (x0rigin, yOrigin, radius, degrees, xOut, yOut) ' all default single should be ok
xOut = x0rigin + radius * Cos(_D2R(degrees))
yOut = yOrigin + radius * Sin(_D2R(degrees))
End Sub
orbit is a Sub not a Function so it returns it's results: xOut and yOut as changed inputs to the sub so the calling code can use xOut, yOut for the point that is radius away from xOrigin, yOrigin at degrees clockwise from 0 degrees that is due east.