I have made a simple screensaver that consists in lots of colorful dots floating through the screen, and when they touch the edges they get stuck, and a new dot appears somewhere in the screen. It's simple but I think it's a nice screensaver.
Here's the code:
clear
display(5).mode=displayMode.pixel
gfx=display(5)
gfx.clear "#000000FF"
display(4).mode=displayMode.sprite
disp=display(4)
disp.clear
dotImages=[]
dotSheet=file.loadImage("dots.png")
for i in range(0,dotSheet.width/7-1)
dotImages.push dotSheet.getImage(7*i,0,7,7)
end for
Dot=new Sprite
Dot.dx=0
Dot.dy=0
Dot.maxDy=1
Dot.minDy=-1
Dot.going=-1
Dot.update=function()
if self.tint[7:9]!="99" then
self.tint=self.tint[0:7]+str(val(self.tint[7:9])+11)
end if
if self.going==0 then self.going=floor(rnd*3)-1
if self.dy>self.maxDy then
self.going=-1
else if self.dy<self.minDy then
self.going=1
end if
if self.x>960 then
dots.remove dots.indexOf(self)
setDot floor(rnd*960),floor(rnd*640)
dots[-1].tint=dots[-1].tint[0:7]+"00"
else if 0>self.x then
dots.remove dots.indexOf(self)
setDot floor(rnd*960),floor(rnd*640)
dots[-1].tint=dots[-1].tint[0:7]+"00"
end if
if self.y>640 or 0>self.y then
dots.remove dots.indexOf(self)
setDot floor(rnd*960),floor(rnd*640)
dots[-1].tint=dots[-1].tint[0:7]+"00"
end if
self.dy=self.dy+0.1*self.going
self.x=self.x+self.dx
self.y=self.y+self.dy
end function
dots=[]
rndFrom=function(lt)
return lt[floor(rnd*lt.len)]
end function
setDot=function(x,y)
d=new Dot
d.x=x
d.y=y
d.tint=rndFrom(["#AAAA0000","#AA000000","#0000AA00","#00000000","#80800000","#00AA0000","#AACCEE00"])
d.dy=floor(rnd*3)-1
d.going=floor(rnd*3)-1
d.image=dotImages[floor(rnd*dotImages.len)]
d.rotation=floor(rnd*360)
d.scale=floor(rnd*2)+1//[floor(rnd*2)+1,floor(rnd*2)+1]
d.maxDy=rnd*d.scale+0.1
d.minDy=rnd*-d.scale-0.1
d.dx=(rndFrom([1,-1]))*d.scale/3
// d.tint="#FFFFFF99"
disp.sprites.push d
dots.push d
end function
for i in range(0,100)
setDot floor(rnd*gfx.width),floor(rnd*gfx.height)
end for
gfx.clear color.white
while true
yield
for d in dots
d.update
end for
end while
You can also write gfx.clear "#00000000"
instead of gfx.clear "#FFFFFFFF"
, it's cool too.
Make a "dots.ms" (or any name you want) file with this code, then put the image below in the same folder as the file.