Traveller Store CotI Features New Posts Mark Forums Read Register


Go Back TravellerRPG.com > Citizens of the Imperium > General Traveller Discussions > Software Solutions

Software Solutions Discussions on Traveller related software.

Reply
 
Thread Tools Display Modes
  #1  
Old August 11th, 2019, 03:00 PM
AndyW AndyW is offline
Citizen: SOC-9
 
Join Date: Jun 2019
Posts: 45
Gallery : 0
AndyW Citizen
Default How to incapacitate a Trekkie

Thought I'd share some otherwise useless eye candy for QB64 users.

Code:
_TITLE "OldMoses' 3D StarField (+ & - speed) (left/right arrows turn)"

a& = _NEWIMAGE(600, 600, 32)
SCREEN a&
DO: LOOP UNTIL _SCREENEXISTS
_SCREENMOVE 50, 50
TYPE star '                                                     define the star data type
    x AS INTEGER
    y AS INTEGER
    z AS INTEGER
    r AS INTEGER
    g AS INTEGER
    b AS INTEGER
    xa AS INTEGER
    ya AS INTEGER
END TYPE

DIM SHARED max AS INTEGER: max = 500
DIM SHARED vprt AS INTEGER: vprt = 600 '                        set the viewport setback from viewer's eye
DIM SHARED p(max) AS star '                                     dimension the star data array
DIM SHARED speed AS INTEGER: speed = 2 '                        warp factor
DIM SHARED xch AS _BYTE
DIM SHARED ych AS _BYTE

PopVoid '                                                       OldMoses said "Let there be light" and the universe was, is and ever shall be
WINDOW (-300, 300)-(300, -300) '                                create viewport window, Cap'n Kirk spends his days staring at this

DO '                                                            draw the stars
    x$ = INKEY$
    IF x$ = "" THEN
        xch = 0: ych = 0
    END IF
    IF x$ = CHR$(43) THEN speed = speed + 1
    IF x$ = CHR$(45) THEN speed = speed - 1
    IF x$ = CHR$(0) + CHR$(75) THEN xch = 1
    IF x$ = CHR$(0) + CHR$(77) THEN xch = -1
    'IF x$ = CHR$(0) + CHR$(72) THEN ych = 1
    'IF x$ = CHR$(0) + CHR$(80) THEN ych = -1
    CLS
    FOR x = 1 TO max '                                          iterate through all stars
        dst = Pythagorus(p(x)) '                                distance to star
        p(x).x = p(x).x + SinCalc(p(x).z, xch * 0.3)
        'p(x).y = p(x).y + CosCalc(p(x).z, ych * 0.3) '          <<<this just doesn't work
        p(x).xa = p(x).x / dst * vprt '                         get relative screen position from absolute position for x & y
        p(x).ya = p(x).y / dst * vprt
        IF ABS(p(x).xa) < 301 AND ABS(p(x).ya) < 301 THEN '     place the star if within the viewport
            fdf& = (dst - 12952) / 8
            IF fdf& < 0 THEN fdf& = 0
            SELECT CASE dst
                CASE IS > 7500
                    PSET (p(x).xa, p(x).ya), _RGBA32(p(x).r, p(x).g, p(x).b, 255 - fdf&)
                CASE ELSE
                    FCirc p(x).xa, p(x).ya, 1, _RGBA32(p(x).r, p(x).g, p(x).b, 255)
            END SELECT
        END IF
        p(x).z = p(x).z - speed '                               move the star closer to the viewer
        IF speed < 0 THEN
            IF p(x).z > 15000 THEN ReplaceStar x, 0
        ELSE
            IF p(x).z < 0 THEN ReplaceStar x, 15000 '                      add new stars as existing ones go behind the viewer
        END IF
    NEXT x
    _DISPLAY '                                                  eliminate screen flicker
    _LIMIT 500 '                                                smooth out the action
LOOP UNTIL _KEYDOWN(27)


SUB PopVoid '                                                   Do an initial population of stars

    FOR x = 1 TO max '                                          place a 'max' # of stars randomly in a 3D space
        RANDOMIZE TIMER
        p(x).x = INT(RND * 15000) - 7500
        p(x).y = INT(RND * 15000) - 7500
        p(x).z = INT(RND * 15000) + 1
        t% = INT(RND * 110) - 55
        ch = INT(RND * 6)
        IF ch < 4 THEN
            p(x).r = 200 + t%: p(x).b = 200 - t%
        ELSE
            p(x).r = 200 - t%: p(x).b = 200 + t%
        END IF
        p(x).g = 200
    NEXT x

END SUB 'PopVoid


FUNCTION Pythagorus (var1 AS star)

    horizontal = _HYPOT(ABS(var1.x), ABS(var1.y)) '             Use to find distance between star and origin (viewer)
    Pythagorus = _HYPOT(horizontal, ABS(var1.z))

END FUNCTION 'Pythagorus


