Author Topic: Remember Screen Savers  (Read 1230 times)

B+

  • Guest
Remember Screen Savers
« on: February 13, 2016, 07:28:20 am »
Code: [Select]
REM ss number 2.bas 2016-02-11 SmallBASIC 0.12.0 [B+=MGA]

randomize
n=200
dim x(n),y(n),r(n),c(n),dx(n),dy(n),dr(n)
mxr=60

label restart
for i=1 to n
  x(i)=(xmax+200)*rnd-100
  y(i)=(ymax+200)*rnd-100
  r(i)=1+rnd*(mxr-1)
  dx(i)=10*rnd*rdir
  dy(i)=5*rnd*rdir
  dr(i)=2*rnd*rdir
  c1=int(rnd*2):c2=int(rnd*2):c3=int(rnd*2)
  c(i)=rgb(255*rnd*c1,255*rnd*c2,255*rnd*c3)
  if c(i)=0 then c(i)=rgb(255,0,0)
next
while 1
  if len(inkey) then goto restart
  cls
  for i=1 to n
    circle x(i)+rnd*6,y(i)+rnd*6,r(i),1,0 filled
    circle x(i),y(i),r(i),1,c(i) filled
    x(i)=x(i)+dx(i)
    if x(i)<-100 then dx(i)=dx(i)*-1
    if x(i)>xmax+100 then dx(i)=dx(i)*-1
    y(i)=y(i)+dy(i)
    if y(i)<-100 then dy(i)=dy(i)*-1
    if y(i)>ymax+100 then dy(i)=dy(i)*-1
    r(i)=r(i)+dr(i)
    if r(i)<1 then dr(i)=dr(i)*-1
    if r(i)>mxr then dr(i)=dr(i)*-1
  next
  showpage
  delay 10
wend
func rdir()
  if int(rnd*2) then rdir=1 else rdir=-1
end

B+

  • Guest
Re: Remember Screen Savers
« Reply #1 on: February 13, 2016, 07:36:09 am »
Code: [Select]
'SS number 2.sdlbas 2016-02-12 [B+=MGA]
xmax=800 :cx=xmax/2
ymax=600 :cy=ymax/2
randomize
setdisplay(xmax,ymax,32,1)
setcaption("SS number 2 for sdlBasic")
autoback(-2)

function randir()
if rnd(3)=2 then
randir=-1
else
randir=1
end if
end function

'initialize coordinates for a triangle 3 random points on the screen
x1=rnd(xmax+1)/2:x2=rnd(xmax+1)/2:x3=rnd(xmax+1)/2
y1=rnd(ymax+1)/2:y2=rnd(ymax+1)/2:y3=rnd(ymax+1)/2
cc=0 'color counter
dx1=randir*rnd(3)
dx2=randir*rnd(3)
dx3=randir*rnd(3)
dy1=randir*rnd(3)
dy2=randir*rnd(3)
dy3=randir*rnd(3)
toggle=0
while 1 'loop forever 1 is always true
if cc mod 510=0 then
cls
toggle=toggle+1
end if
'draw triangle
select case toggle mod 6
case 0
ink(rgb(255-(cc mod 510)/2,(cc mod 510)/2,0))
case 1
ink(rgb(255-(cc mod 510)/2,0,(cc mod 510)/2))
case 2
ink(rgb(0,255-(cc mod 510)/2,(cc mod 510)/2))
case 3
ink(rgb((cc mod 510)/2,255-(cc mod 510)/2,0))
case 4
ink(rgb(0,(cc mod 510)/2,255-(cc mod 510)/2))
case 5
ink(rgb((cc mod 510)/2,0,255-(cc mod 510)/2))
end select
triangle(x1,y1,x2,y2,x3,y3)
select case toggle mod 6
case 0
ink(rgb((cc mod 510)/2,255-(cc mod 510)/2,0))
case 1
ink(rgb((cc mod 510)/2,0,255-(cc mod 510)/2))
case 2
ink(rgb(0,(cc mod 510)/2,255-(cc mod 510)/2))
case 3
ink(rgb(255-(cc mod 510)/2,(cc mod 510)/2,0))
case 4
ink(rgb(0,255-(cc mod 510)/2,(cc mod 510)/2))
case 5
ink(rgb(255-(cc mod 510)/2,0,(cc mod 510)/2))
end select
d=x1-cx:xx1=cx-d
d=x2-cx:xx2=cx-d
d=x3-cx:xx3=cx-d
d=y1-cy:yy1=cy-d
d=y2-cy:yy2=cy-d
d=y3-cy:yy3=cy-d
triangle(xx1,yy1,xx2,yy2,xx3,yy3)
x1=x1+dx1
if x1<-10 then: dx1=dx1*-1 : end if
if x1>xmax then: dx1=dx1*-1 : end if
x2=x2+dx2
if x2<-10 then: dx2=dx2*-1 : end if
if x2>xmax+10 then: dx2=dx2*-1 : end if
x3=x3+dx3
if x3<-10 then: dx3=dx3*-1 : end if
if x3>xmax+10 then: dx3=dx3*-1 : end if
y1=y1+dy1
if y1<-10 then: dy1=dy1*-1 : end if
if y1>ymax+10 then: dy1=dy1*-1 : end if
y2=y2+dy2
if y2<-10 then: dy2=dy2*-1 : end if
if y2>ymax+10 then: dy2=dy2*-1 : end if
y3=y3+dy3
if y3<-10 then: dy3=dy3*-1 : end if
if y3>ymax+10 then: dy3=dy3*-1 : end if
cc=cc+1
screenswap
wait(10)
wend

dragomrak

  • Guest
Re: Remember Screen Savers
« Reply #2 on: February 13, 2016, 07:57:23 am »
Very nice, B+. Thanks.