Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sin cos using SUB SumLocate (x,y,l)
#1
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.....

hope i said it clear... almost confused myself Smile
Reply
#2
Code: (Select All)
_Title "orbit demo" ' bplus  2024-05-08
Screen _NewImage(800, 600, 32)

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

hi @pmackay ask away ;-))


Attached Files Image(s)
   
b = b + ...
Reply
#3
Code: (Select All)
_Title "orbit demo 2 spiral out" ' bplus  2024-05-08
Screen _NewImage(800, 600, 32)

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
b = b + ...
Reply
#4
probably want to use x, y output by orbit to serve as the center of a label instead of the top left corner of the text.

update:
Code: (Select All)
_Title "label demo with orbit" ' b+ 2024-05-08
Screen _NewImage(800, 600, 32)

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


Attached Files Image(s)
   
b = b + ...
Reply
#5
[Image: THEYWALK.png]

       
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$ <> " "
[Image: inva.png]

[Image: THEYWALK.png]
Reply
#6
Code: (Select All)
_Title "orbit demo" ' bplus  2024-05-08
Screen _NewImage(800, 600, 32)
a& = _LoadImage("alien.png")
time = 3 ' due East degrees = 0
radius = 200
xo = _Width / 2
yo = _Height / 2
While _KeyDown(27) = 0
    Cls
    For angle = 0 To 359 Step 30
        orbit xo, yo, radius, angle - da, x, y
        _PutImage (x - _Width(a&) / 2, y - _Height(a&) / 2), a&, 0
        orbit xo, yo, radius + 100, angle + da, x, y
        _PutImage (x - _Width(a&) / 2, y - _Height(a&) / 2), a&, 0
        orbit xo, yo, radius - 100, angle + da, x, y
        _PutImage (x - _Width(a&) / 2, y - _Height(a&) / 2), a&, 0
    Next
    _Display
    _Limit 60
    da = da + .3
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

alien.png attached


Attached Files Image(s)
   
b = b + ...
Reply
#7
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.
b = b + ...
Reply
#8
here is mod using orbit
Code: (Select All)
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

   
b = b + ...
Reply
#9
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

   
b = b + ...
Reply
#10
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

x0rigin, yOrigin.......radius
o--------------------->
.\oooooooooooooo
..\ooooooooooooo
...\ooooooooooo degrees
....\oooooooo
.....\ooooo
......vo
.......(xOut, yOut)

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.
b = b + ...
Reply




Users browsing this thread: 4 Guest(s)