Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Equation For Specific Line Length Needed
#13
...and now for a more googly-eyed monster...

By doubling up the algorithm for each eye, we get independent action of each eyeball.

Code: (Select All)
'Following Eyes - Code by OldMoses mod by SierraKen
TYPE V2
    x AS INTEGER
    y AS INTEGER
END TYPE

DIM AS V2 m, h, h2, d, d2, sp, sp2
SCREEN _NEWIMAGE(800, 600, 32)
h.x = 350: h.y = 300
h2.x = 450: h2.y = 300
swordlength% = 5
DO
    CLS
    WHILE _MOUSEINPUT: WEND
    R2_Mouse m
    d = m: R2_Add d, h, -1 '
    d2 = m: R2_Add d2, h2, -1 '
    sp = d: R2_Norm sp, swordlength% '
    sp2 = d2: R2_Norm sp2, swordlength% '
    FOR sz = .25 TO 5 STEP .25
        CIRCLE (h.x + sp.x, h.y + sp.y), sz, _RGB32(255, 255, 255)
        CIRCLE (h2.x + sp2.x, h2.y + sp2.y), sz, _RGB32(255, 255, 255)
    NEXT sz
    CIRCLE (h.x, h.y), 15, _RGB32(255, 255, 255)
    CIRCLE (h2.x, h2.y), 15, _RGB32(255, 255, 255)
    CIRCLE (400, 325), 100, _RGB32(255, 255, 255)
    CIRCLE (400, 365), 65, _RGB32(255, 255, 255), , , .3
    _LIMIT 100
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
END


'SUBROUTINES
SUB R2_Mouse (re AS V2) 'get mouse position vector and store in return
    re.x = _MOUSEX
    re.y = _MOUSEY
END SUB


SUB R2_Add (re AS V2, v AS V2, add AS INTEGER) 'adds or subtracts scalar multiples of v from return
    re.x = re.x + (v.x * add)
    re.y = re.y + (v.y * add)
END SUB 'R2_Add


SUB R2_Norm (re AS V2, scalar AS INTEGER) 'shrink return to unit vector and regrow by scalar amount
    x! = re.x: y! = re.y
    m! = _HYPOT(x!, y!)
    IF m! = 0 THEN
        re.x = 0: re.y = 0
    ELSE
        re.x = (x! / m!) * scalar
        re.y = (y! / m!) * scalar
    END IF
END SUB 'R2_Norm
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply


Messages In This Thread
RE: Equation For Specific Line Length Needed - by OldMoses - 08-17-2022, 11:13 PM



Users browsing this thread: 6 Guest(s)