Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Googly Eyes looking around screen
#1
Small demo of Googly eyes drifting around the screen.  The eyes look toward the direction they are moving.  Just a small demo that may help some learn to use _PUTIMAGE and move images around the screen in different ways.  I tried to comment more than usual.

- Dav

Code: (Select All)
'==============
'GOOGLYEYES.BAS
'==============
'Eyes drift around space, looking in direction they go.
'Shows how to create images off screen and use _PUTIMAGE.
'Demo also shows how to move images in interesting ways.
'Coded by Dav, NOV/2022


'=== First, create 4 eye images to use....

'=== Create image of eyes looking left
eyeleft& = _NEWIMAGE(230, 200, 32)
_DEST eyeleft& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255 'left eye
ball 30, 50, 20, 0, 0, 32 'left pupil
ball 150, 50, 50, 255, 255, 255 'right eye
ball 130, 50, 20, 0, 0, 32 'right pupil

'=== Create image of eyes looking right
eyeright& = _NEWIMAGE(230, 200, 32)
_DEST eyeright& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 70, 50, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 170, 50, 20, 0, 0, 32

'=== Create an image of eyes looking up
eyeup& = _NEWIMAGE(230, 200, 32)
_DEST eyeup& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 30, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 30, 20, 0, 0, 32

'=== Create an image of eyes looking down
eyedown& = _NEWIMAGE(230, 200, 32)
_DEST eyedown& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 70, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 70, 20, 0, 0, 32


'=== Now we point to main screen

_DEST 0 'set destination to draw to main screen
SCREEN _NEWIMAGE(800, 600, 32) 'main screen size

RANDOMIZE TIMER 'do this so the RND call is different everytime

Eyes = 100 'the number of eyes on screen
EyeSizeMax = 225 'largest size eyes can be

DIM EyeX(Eyes), EyeY(Eyes) 'x/y position of the eye
DIM EyeSize(Eyes) ' size of eye
DIM EyeGrowth(Eyes) 'eye growing or shrinking on screen
DIM EyeDrift(Eyes) 'direction eye drifts across screen
DIM EyeDriftSpeed(Eyes) 'speed for the drift

'generate eye values
FOR d = 1 TO Eyes
    EyeX(d) = RND * _WIDTH 'make random x position
    EyeY(d) = RND * _HEIGHT 'make random y position
    EyeSize(d) = (RND * EyeSizeMax) 'random eye size, up to EyeSizeMax
    EyeGrowth(d) = INT(RND * 2) 'make way eye size is changing, 0=shrinking, 1=growing
    EyeDrift(d) = INT(RND * 4) 'make random direction a eye can drift (4 different ways)
    EyeDriftSpeed(d) = INT(RND * 3) + 2 'speed eyes will be drifting
NEXT


