Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bouncing lines & boxes
#1
Starting playing around with the power of LINE styles and it lead to 3d looking mystify like screensaver (in 1st code box).  Afterwards changed it to bouncing boxes, added some fading.  Kept in some LINE style stuff.  (Code box #2).   On my laptop 12 boxes seems to be the sweet spot when setting _LIMIT 30. 

- Dav


Bouncing LINEs....

Code: (Select All)
'=================
'BouncingLines.bas
'=================
'Coded by Dav, May/2022

SCREEN _NEWIMAGE(800, 600, 32)

RANDOMIZE TIMER

lines = 12 'Number of lines on screen

DIM line.x1(lines), line.y1(lines), line.cx1(lines), line.cy1(lines)
DIM line.x2(lines), line.y2(lines), line.cx2(lines), line.cy2(lines)
DIM line.r(lines), line.g(lines), line.b(lines), line.a(lines)

'Init values for each line
FOR s = 1 TO lines
    line.y1(s) = INT(RND * _HEIGHT) + 1: line.x1(s) = INT(RND * _WIDTH) + 1
    line.y2(s) = INT(RND * _HEIGHT) + 1: line.x2(s) = INT(RND * _WIDTH) + 1
    line.cx1(s) = RND * 1: line.cy1(s) = RND * 1
    line.cx2(s) = RND * 1: line.cy2(s) = RND * 1
    line.r(s) = RND * 255: line.g(s) = RND * 255: line.b(s) = RND * 255
    line.a(s) = RND * 75 + 15
NEXT

DO

    FOR s = 1 TO lines

        'draw line...
        LINE (line.x1(s), line.y1(s))-(line.x2(s), line.y2(s)), _RGBA(line.r(s), line.g(s), line.b(s), line.a(s)), , 255
        'shadow
        LINE (line.x1(s) + 2, line.y1(s) + 2)-(line.x2(s) + 2, line.y2(s) + 2), _RGBA(0, 0, 0, line.a(s)), , 255

        IF line.x1(s) <= 0 OR line.x1(s) >= _WIDTH THEN line.cx1(s) = -line.cx1(s)
        IF line.y1(s) <= 0 OR line.y1(s) >= _HEIGHT THEN line.cy1(s) = -line.cy1(s)

        IF line.x2(s) <= 0 OR line.x2(s) >= _WIDTH THEN line.cx2(s) = -line.cx2(s)
        IF line.y2(s) <= 0 OR line.y2(s) >= _HEIGHT THEN line.cy2(s) = -line.cy2(s)

        line.x1(s) = line.x1(s) + line.cx1(s): line.y1(s) = line.y1(s) + line.cy1(s)
        line.x2(s) = line.x2(s) + line.cx2(s): line.y2(s) = line.y2(s) + line.cy2(s)

    NEXT

    _DISPLAY

    _LIMIT 300

LOOP UNTIL INKEY$ <> ""


Bouncing  faded boxes.....


Code: (Select All)
'=================
'BouncingBoxes.bas
'=================
'Coded by Dav, May/2022

SCREEN _NEWIMAGE(800, 600, 32)

RANDOMIZE TIMER

boxes = 12 'Number of boxes on screen

DIM box.x1(boxes), box.y1(boxes), box.cx1(boxes), box.cy1(boxes)
DIM box.x2(boxes), box.y2(boxes), box.cx2(boxes), box.cy2(boxes)
DIM box.r(boxes), box.g(boxes), box.b(boxes), box.a(boxes)

'Init values for each box
FOR s = 1 TO boxes
    box.y1(s) = INT(RND * _HEIGHT) + 1: box.x1(s) = INT(RND * _WIDTH) + 1
    box.y2(s) = INT(RND * _HEIGHT) + 1: box.x2(s) = INT(RND * _WIDTH) + 1
    box.cx1(s) = RND * 4: box.cy1(s) = RND * 4
    box.cx2(s) = RND * 4: box.cy2(s) = RND * 4
    box.r(s) = RND * 255: box.g(s) = RND * 255: box.b(s) = RND * 255
    box.a(s) = RND * 75 + 15
NEXT

DO

    CLS , _RGB(0, 0, 48)

    FOR s = 1 TO boxes

        'draw box
        LINE (box.x1(s), box.y1(s))-(box.x2(s), box.y2(s)), _RGBA(box.r(s), box.g(s), box.b(s), box.a(s)), BF
        'center lines
        LINE (box.x1(s), box.y1(s))-(box.x2(s), box.y2(s)), _RGBA(255, 255, 255, box.a(s)), , 255
        LINE (box.x2(s), box.y1(s))-(box.x1(s), box.y2(s)), _RGBA(255, 255, 255, box.a(s)), , 255
        'box outline
        LINE (box.x1(s), box.y1(s))-(box.x2(s), box.y2(s)), _RGBA(255, 255, 255, box.a(s)), B , 255

        IF box.x1(s) <= 0 OR box.x1(s) >= _WIDTH THEN box.cx1(s) = -box.cx1(s)
        IF box.y1(s) <= 0 OR box.y1(s) >= _HEIGHT THEN box.cy1(s) = -box.cy1(s)

        IF box.x2(s) <= 0 OR box.x2(s) >= _WIDTH THEN box.cx2(s) = -box.cx2(s)
        IF box.y2(s) <= 0 OR box.y2(s) >= _HEIGHT THEN box.cy2(s) = -box.cy2(s)

        box.x1(s) = box.x1(s) + box.cx1(s): box.y1(s) = box.y1(s) + box.cy1(s)
        box.x2(s) = box.x2(s) + box.cx2(s): box.y2(s) = box.y2(s) + box.cy2(s)

    NEXT

    _DISPLAY

    _LIMIT 30

LOOP UNTIL INKEY$ <> ""

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Bouncing lines & boxes - by Dav - 05-25-2022, 10:46 PM
RE: Bouncing lines & boxes - by SierraKen - 05-25-2022, 11:07 PM
RE: Bouncing lines & boxes - by bplus - 05-26-2022, 12:03 AM
RE: Bouncing lines & boxes - by James D Jarvis - 05-26-2022, 12:22 PM
RE: Bouncing lines & boxes - by Dav - 05-27-2022, 12:53 PM
RE: Bouncing lines & boxes - by Kernelpanic - 05-27-2022, 04:55 PM



Users browsing this thread: 1 Guest(s)