Pan screen watching the tripping around
#1
Smile 
Going further with what I posted in this topic:

https://staging.qb64phoenix.com/showthread.php?tid=1334

I came up with something rather silly and visual to enjoy. I used pretty much these computations to come up with the "jaggies personalities" earlier. Press the arrow keys to pan around in the view. Press escape to quit this program.

Originally this program was in SCREEN 0 but I desired higher resolution and 32-bit color. Smile

Code: (Select All)
'by mnrvovrfc 15-May-2023
OPTION _EXPLICIT
TYPE being
    AS SINGLE x, y, a1, c1, f1, s1, m1, n1, a2, c2, f2, s2, m2, n2, a3, c3, m3
    AS INTEGER xn, yn
END TYPE

'a1 = angle (to convert to radians); c1 = coefficient; f1 = equation variety; s2 = added angle always sin
'm1 = increase a1; n1 = increase s1
'this is for first "wing" only, second "wing" doesn't have "f2"
'xn, yn = nudge; c = color; a3, m3 = outer "wing" angle
CONST NUMB = 100, VSLIM = 300
DIM SHARED vs(-VSLIM TO VSLIM, -VSLIM TO VSLIM)
DIM SHARED b(1 TO NUMB) AS being
DIM SHARED AS INTEGER xpan, ypan, rr, gg, bb
DIM AS INTEGER i, j
DIM upd AS _BYTE

DIM SHARED colr(1 TO NUMB) AS LONG

SCREEN _NEWIMAGE(960, 488, 32)
_DELAY 0.5
_TITLE "Press [ESC] to quit. Arrow keys to pan the view."
_FONT 8
xpan = 0
ypan = 0

RANDOMIZE TIMER
FOR i = 1 TO NUMB
    rr = (Rand(48, 191) \ 8) * 8
    gg = (Rand(80, 223) \ 8) * 8
    bb = (Rand(112, 255) \ 8) * 8
    IF Random1(2) = 1 THEN SWAP rr, gg
    IF Random1(2) = 1 THEN SWAP bb, gg
    IF Random1(2) = 1 THEN SWAP rr, bb
    colr(i) = _RGB(rr, gg, bb)
NEXT

FOR i = 1 TO NUMB
    b(i).xn = Random1(600) - 301
    b(i).yn = Random1(600) - 301
    b(i).a1 = Random1(360) - 1
    b(i).c1 = Rand(7, 150) / 10
    b(i).f1 = Random1(8)
    b(i).s1 = Random1(360) - 1
    b(i).m1 = Rand(5, 750) / 1000
    b(i).n1 = Random1(100) / 100
    b(i).a2 = Random1(360) - 1
    b(i).c2 = Rand(7, 95) / 10
    b(i).s2 = Random1(360) - 1
    b(i).m2 = Rand(5, 750) / 1000
    b(i).n2 = Random1(100) / 100
    b(i).a3 = Random1(360) - 1
    b(i).c3 = Rand(10, 45) / 10
    b(i).m3 = Rand(25, 900) / 1000
NEXT

upd = 1
DO
    _LIMIT 60
    FOR i = 1 TO NUMB
        changebeing i
    NEXT
    IF _KEYDOWN(18432) THEN
        ypan = ypan + 1
        upd = 1
    ELSEIF _KEYDOWN(20480) THEN
        ypan = ypan - 1
        upd = 1
    END IF
    IF _KEYDOWN(19200) THEN
        xpan = xpan + 1
        upd = 1
    ELSEIF _KEYDOWN(19712) THEN
        xpan = xpan - 1
        upd = 1
    END IF
    update upd
    IF upd = 1 THEN upd = 0
LOOP UNTIL _KEYDOWN(27)
SYSTEM