DO

    CLS , _RGB(0, 0, 32) 'clear screen to dark blue

    'step through each eye
    FOR d = 1 TO Eyes

        'if eye is shrinking, subtract eyesize, else add to it
        IF EyeGrowth(d) = 0 THEN
            EyeSize(d) = EyeSize(d) - 1
        ELSE
            EyeSize(d) = EyeSize(d) + 1
        END IF

        'if eyesize reaches max size, switch growth to 0 start shrinking instead
        IF EyeSize(d) >= EyeSizeMax THEN EyeGrowth(d) = 0
        'if if reaches smallest eyesize, switch growth to 1 to start growing now
        IF EyeSize(d) <= 20 THEN EyeGrowth(d) = 1

        'drift eye in  1 of 4 directions we generated, and do +x,-x,+y,-y to it.
        IF EyeDrift(d) = 0 THEN EyeX(d) = EyeX(d) + EyeDriftSpeed(d) 'drift right
        IF EyeDrift(d) = 1 THEN EyeX(d) = EyeX(d) - EyeDriftSpeed(d) 'drift left
        IF EyeDrift(d) = 2 THEN EyeY(d) = EyeY(d) + EyeDriftSpeed(d) 'drift down
        IF EyeDrift(d) = 3 THEN EyeY(d) = EyeY(d) - EyeDriftSpeed(d) 'drift up

        'this creates the shakiness. randomly adjust x/y positions by +/-2 each step
        IF INT(RND * 2) = 0 THEN EyeX(d) = EyeX(d) + 2 ELSE EyeX(d) = EyeX(d) - 2
        IF INT(RND * 2) = 0 THEN EyeY(d) = EyeY(d) + 2 ELSE EyeY(d) = EyeY(d) - 2

        'below handles if eye goes off screen, let it dissapear completely
        IF EyeX(d) > _WIDTH + EyeSize(d) THEN EyeX(d) = -EyeSize(d)
        IF EyeX(d) < -EyeSize(d) THEN EyeX(d) = _WIDTH + EyeSize(d)
        IF EyeY(d) > _HEIGHT + EyeSize(d) THEN EyeY(d) = -EyeSize(d)
        IF EyeY(d) < -EyeSize(d) THEN EyeY(d) = _HEIGHT + EyeSize(d)

        'drift eye in  1 of 4 directions we generated, and +x,-x,+y,-y to it.
        IF EyeDrift(d) = 0 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeright& 'drift right
        IF EyeDrift(d) = 1 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeleft& 'drift left
        IF EyeDrift(d) = 2 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyedown& 'drift down
        IF EyeDrift(d) = 3 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeup& 'drift up

        'get new random direction change
        SELECT CASE INT(RND * 300)
            CASE 1: EyeDrift(d) = 0: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 2: EyeDrift(d) = 1: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 3: EyeDrift(d) = 2: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 4: EyeDrift(d) = 3: EyeDriftSpeed(d) = INT(RND * 3) + 2
        END SELECT

    NEXT

    _DISPLAY
    _LIMIT 30

LOOP

SUB ball (x, y, size, r&, g&, b&)
    'small sub that draws a filled ball with given color.
    FOR s = 1 TO size STEP .4
        CIRCLE (x, y), s, _RGB(r&, g&, b&)
        r& = r& - 1: g& = g& - 1: b& = b& - 1
    NEXT
END SUB

Find my programs here in Dav's QB64 Corner
Reply
#2
Great fun! I was doing that with Boids and space ships pointed in direction they were going.

I also like eyeballs/boids heading towards the mouse.
b = b + ...
Reply
#3
Yeah maybe I can add mouse interaction.  I thought having the smaller eyes over the bigger ones on screen doesn't look natural, so I threw in a bubble sort to keep the bigger size eyes over the smaller ones.  Not sure which looks better, but here's that one.

Code: (Select All)
'===============
'GOOGLYEYES2.BAS
'===============
'Eyes drift around space, looking in direction they go.
'Shows how to create images off screen and use _PUTIMAGE.
'Demo also shows how to move images in interesting ways.
'Coded by Dav, NOV/2022

'V2 - Added bubble sort to keep smaller eyes in background.

'=== First, create 4 eye images to use....

'=== Create image of eyes looking left
eyeleft& = _NEWIMAGE(230, 200, 32)
_DEST eyeleft& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255 'left eye
ball 30, 50, 20, 0, 0, 32 'left pupil
ball 150, 50, 50, 255, 255, 255 'right eye
ball 130, 50, 20, 0, 0, 32 'right pupil

'=== Create image of eyes looking right
eyeright& = _NEWIMAGE(230, 200, 32)
_DEST eyeright& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 70, 50, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 170, 50, 20, 0, 0, 32

'=== Create an image of eyes looking up
eyeup& = _NEWIMAGE(230, 200, 32)
_DEST eyeup& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 30, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 30, 20, 0, 0, 32

'=== Create an image of eyes looking down
eyedown& = _NEWIMAGE(230, 200, 32)
_DEST eyedown& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 70, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 70, 20, 0, 0, 32


'=== Now we point to main screen

_DEST 0 'set destination to draw to main screen
SCREEN _NEWIMAGE(800, 600, 32) 'main screen size

RANDOMIZE TIMER 'do this so the RND call is different everytime

Eyes = 100 'the number of eyes on screen
EyeSizeMax = 225 'largest size eyes can be

