Author Topic: Networking with the Stars  (Read 17006 times)

B+

  • Guest
Networking with the Stars
« on: November 13, 2018, 07:05:09 PM »
Code: [Select]
_TITLE "Networking 1 translation" 'by B+ started 2018-11-13

' networking.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-14
' 2017-04-16 modified for new array method for drawpoly
'            plus needed to check another distance!!!
'2018-11-12 add star background and alpha coloring

CONST xmax = 800
CONST ymax = 600
CONST nP = 85
CONST rD = 100

SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 80, 20

TYPE point
    x AS SINGLE
    y AS SINGLE
    dx AS SINGLE
    dy AS SINGLE
    c AS _UNSIGNED LONG
END TYPE
DIM p(nP) AS point

'initialize points
FOR i = 0 TO nP
    p(i).x = rand(0, xmax)
    p(i).y = rand(0, ymax)
    p(i).dx = rdir * (RND * 3 + .5)
    p(i).dy = rdir * (RND * 2 + .5)
    p(i).c = _RGBA32(rand(64, 255), rand(64, 255), rand(64, 255), 40)
NEXT
stars& = _LOADIMAGE("stars.png")
WHILE 1
    'if inkey = " " then cls
    _SOURCE stars&
    _DEST 0
    _PUTIMAGE
    FOR i = 0 TO nP 'big show of points and triangle
        COLOR p(i).c
        LINE (p(i).x, p(i).y)-STEP(2, 2), p(i).c, BF
        FOR j = i + 1 TO nP 'search for triangle points within 100 pixels
            IF distance(p(i).x, p(i).y, p(j).x, p(j).y) < rD THEN
                FOR k = j + 1 TO nP
                    IF distance(p(k).x, p(k).y, p(j).x, p(j).y) < rD THEN
                        IF distance(p(k).x, p(k).y, p(i).x, p(i).y) < rD THEN
                            'draw 3 lines of triangle
                            LINE (p(i).x, p(i).y)-(p(j).x, p(j).y), p(i).c
                            LINE (p(k).x, p(k).y)-(p(j).x, p(j).y), p(i).c
                            LINE (p(i).x, p(i).y)-(p(k).x, p(k).y), p(i).c
                        END IF
                    END IF
                NEXT
            END IF
        NEXT
        'update points
        p(i).x = p(i).x + p(i).dx
        p(i).y = p(i).y + p(i).dy
        IF p(i).x < 0 THEN p(i).x = xmax + p(i).x
        IF p(i).x > xmax THEN p(i).x = p(i).x - xmax
        IF p(i).y < 0 THEN p(i).y = 0: p(i).dy = p(i).dy * -1
        IF p(i).y > ymax THEN p(i).y = ymax: p(i).dy = p(i).dy * -1
    NEXT
    _DISPLAY
    _LIMIT 30
WEND

FUNCTION rand& (lo, hi)
    rand& = (RND * (hi - lo + 1)) \ 1 + lo
END FUNCTION

FUNCTION rdir%
    IF RND < .5 THEN rdir% = -1 ELSE rdir% = 1
END FUNCTION

FUNCTION distance (x1, y1, x2, y2)
    distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
END FUNCTION


Thanks to Johnno for the image used for background.
« Last Edit: November 13, 2018, 07:08:34 PM by B+ »

B+

  • Guest
Re: Networking with the Stars
« Reply #1 on: November 17, 2018, 01:23:15 PM »
Dark Matter discovered:

B+

  • Guest
Re: Networking with the Stars
« Reply #2 on: November 17, 2018, 01:26:45 PM »
Networking on Mars:

B+

  • Guest
Re: Networking with the Stars
« Reply #3 on: November 17, 2018, 01:31:03 PM »
Preparing for Mars:

Rick3137

  • Guest
Re: Networking with the Stars
« Reply #4 on: November 17, 2018, 04:17:59 PM »

 Cool stuff. All you need now is a star gate. 8)

B+

  • Guest
Re: Networking with the Stars
« Reply #5 on: November 17, 2018, 06:58:08 PM »

 Cool stuff. All you need now is a star gate. 8)

Thanks Rick, you know, we are both sitting before the Star Gate! You just need to know the code. ;-))

Nice to hear from you. :)

B+

  • Guest
Re: Networking with the Stars
« Reply #6 on: November 28, 2018, 04:42:23 PM »
Ho! Look who's coming!

Rick3137

  • Guest
Re: Networking with the Stars
« Reply #7 on: November 29, 2018, 01:51:40 PM »
  Just when we thought it was safe to use the fire place...