Bouncing lines & boxes - Dav - 05-25-2022
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$ <> ""
RE: Bouncing lines & boxes - SierraKen - 05-25-2022
Pretty wild Dav! Reminds me of the 90's screen savers. I like how everything shifts from small to large to small, etc.
RE: Bouncing lines & boxes - bplus - 05-26-2022
Striped lines are interesting. Boxes remind me of Sierpinski in Space.
RE: Bouncing lines & boxes - James D Jarvis - 05-26-2022
I like the 3-d shaded look on those bouncing lines.
RE: Bouncing lines & boxes - Dav - 05-27-2022
Here's a twist on the lines one. Makes a ghost lines, patchwork looking screen. Increase the lines count for more involved look. 5000 looks interesting. My Laptop could go up to 10000 lines before getting too slow.
- Dav
Code: (Select All) '==================
'BouncingLines2.bas
'==================
'Coded by Dav, May/2022
SCREEN _NEWIMAGE(800, 600, 32)
RANDOMIZE TIMER
lines = 100 'Number of lines on screen. (Try 5000!)
DIM line.x1(lines), line.y1(lines), line.cx1(lines), line.cy1(lines)
DIM line.r(lines), line.g(lines), line.b(lines), line.a(lines)
'Init values for each box
FOR s = 1 TO lines
line.y1(s) = INT(RND * _HEIGHT) + 1: line.x1(s) = INT(RND * _WIDTH) + 1
line.cx1(s) = RND * 2: line.cy1(s) = RND * 2
line.r(s) = RND * 200 + 55: line.g(s) = RND * 200 + 55: line.b(s) = RND * 200 + 55
line.a(s) = RND * 100
NEXT
DO
FOR s = 1 TO lines
LINE (line.x1(s) - RND * 8, line.y1(s) - RND * 8)-(line.x1(s) + RND * 8, line.y1(s) + RND * 8), _RGBA(line.r(s), line.g(s), line.b(s), line.a(s)), BF
LINE (line.x1(s) - 8, line.y1(s) - 8)-(line.x1(s) + 8, line.y1(s) + 8), _RGBA(0, 0, 0, line.a(s)), B
IF line.x1(s) <= 0 OR line.x1(s) >= _WIDTH THEN line.cx1(s) = -line.cx1(s): line.a(s) = RND * 15
IF line.y1(s) <= 0 OR line.y1(s) >= _HEIGHT THEN line.cy1(s) = -line.cy1(s): line.a(s) = RND * 15
line.x1(s) = line.x1(s) + line.cx1(s): line.y1(s) = line.y1(s) + line.cy1(s)
line.a(s) = line.a(s) - .05
IF line.a(s) <= -10 THEN line.a(s) = RND * 100
NEXT
_DISPLAY
_LIMIT 300
LOOP UNTIL INKEY$ <> ""
RE: Bouncing lines & boxes - Kernelpanic - 05-27-2022
Very nice! Reminds me at the old times with Win 95.
|