DIM EyeX(Eyes), EyeY(Eyes) 'x/y position of the eye
DIM EyeSize(Eyes) ' size of eye
DIM EyeGrowth(Eyes) 'eye growing or shrinking on screen
DIM EyeDrift(Eyes) 'direction eye drifts across screen
DIM EyeDriftSpeed(Eyes) 'speed for the drift

'generate eye values
FOR d = 1 TO Eyes
    EyeX(d) = RND * _WIDTH 'make random x position
    EyeY(d) = RND * _HEIGHT 'make random y position
    EyeSize(d) = (RND * EyeSizeMax) 'random eye size, up to EyeSizeMax
    EyeGrowth(d) = INT(RND * 2) 'make way eye size is changing, 0=shrinking, 1=growing
    EyeDrift(d) = INT(RND * 4) 'make random direction a eye can drift (4 different ways)
    EyeDriftSpeed(d) = INT(RND * 3) + 2 'speed eyes will be drifting
NEXT


DO


    'Bubble sort through eyesize, putting smallest size first so..
    '..they will be _PUTIMAGE'd first, putting them in the background.
    FOR b = 1 TO Eyes
        FOR b2 = 1 TO Eyes
            IF EyeSize(b2) > EyeSize(b) THEN
                SWAP EyeX(b), EyeX(b2)
                SWAP EyeY(b), EyeY(b2)
                SWAP EyeSize(b), EyeSize(b2)
                SWAP EyeGrowth(b), EyeGrowth(b2)
                SWAP EyeDrift(b), EyeDrift(b2)
                SWAP EyeDriftSpeed(b), EyeDriftSpeed(b2)
            END IF
        NEXT
    NEXT

    CLS , _RGB(0, 0, 32) 'clear screen to dark blue

    'step through each eye
    FOR d = 1 TO Eyes

        'if eye is shrinking, subtract eyesize, else add to it
        IF EyeGrowth(d) = 0 THEN
            EyeSize(d) = EyeSize(d) - 1
        ELSE
            EyeSize(d) = EyeSize(d) + 1
        END IF

        'if eyesize reaches max size, switch growth to 0 start shrinking instead
        IF EyeSize(d) >= EyeSizeMax THEN EyeGrowth(d) = 0

        'if if reaches smallest eyesize, switch growth to 1 to start growing now
        IF EyeSize(d) <= 20 THEN EyeGrowth(d) = 1

        'drift eye in  1 of 4 directions we generated, and do +x,-x,+y,-y to it.
        IF EyeDrift(d) = 0 THEN EyeX(d) = EyeX(d) + EyeDriftSpeed(d) 'drift right
        IF EyeDrift(d) = 1 THEN EyeX(d) = EyeX(d) - EyeDriftSpeed(d) 'drift left
        IF EyeDrift(d) = 2 THEN EyeY(d) = EyeY(d) + EyeDriftSpeed(d) 'drift down
        IF EyeDrift(d) = 3 THEN EyeY(d) = EyeY(d) - EyeDriftSpeed(d) 'drift up

        'this creates the shakiness. randomly adjust x/y positions by +/-2 each step
        IF INT(RND * 2) = 0 THEN EyeX(d) = EyeX(d) + 2 ELSE EyeX(d) = EyeX(d) - 2
        IF INT(RND * 2) = 0 THEN EyeY(d) = EyeY(d) + 2 ELSE EyeY(d) = EyeY(d) - 2

        'below handles if eye goes off screen, let it dissapear completely
        IF EyeX(d) > _WIDTH + EyeSize(d) THEN EyeX(d) = -EyeSize(d)
        IF EyeX(d) < -EyeSize(d) THEN EyeX(d) = _WIDTH + EyeSize(d)
        IF EyeY(d) > _HEIGHT + EyeSize(d) THEN EyeY(d) = -EyeSize(d)
        IF EyeY(d) < -EyeSize(d) THEN EyeY(d) = _HEIGHT + EyeSize(d)

        'drift eye in  1 of 4 directions we generated, and +x,-x,+y,-y to it.
        IF EyeDrift(d) = 0 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeright& 'drift right
        IF EyeDrift(d) = 1 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeleft& 'drift left
        IF EyeDrift(d) = 2 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyedown& 'drift down
        IF EyeDrift(d) = 3 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeup& 'drift up

        'get new random direction change
        SELECT CASE INT(RND * 300)
            CASE 1: EyeDrift(d) = 0: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 2: EyeDrift(d) = 1: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 3: EyeDrift(d) = 2: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 4: EyeDrift(d) = 3: EyeDriftSpeed(d) = INT(RND * 3) + 2
        END SELECT

    NEXT

    _DISPLAY
    _LIMIT 30