SUB update (uf AS _BYTE)
    STATIC AS INTEGER xrig, ybot, i, j, xx, yy
    STATIC ufo AS _BYTE
    ufo = 1
    IF xpan < -VSLIM THEN xpan = -VSLIM: ufo = 0
    xrig = xpan + 239
    IF xrig > VSLIM THEN
        xpan = xpan - 1
        xrig = xpan + 239
        ufo = 0
    END IF
    IF ypan < -VSLIM THEN ypan = -VSLIM: ufo = 0
    ybot = ypan + 119
    IF ybot > VSLIM THEN
        ypan = ypan - 1
        ybot = ypan + 119
        ufo = 0
    END IF
    IF uf AND ufo THEN CLS
    _PRINTSTRING (0, 480), "|" + STR$(xpan) + "|" + STR$(ypan)
    yy = 0
    FOR j = ypan TO ybot
        xx = 0
        FOR i = xpan TO xrig
            IF vs(j, i) THEN
                LINE (xx, yy)-STEP(3, 3), colr(vs(j, i)), BF
            END IF
            xx = xx + 4
        NEXT
        yy = yy + 4
    NEXT
END SUB

SUB changebeing (w AS INTEGER)
    STATIC AS LONG x, y
    b(w).a1 = b(w).a1 + b(w).m1
    b(w).s1 = b(w).s1 + b(w).n1
    IF b(w).a1 > 360 THEN b(w).a1 = b(w).a1 - 360
    IF b(w).s1 > 360 THEN b(w).s1 = b(w).s1 - 360
    b(w).a2 = b(w).a2 + b(w).m2
    b(w).s2 = b(w).s2 + b(w).n2
    IF b(w).a2 > 360 THEN b(w).a2 = b(w).a2 - 360
    IF b(w).s2 > 360 THEN b(w).s2 = b(w).s2 - 360
    b(w).a3 = b(w).a3 + b(w).m3
    IF b(w).a3 > 360 THEN b(w).a3 = b(w).a3 - 360
    SELECT CASE b(w).f1
        CASE 1
            b(w).x = b(w).c1 * (SIN(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) + b(w).c3 * SIN(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 2
            b(w).x = b(w).c1 * (COS(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) + b(w).c3 * SIN(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 3
            b(w).x = b(w).c1 * (SIN(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) * b(w).c3 * SIN(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 4
            b(w).x = b(w).c1 * (COS(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) * b(w).c3 * SIN(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 5
            b(w).x = b(w).c1 * (SIN(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) + b(w).c3 * COS(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 6
            b(w).x = b(w).c1 * (COS(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) + b(w).c3 * COS(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 7
            b(w).x = b(w).c1 * (SIN(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) * b(w).c3 * COS(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
        CASE 8
            b(w).x = b(w).c1 * (COS(_D2R(b(w).a1)) + SIN(_D2R(b(w).s1))) * b(w).c3 * COS(_D2R(b(w).a3))
            b(w).y = b(w).c2 * (SIN(_D2R(b(w).a2)) + SIN(_D2R(b(w).s2)))
    END SELECT
    x = INT(b(w).x + b(w).xn)
    y = INT(b(w).y + b(w).yn)
    IF x >= -VSLIM AND y >= -VSLIM AND x <= VSLIM AND y <= VSLIM THEN
        IF vs(y, x) = 0 THEN vs(y, x) = w
    END IF
END SUB


FUNCTION Rand& (fromval&, toval&)
    DIM sg%, f&, t&
    IF fromval& = toval& THEN
        Rand& = fromval&
        EXIT FUNCTION
    END IF
    f& = fromval&
    t& = toval&
    IF (f& < 0) AND (t& < 0) THEN
        sg% = -1
        f& = f& * -1
        t& = t& * -1
    ELSE
        sg% = 1
    END IF
    IF f& > t& THEN SWAP f&, t&
    Rand& = INT(RND * (t& - f& + 1) + f&) * sg%
END FUNCTION

FUNCTION Random1& (maxvaluu&)
    DIM sg%
    sg% = SGN(maxvaluu&)
    IF sg% = 0 THEN
        Random1& = 0
    ELSE
        IF sg% = -1 THEN maxvaluu& = maxvaluu& * -1
        Random1& = INT(RND * maxvaluu& + 1) * sg%
    END IF
END FUNCTION
Reply




Users browsing this thread: 2 Guest(s)