metanohi-misc-subsites/old-projects/x/mgravity.htm

149 lines
2.8 KiB
HTML
Raw Normal View History

2011-08-02 19:57:57 +02:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3c.org/1999/xhtml"><head><title>Multi Gravity</title><style type='text/css'>
body {
margin:0;
padding:0;
overflow:hidden;
}
div {
position:absolute;
left:-50px;
top:-50px;
width:50px;
height:50px;
}
#l {
top:0;
left:0;
height:100%;
width:100%;
z-index:2;
background:transparent;
}
</style><script type='text/javascript'>
paused=false
oknbox=true
function getwh() {
if (self.innerHeight) {
h=self.innerHeight
w=self.innerWidth
}
else if (document.documentElement && document.documentElement.clientHeight) {
h=document.documentElement.clientHeight
w=document.documentElement.clientHeight
}
else if (document.body) {
h=document.body.clientHeight
w=document.body.clientWidth
}
}
function gravity() {
getwh()
ah=h-50
aw=w-50
d=0
for (i=0;i<num;i++) {
if (y[i]<ah || spd[i]>-1) {
if (f[i]) {
spd[i]+=verticalspeed[i]
y[i]+=spd[i]
if (y[i]<ah) b[i].style.top=y[i]+"px"
else {
b[i].style.top=ah+"px"
spd[i]-=verticalspeed[i]
f[i]=false
horizontalspeed[i]=horizontalspeed[i]/1.1
}
}
else {
spd[i]-=verticalspeed[i]
y[i]-=spd[i]
if (y[i]>ah) y[i]=ah
if (spd[i]>0 && y[i]<=ah) b[i].style.top=y[i]+"px"
else f[i]=true
}
if (r[i]) {
x[i]+=horizontalspeed[i]
if (x[i]<aw) b[i].style.left=x[i]+"px"
else {
r[i]=false
horizontalspeed[i]=horizontalspeed[i]/1.2
}
}
else {
x[i]-=horizontalspeed[i]
if (x[i]>0) b[i].style.left=x[i]+"px"
else {
r[i]=true
horizontalspeed[i]=horizontalspeed[i]/1.2
}
}
}
else {
horizontalspeed[i]=0
d++
}
}
document.title="Multi Gravity :: "+d+"/"+num
t=setTimeout("gravity()",50)
}
function newbox() {
if (oknbox) {
getwh()
y[num]=-50
x[num]=Math.floor(Math.random()*(w-49))
spd[num]=0
verticalspeed[num]=2
horizontalspeed[num]=15
f[num]=true
rol=Math.floor(Math.random()*2)
if (rol==0) r[num]=true
else r[num]=false
b[num]=document.createElement("div")
b[num].style.top=y[num]+"px"
b[num].style.left=x[num]+"px"
b[num].style.backgroundColor="rgb("+(Math.floor(Math.random()*100)+77)+","+(Math.floor(Math.random()*100)+77)+","+(Math.floor(Math.random()*100)+77)+")"
document.body.appendChild(b[num])
num++
}
nt=setTimeout("newbox()",1000)
}
function pauseboxes() {
if (!paused) {
paused=true
clearTimeout(t)
oknbox=false
}
else {
paused=false
gravity()
oknbox=true
}
}
function load() {
l=document.createElement("div")
l.id="l"
l.onclick=pauseboxes
document.body.appendChild(l)
y=new Array()
x=new Array()
b=new Array()
spd=new Array()
verticalspeed=new Array()
horizontalspeed=new Array()
f=new Array()
r=new Array()
num=0
newbox()
gravity()
}
window.onload=load
</script></head><body></body></html>