LOOP

SUB ball (x, y, size, r&, g&, b&)
    'small sub that draws a filled ball with given color.
    FOR s = 1 TO size STEP .4
        CIRCLE (x, y), s, _RGB(r&, g&, b&)
        r& = r& - 1: g& = g& - 1: b& = b& - 1
    NEXT
END SUB

Find my programs here in Dav's QB64 Corner
Reply
#4
Eye like it!

+ 1

Pete
Reply
#5
Hmmm... Muppets in the dark... Cool...
May your journey be free of incident. Live long and prosper.
Reply
#6
Hmmm... many people wouldn't go for it but combine this somehow with some of MasterGy's code. When this imaginary program runs, the camera takes a picture. Then the "eyes" could indicate what it might be looking at, moving around, rotating, zooming and what not. It might become realistic enough and scary.
Reply
#7
Are you sure they're eyes?
My perverted mind sees them differently!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#8
Oh, I forgot. It isn't cold in Australia this time of year. Sad

Pete
Reply
#9
Eyes now blink (hopefully they will look more like eyes Phil, lol).   Gave the eyes something to look at too. 

Last version probably, my eyes are getting tired of looking at these.  Was a fun diversion for a while.

- Dav

Code: (Select All)
'===============
'GOOGLYEYES3.BAS
'===============
'Eyes drift around space, looking in direction they go.
'Shows how to create images off screen and use _PUTIMAGE.
'Demo also shows how to move images in interesting ways.
'Coded by Dav, NOV/2022

'V3 - Gave eyes something to look at. Made Eyes Blink

'=== First, create 4 eye images to use....

'=== Create image of eyes looking left
eyeleft& = _NEWIMAGE(230, 200, 32)
_DEST eyeleft& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255 'left eye
ball 30, 50, 20, 0, 0, 128 'left pupil
ball 150, 50, 50, 255, 255, 255 'right eye
ball 130, 50, 20, 0, 0, 128 'right pupil
CIRCLE (50, 50), 50, _RGB(0, 0, 0)
CIRCLE (150, 50), 50, _RGB(0, 0, 0)
CIRCLE (30, 50), 20, _RGB(0, 0, 0)
CIRCLE (130, 50), 20, _RGB(0, 0, 0)

'=== Create image of eyes looking right
eyeright& = _NEWIMAGE(230, 200, 32)
_DEST eyeright& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 70, 50, 20, 0, 0, 128
ball 150, 50, 50, 255, 255, 255
ball 170, 50, 20, 0, 0, 128
CIRCLE (50, 50), 50, _RGB(0, 0, 0)
CIRCLE (150, 50), 50, _RGB(0, 0, 0)
CIRCLE (70, 50), 20, _RGB(0, 0, 0)
CIRCLE (170, 50), 20, _RGB(0, 0, 0)

'=== Create an image of eyes looking up
eyeup& = _NEWIMAGE(230, 200, 32)
_DEST eyeup& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 30, 20, 0, 0, 128
ball 150, 50, 50, 255, 255, 255
ball 150, 30, 20, 0, 0, 128
CIRCLE (50, 50), 50, _RGB(0, 0, 0)
CIRCLE (150, 50), 50, _RGB(0, 0, 0)
CIRCLE (50, 30), 20, _RGB(0, 0, 0)
CIRCLE (150, 30), 20, _RGB(0, 0, 0)

