SB Mystic Rectangles SS#3
#1
Here is the SmallBASIC version that inspired the QB64 version of Mystic Rectangles:
Code:
' Screen Saver #3 Mystic Rectangles.bas SmallBASIC 0.12.11 (B+=MGA) 2018-02-28
' instead of wire frame triangles try solid color rectangles
' arrays? we don't need no dang arrays!

randomize timer
nT = 150 'number of Things per screen
newRect
savex1 = x1 : savey1 = y1 : savedx1 = dx1 : savedy1 = dy1
savex2 = x2 : savey2 = y2 : savedx2 = dx2 : savedy2 = dy2
cN = nT
resetPlasma
while 1
 cls

 'reset color Number back to beginning + 1
 cN = cN - nT + 1
 
 'reset rect back to beginning and then update it once and save this for next round
 x1 = savex1 : y1 = savey1 : dx1 = savedx1 : dy1 = savedy1
 x2 = savex2 : y2 = savey2 : dx2 = savedx2 : dy2 = savedy2
 updateRect
 savex1 = x1 : savey1 = y1 : savedx1 = dx1 : savedy1 = dy1
 savex2 = x2 : savey2 = y2 : savedx2 = dx2 : savedy2 = dy2
 
 for j = 1 to nT
   updateRect
   changePlasma
   rect x1-12, y1-7, x2+2, y2+2 filled
   'inverse image and color
   xx1 = xmax - x1 : yy1 = ymax - y1
   xx2 = xmax - x2 : yy2 = ymax - y2
   if xx1 > xx2 then swap xx1, xx2
   if yy1 > yy2 then swap yy1, yy2
   rect xx1-12, yy1-7, xx2 , yy2, invColor filled
 next
 showpage
 delay 10
 k = inkey
 if k = " " then
   resetPlasma
 fi
wend

sub newRect
 x1 = RND * xmax
 y1 = RND * ymax
 dx1 = (RND * 9 + 3 ) * rdir
 dy1 = (RND * 5 + 2) * rdir
 x2 = RND * xmax
 y2 = RND * ymax
 dx2 = (RND * 9 + 3 ) * rdir
 dy2 = (RND * 5 + 2) * rdir
 'keep x1, y1 the lesser corner and x2, y2 the greater
 if x1 > x2 then swap x1, x2 : swap dx1, dx2
 if y1 > y2 then swap y1, y2 : swap dy1, dy2
end

sub updateRect
 if x1 + dx1 < 0 then dx1 = -dx1
 if x1 + dx1 > xmax then dx1 = -dx1
 x1 = x1 + dx1
 if y1 + dy1 < 0 then dy1 = -dy1
 if y1 + dy1 > ymax then dy1 = - dy1
 y1 = y1 + dy1
 if x2 + dx2 < 0 then dx2 = -dx2
 if x2 + dx2 > xmax then dx2 = -dx2
 x2 = x2 + dx2
 if y2 + dy2 < 0 then dy2 = -dy2
 if y2 + dy2 > ymax then dy2 = -dy2
 y2 = y2 + dy2
 'keep x1, y1 the lesser corner and x2, y2 the greater
 if x1 > x2 then swap x1, x2 : swap dx1, dx2
 if y1 > y2 then swap y1, y2 : swap dy1, dy2
end

sub changePlasma ()
 cN = cN + 1
 color rgb(127 + 127 * sin(pR * .2 * cN), 127 + 127 * sin(pG * .2 * cN), 127 + 127 * sin(pB * .2 * cN))
 invColor = rgb(255-(127+127*sin(pR*.2*cN)), 255-(127+127*sin(pG*.2*cN)),255-(127+17*sin(pB*.2*cN)))
end

sub resetPlasma ()
 pR = rnd ^ 2: pG = rnd ^ 2: pB = rnd ^ 2
end

func rdir()
 IF rnd < .5 THEN rdir = -1 ELSE rdir = 1
end


Attached Files Thumbnail(s)

B += x
Reply