SUB ReplaceStar (var AS INTEGER, insert AS INTEGER) '                              This replaces any star that goes behind the viewer

    RANDOMIZE TIMER
    p(var).x = INT(RND * 15000) - 7500 '                        New x,y,z but keep old color for simplicity sake
    p(var).y = INT(RND * 15000) - 7500
    p(var).z = insert

END SUB 'ReplaceStar

FUNCTION SinCalc (var1 AS _INTEGER64, var2 AS SINGLE)

    'Polar coordinate X finder
    'used to find X coordinate of a speed/distance (var1) and heading/azimuth (var2)
    SinCalc = var1 * SIN(_D2R(var2))

END FUNCTION 'SinCalc


FUNCTION CosCalc (var1 AS _INTEGER64, var2 AS SINGLE)

    'Polar coordinate Y finder
    'used to find Y coordinate of a speed/distance (var1) and heading/azimuth (var2)
    CosCalc = var1 * COS(_D2R(var2))

END FUNCTION 'CosCalc


SUB FCirc (CX AS INTEGER, CY AS INTEGER, RR AS INTEGER, C AS _UNSIGNED LONG)
    DIM R AS INTEGER, RError AS INTEGER
    DIM X AS INTEGER, Y AS INTEGER

    R = ABS(RR)
    RError = -R
    X = R
    Y = 0
    IF R = 0 THEN PSET (CX, CY), C: EXIT SUB
    LINE (CX - X, CY)-(CX + X, CY), C, BF
    WHILE X > Y
        RError = RError + Y * 2 + 1
        IF RError >= 0 THEN
            IF X <> Y + 1 THEN
                LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            END IF
            X = X - 1
            RError = RError - X * 2
        END IF
        Y = Y + 1
        LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    WEND
END SUB 'FCirc

Last edited by AndyW; August 11th, 2019 at 04:31 PM..
Reply With Quote
  #2  
Old August 11th, 2019, 04:02 PM
aramis's Avatar
aramis aramis is offline
Administrator
 
Join Date: May 2001
Location: Anchorage, AK, USofA
Posts: 29,297
Gallery : 53
Visit aramis's Blog
aramis has disabled reputation
Send a message via ICQ to aramis Send a message via AIM to aramis Send a message via Yahoo to aramis
Default

Nice...
__________________
~ Aramis
aramis.hostman.us /trav
Smith & Wesson: The Original Point and Click interface!

Archduke of Sylea (CORE 2118)
Duke of the Third Imperium (SPIN 0534)
Count Terra (SOLO 1827)
Count Gorod (REFT 1302)
Count of the Third Imperium (SPIN 2232)
Viscount of Adabicci (SPIN 1824)
Marquis of the Solomani Rim (SOLO 0606)
Marquis of the Third Imperium (SPIN 2410)
Baron of the Third Imperium (SPIN 2231)
Knight of the Iridium Throne (CORE 1434)
Sir William Hostman (OLDE 0512)
Sir William Hostman (DAGU 0622)
Knight of Deneb (REFT 2239)
Knight of Deneb (Spin 2532)
SEH w/Diamonds for Extreme Heroism - Battle of Boughene
MCG - Battle of Boughene
TAS: William Hostman (CORR 2506)
TAS: Bearer (DAIB 1326)
IMTU ct+ tm++ tne tg-- tt+ tmo+ t4- t20+ to ru+ ge+ 3i+ c+ jt au ls pi+ ta he+ st+
Wil Hostman 0602 C539857-9 S A724
OTU: 95% 3i an+ au+ br- cpu± dt± f+ fs++ ge± ih- inf± j± jf+ jm+ jt+ ls- n= nc+ pi+ pp-- tp+ tr+ tv- vi-- xb+-
Unless there is bold red text, presume my posts to be my personal material only.
Reply With Quote
  #3  
Old August 11th, 2019, 04:32 PM
AndyW AndyW is offline
Citizen: SOC-9
 
Join Date: Jun 2019
Posts: 45
Gallery : 0
AndyW Citizen
Default

found a bug that would swallow my universe if I went in reverse. Fixed it now so it goes both ways. Very useful when dodging Romulan torpedos...
Reply With Quote
  #4  
Old August 11th, 2019, 08:30 PM
BRJN BRJN is offline
Citizen: SOC-12
 
Join Date: Jul 2018
Location: Fort Wayne
Posts: 222
Gallery : 0
BRJN Citizen
Default

Feed this program the Near Star List from 2300AD and you can incapacitate fans of that game, too.
__________________
Master, Hero (Siigiizuni)-class freighter Salutary Neglect.
Founder of Epsilon Ceti interface line.
Reply With Quote
  #5  
Old August 12th, 2019, 04:32 AM
timerover51's Avatar
timerover51 timerover51 is offline
Citizen: SOC-14
 
Join Date: Sep 2012
Location: North of Chicago
Posts: 6,355
Gallery : 4
Visit timerover51's Blog
timerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizen
Default