'=== Create an image of eyes looking down
eyedown& = _NEWIMAGE(230, 200, 32)
_DEST eyedown& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 70, 20, 0, 0, 128
ball 150, 50, 50, 255, 255, 255
ball 150, 70, 20, 0, 0, 128
CIRCLE (50, 50), 50, _RGB(0, 0, 0)
CIRCLE (150, 50), 50, _RGB(0, 0, 0)
CIRCLE (50, 70), 20, _RGB(0, 0, 0)
CIRCLE (150, 70), 20, _RGB(0, 0, 0)

'=== Create an image of eyes blinking
eyeblink& = _NEWIMAGE(200, 800, 32)
_DEST eyeblink& 'point to above image so we can draw to it
ball 50, 150, 50, 196, 196, 196
ball 150, 150, 50, 196, 196, 196
ball 50, 150, 20, 64, 64, 128
ball 150, 150, 29, 64, 64, 128

CIRCLE (50, 150), 50, _RGB(0, 0, 0)
CIRCLE (150, 150), 50, _RGB(0, 0, 0)

'=== Now we point to main screen

_DEST 0 'set destination to draw to main screen
SCREEN _NEWIMAGE(800, 600, 32) 'main screen size

RANDOMIZE TIMER 'do this so the RND call is different everytime

Eyes = 75 'the number of eyes on screen
EyeSizeMax = 225 'largest size eyes can be

DIM EyeX(Eyes), EyeY(Eyes) 'x/y position of the eye
DIM EyeSize(Eyes) ' size of eye
DIM EyeGrowth(Eyes) 'eye growing or shrinking on screen
DIM EyeDrift(Eyes) 'direction eye drifts across screen
DIM EyeDriftSpeed(Eyes) 'speed for the drift
DIM EyeBlinkFlag(Eyes) 'eyes blinking flag
DIM EyeBlinkCount(Eyes)

'generate eye values
FOR d = 1 TO Eyes
    EyeX(d) = RND * _WIDTH 'make random x position
    EyeY(d) = RND * _HEIGHT 'make random y position
    EyeSize(d) = (RND * EyeSizeMax) 'random eye size, up to EyeSizeMax
    EyeGrowth(d) = INT(RND * 2) 'make way eye size is changing, 0=shrinking, 1=growing
    EyeDrift(d) = INT(RND * 4) 'make random direction a eye can drift (4 different ways)
    EyeDriftSpeed(d) = INT(RND * 3) + 2 'speed eyes will be drifting
    EyeBlinkFlag(d) = 0 'if eye is blinking or not
    EyeBlinkCount(d) = 0
NEXT


