Text Rotation Fun
#1
Here is the QB64 translation from SmallBASIC version:
Code:
_TITLE "Text Rotation Fun by bplus 2018-02-02"
'from: text rotation fun.bas for SmallBASIC 0.12.11 (B+=MGA) 2017-02-02

CONST xmax = 1200
CONST ymax = 720
SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 100, 20

'global variables
COMMON SHARED message$, secWide, secHigh, a
message$ = "abcdefghijklmnopqrstuvwxyz"
secWide = LEN(message$) * 8
secHigh = 16
DIM SHARED sect(secWide, secHigh) 'array to store message points
COLOR _RGB32(200, 200, 200), 0: CLS
'LINE (0, 0)-(secWide, secHigh), _RGB32(0, 0, 255), B

PRINT message$
loadSect 0, 0 'load array
'debug checks
'FOR y = 0 TO secHigh
'    FOR x = 0 TO secWide
'        IF sect(x, y) THEN PSET (x + 200, y + 200)
'    NEXT
'NEXT
'INPUT "OK "; ok

DIM SHARED plasma(5, 3)
FOR i = 0 TO 5
    plasma(i, 0) = RND * RND
    plasma(i, 1) = RND * RND
    plasma(i, 2) = RND * RND
NEXT

CLS
cx = xmax / 2: cy = ymax / 2
WHILE 1
    CLS
    dp 0
    yaxis cx, cy / 4, a, 2
    dp 1
    xaxis cx, 3 * cy / 4, .5 * a, 6
    dp 2
    rotate cx / 2, cy, -3 * a, 1
    dp 3
    rotate 3 * cx / 2, cy, 2 * a - 90, 2.5
    dp 4
    rotate cx, cy / 2, -a - 90, 2
    dp 5
    rotate cx, 3 * cy / 2, a + 180, 4.5
    _DISPLAY
    _LIMIT 60
    a = a + 1
    IF a = 36000 THEN a = 0
WEND

SUB dp (i)
    COLOR _RGB32(128 + 127 * SIN(plasma(i, 0) * .01 * a), 128 + 127 * SIN(plasma(i, 1) * .01 * a), 128 + 127 * SIN(plasma(i, 2) * .01 * a))
END SUB

SUB loadSect (xstart, ystart)
    'local x, y, p, black
    'these are all global
    black&& = _RGB32(0, 0, 0)
    FOR y = 0 TO secHigh
        FOR x = 0 TO secWide
            p&& = POINT(xstart + x, ystart + y)
            IF p&& <> black& THEN sect(x, y) = 1 '<== data from screen points
        NEXT
    NEXT
END SUB

SUB rotate (cx, cy, angle, scale) 'and scale
    'local cax, cay, ra, cc, d, anew, ax,ay

    cax = secWide / 2: cay = secHigh / 2 'array center
    FOR y = 0 TO secHigh
        FOR x = 0 TO secWide
            cc = sect(x, y)
            IF (x - cax) <> 0 AND cc <> 0 THEN
                d = ((x - cax) ^ 2 + (y - cay) ^ 2) ^ .5
                anew = ATN((y - cay) / (x - cax))
                IF x - cax < 0 AND y - cay < 0 THEN anew = anew + _PI + rad(angle) '-x,-y
                IF x - cax < 0 AND y - cay >= 0 THEN anew = anew + _PI + rad(angle) '-x,+y
                IF x - cax >= 0 AND y - cay < 0 THEN anew = anew + rad(angle) '+x,-y
                IF x - cax >= 0 AND y - cay >= 0 THEN anew = anew + rad(angle) '+x,+y
                ax = d * COS(anew): ay = d * SIN(anew)
                LINE (cx + ax * scale, cy + ay * scale)-STEP(scale - 1, scale - 1), , BF
            END IF
        NEXT
    NEXT
END SUB

SUB yaxis (cx, cy, angle, scale)
    'local cax, cay, cc, ax,ay

    cax = secWide / 2: cay = secHigh / 2 'array center
    FOR y = 0 TO secHigh
        FOR x = 0 TO secWide
            cc = sect(x, y)
            IF cc <> 0 THEN
                ax = (x - cax) * COS(rad(angle)): ay = (y - cay)
                LINE (cx + ax * scale, cy + ay * scale)-STEP(scale - 1, scale - 1), , BF
            END IF
        NEXT
    NEXT
END SUB

SUB xaxis (cx, cy, angle, scale)
    'local cax, cay, cc, ax,ay

    cax = secWide / 2: cay = secHigh / 2 'array center
    FOR y = 0 TO secHigh
        FOR x = 0 TO secWide
            cc = sect(x, y)
            IF cc <> 0 THEN
                ax = (x - cax): ay = (y - cay) * SIN(rad(angle))
                LINE (cx + ax * scale, cy + ay * scale)-STEP(scale - 1, scale - 1), , BF
            END IF
        NEXT
    NEXT
END SUB

FUNCTION rad (degreeAngle)
    rad = degreeAngle * _PI / 180
END FUNCTION

I particularly like the y axis rotation!
B += x
Reply
#2
Nice. I saw it on qb64 first.
Reply
#3
Yeah, today I realized, "Why stop at text?", can do this with any image or part of one!

So next up is to generalize, LoadSec to return a loaded array and then render by array rotations or new scales... anywhere around any point.

This may be key to finally drawing on top of SmallBASIC images the biggest hindrance to doing game stuff there.
B += x
Reply
#4
Really really nice. Ok, so I have another demo to study to figure out how it work.

Donald
Reply
#5
Quote:For a bad joke 
http://www.laughfactory.com/jokes/joke-of-the-day 
worse than Pete's [Image: biggrin.gif]

I'm happy to hear you hold my humor in such high ass-steam!

Pete Big Grin
Reply