I apologize for my ignorance, but what exactly is this supposed to do?
__________________
Star Port Administrator: El Paso, El Paso, Sword Sub-sector, Piper-Norton Out Rim Sector
Link to Piper Sector: http://www.zarthani.net/ridder-mankind_to_the_stars.htm
Do you have a security clearance? New July 10 Blog Entry-New Goodies
http://www.youtube.com/watch?v=ElI451TxsTg, 3:24 in.
I march to my own set of bagpipes. Caution: This individual thinks that studying logistics is FUN.

They that go down to the sea in ships,
that do business in great waters;
These see the works of the LORD,
and his wonders in the deep.
Reply With Quote
  #6  
Old August 12th, 2019, 08:09 AM
AndyW AndyW is offline
Citizen: SOC-9
 
Join Date: Jun 2019
Posts: 45
Gallery : 0
AndyW Citizen
Default

Quote:
Originally Posted by timerover51 View Post
I apologize for my ignorance, but what exactly is this supposed to do?
It's just a random star field simulator, something to waste a few minutes of one's life on before moving on to the next distraction.

The speed can be changed with "+" & "-", and left and right turns can be done within the field with the left and right arrow keys. I can't yet figure out how to pitch up and down. I suppose it could be the basis for some sort of display for a space video game, but I'm not intending to do one. It's just a coding exercise which worked better than expected.

The approach is inspired by the ray tracing process. A "universe" is defined as a box of a range of 15000 each in x,y&z. The "viewscreen" is an x,y plane placed at z=600, and the users "eye" is assumed to be at 0,0,0. It is then populated by 500 stars.

The stars are fixed in x & y while they are in the limits of the "universe", with only their z changing with each iteration of the loop. A ratio of the distance between the absolute x,y,z position of the stars and the eye of the viewer and the distance from the eye to the screen is used to compute an "apparent" x,y value which is plotted on the screen. Once the stars advance beyond the limits of the universe box they are recycled to the opposite side at new random positions.

It renders a nice parallax effect as the stars advance toward, or away from the viewer to give the impression of 3D movement through the space.

The basic algorithm was done in under 100 lines of code, adding some display refinements and movement functions took a bit beyond that.
Reply With Quote
  #7  
Old August 15th, 2019, 05:12 AM
timerover51's Avatar
timerover51 timerover51 is offline
Citizen: SOC-14
 
Join Date: Sep 2012
Location: North of Chicago
Posts: 6,355
Gallery : 4
Visit timerover51's Blog
timerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizen
Default

I apologize for my ignorance, but I still have no understanding of what you are talking about. I do not follow why this should incapacitate a Trekkie.
__________________
Star Port Administrator: El Paso, El Paso, Sword Sub-sector, Piper-Norton Out Rim Sector
Link to Piper Sector: http://www.zarthani.net/ridder-mankind_to_the_stars.htm
Do you have a security clearance? New July 10 Blog Entry-New Goodies
http://www.youtube.com/watch?v=ElI451TxsTg, 3:24 in.
I march to my own set of bagpipes. Caution: This individual thinks that studying logistics is FUN.

They that go down to the sea in ships,
that do business in great waters;
These see the works of the LORD,
and his wonders in the deep.
Reply With Quote
  #8  
Old August 15th, 2019, 03:49 PM
whartung whartung is offline
Citizen: SOC-14
 
Join Date: Nov 2004
Posts: 2,450
Gallery : 0
whartung Citizen+whartung Citizen+whartung Citizen+
Default

Quote:
Originally Posted by timerover51 View Post
I apologize for my ignorance, but I still have no understanding of what you are talking about. I do not follow why this should incapacitate a Trekkie.
I'm assuming the premise is that were one a fan of Star Trek, with it's iconic bridge view of flying through a star field, seeing this animation may gather their attention for an inordinate amount of time.
Reply With Quote
  #9  
Old August 15th, 2019, 04:05 PM
timerover51's Avatar
timerover51 timerover51 is offline
Citizen: SOC-14
 
Join Date: Sep 2012
Location: North of Chicago
Posts: 6,355
Gallery : 4
Visit timerover51's Blog
timerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizentimerover51 Beloved Citizen
Default

Quote:
Originally Posted by whartung View Post
I'm assuming the premise is that were one a fan of Star Trek, with it's iconic bridge view of flying through a star field, seeing this animation may gather their attention for an inordinate amount of time.
So, basically what the old Afterdark Star Trek screensaver did. I never was a fan of that, as I liked the star ship assortment flying across the screen.
__________________
Star Port Administrator: El Paso, El Paso, Sword Sub-sector, Piper-Norton Out Rim Sector
Link to Piper Sector: http://www.zarthani.net/ridder-mankind_to_the_stars.htm
Do you have a security clearance? New July 10 Blog Entry-New Goodies
http://www.youtube.com/watch?v=ElI451TxsTg, 3:24 in.
I march to my own set of bagpipes. Caution: This individual thinks that studying logistics is FUN.

They that go down to the sea in ships,
that do business in great waters;
These see the works of the LORD,
and his wonders in the deep.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

This website and its contents are copyright ©2010- Far Future Enterprises. All rights reserved. Traveller is a registered trademark of Far Future Enterprises .
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2010-2013, Far Future Enterprises. All Rights Reserved.