DO

    'Bubble sort through eyesize, putting smallest size first so..
    '..they will be _PUTIMAGE'd first, putting them in the background.
    FOR b = 1 TO Eyes
        FOR b2 = 1 TO Eyes
            IF EyeSize(b2) > EyeSize(b) THEN
                SWAP EyeX(b), EyeX(b2)
                SWAP EyeY(b), EyeY(b2)
                SWAP EyeSize(b), EyeSize(b2)
                SWAP EyeGrowth(b), EyeGrowth(b2)
                SWAP EyeDrift(b), EyeDrift(b2)
                SWAP EyeDriftSpeed(b), EyeDriftSpeed(b2)
                SWAP EyeBlinkFlag(b), EyeBlinkFlag(b2)
                SWAP EyeBlinkCount(b), EyeBlinkCount(b2)
            END IF
        NEXT
    NEXT

    'scroll secret built-in qb64 icon image...
    qx = qx + 1: IF qx > _WIDTH THEN qx = 0
    _PUTIMAGE (qx, 0)-(qx + _WIDTH, _HEIGHT), -11
    _PUTIMAGE (-_WIDTH + qx, 0)-(qx, _HEIGHT), -11

    'step through each eye
    FOR d = 1 TO Eyes

        'if eye is shrinking, subtract eyesize, else add to it
        IF EyeGrowth(d) = 0 THEN
            EyeSize(d) = EyeSize(d) - 1
        ELSE
            EyeSize(d) = EyeSize(d) + 1
        END IF

        'if eyesize reaches max size, switch growth to 0 start shrinking instead
        IF EyeSize(d) >= EyeSizeMax THEN EyeGrowth(d) = 0

        'if if reaches smallest eyesize, switch growth to 1 to start growing now
        IF EyeSize(d) <= 20 THEN EyeGrowth(d) = 1

        'drift eye in  1 of 4 directions we generated, and do +x,-x,+y,-y to it.
        IF EyeDrift(d) = 0 THEN EyeX(d) = EyeX(d) + EyeDriftSpeed(d) 'drift right
        IF EyeDrift(d) = 1 THEN EyeX(d) = EyeX(d) - EyeDriftSpeed(d) 'drift left
        IF EyeDrift(d) = 2 THEN EyeY(d) = EyeY(d) + EyeDriftSpeed(d) 'drift down
        IF EyeDrift(d) = 3 THEN EyeY(d) = EyeY(d) - EyeDriftSpeed(d) 'drift up

        'this creates the shakiness. randomly adjust x/y positions by +/-2 each step
        IF INT(RND * 2) = 0 THEN EyeX(d) = EyeX(d) + 2 ELSE EyeX(d) = EyeX(d) - 2
        IF INT(RND * 2) = 0 THEN EyeY(d) = EyeY(d) + 2 ELSE EyeY(d) = EyeY(d) - 2

        'below handles if eye goes off screen, let it dissapear completely
        IF EyeX(d) > _WIDTH + EyeSize(d) THEN EyeX(d) = -EyeSize(d)
        IF EyeX(d) < -EyeSize(d) THEN EyeX(d) = _WIDTH + EyeSize(d)
        IF EyeY(d) > _HEIGHT + EyeSize(d) THEN EyeY(d) = -EyeSize(d)
        IF EyeY(d) < -EyeSize(d) THEN EyeY(d) = _HEIGHT + EyeSize(d)

        'drift eye in  1 of 4 directions we generated, and +x,-x,+y,-y to it.

        'If blinking flag on...
        IF EyeBlinkFlag(d) = 1 THEN

            SELECT CASE EyeBlinkCount(d)
                CASE 0 TO 3
                    _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeblink&
                CASE 4 TO 8
                    LINE (EyeX(d), EyeY(d) + (EyeSize(d) / 6))-(EyeX(d) + EyeSize(d), EyeY(d) + (EyeSize(d) / 6) + 3), _RGB(64, 64, 64), BF
                CASE 9 TO 12
                    _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeblink&
            END SELECT

            EyeBlinkCount(d) = EyeBlinkCount(d) + 1
            IF EyeBlinkCount(d) > 12 THEN
                EyeBlinkCount(d) = 0
                EyeBlinkFlag(d) = 0
            END IF

        ELSE
            'showing normal eyes
            IF EyeDrift(d) = 0 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeright& 'drift right
            IF EyeDrift(d) = 1 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeleft& 'drift left
            IF EyeDrift(d) = 2 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyedown& 'drift down
            IF EyeDrift(d) = 3 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeup& 'drift up
        END IF

        'get random direction change,growth and blinking once in a while
        SELECT CASE INT(RND * 300)
            CASE 1: EyeDrift(d) = 0: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 2: EyeDrift(d) = 1: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 3: EyeDrift(d) = 2: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 4: EyeDrift(d) = 3: EyeDriftSpeed(d) = INT(RND * 3) + 2
            CASE 5: EyeGrowth(d) = 0
            CASE 6: EyeGrowth(d) = 1
            CASE 7: IF EyeBlinkFlag(d) = 0 THEN EyeBlinkFlag(d) = 1
        END SELECT

    NEXT

    _DISPLAY
    _LIMIT 30

LOOP

SUB ball (x, y, size, r&, g&, b&)
    'small sub that draws a filled ball with given color.
    FOR s = 1 TO size STEP .4
        CIRCLE (x, y), s, _RGB(r&, g&, b&)
        r& = r& - 1: g& = g& - 1: b& = b& - 1
    NEXT
END SUB

Find my programs here in Dav's QB64 Corner
Reply
#10
Sorry Dav. Phil ruined it for me, well, kind of.

Pete
Reply




Users browsing this thread: 5 Guest(s)