|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
I was bored, what more can I say? I was in a creation mood, and I had nothing to create. So I thought why not attempt something... so what I attempted was a Matrix kind of thing. You know, the classic, scrolling down the screen numbers things.
So here's what I came up with: <html> <head> <script type="text/javascript"> var count = 0 var greens = new Array ('527B10','639C18','7BC618','94D639') codeNumber = "" for (x = 0; x < 30; x++) { thisNumber = Math.floor(Math.random() * 10) codeNumber += thisNumber.toString() } function breakCode() { stop = false thisDiv = document.createElement('div'); thisDiv.setAttribute ('id' , 'div' + count) document.getElementsByTagName('body')[0].appendChild(thisDiv) document.getElementById('div' + count).style.width = "100%" page = "<table cellpadding='0' cellspacing='0' width='100%'><tr>" codeAttempt = "" for (x = 0; x < 30; x++) { page += "<td align='center' " page += "style='color:#" + greens[Math.floor(Math.random() * greens.length)] + ";" Math.random() * 10 > 5 ? page += "font-weight:bold;" : page += "" ; page += "'" page += ">" thisNumber = Math.floor(Math.random() * 10) codeAttempt += thisNumber.toString() page += thisNumber page += "</td>" } page += "</tr></table>" document.getElementById('div' + count).style.position = "absolute" document.getElementById('div' + count).style.top = 0 document.getElementById('div' + count).style.left = 0 document.getElementById('div' + count).innerHTML = page divs = document.getElementsByTagName('div') for (x = 0; x < divs.length; x++) { thisDiv = eval("document.getElementById('" + divs[x].id + "').style") thisDiv.top = parseInt(thisDiv.top) + 20 if (parseInt(thisDiv.top) > document.body.offsetHeight - 40) { thisDiv.display = "none" } } count++ if (parseInt(codeAttempt) != codeNumber) { setTimeout("breakCode()", 1) } else { document.getElementById('div' + count).style.backgroundColor = "#ff0000" } } </script> </head> <body onLoad="breakCode()" style="background-color:black; font-size:14pt"> </body> </html> It works in IE6. As yet, it has no 'artificial intelligence' in otherwords it scrolls but doesn't actually do anything other than take random stabs at the 30 digit number it generates. I will be adding the intelligence soon, stay tooned! P.S. I said I was bored. |
|
#2
|
||||
|
||||
|
Okay, the updated version:
<html> <head> <script type="text/javascript"> var count = 0 var greens = new Array ('527B10','639C18','7BC618','94D639') var codeNumber = "" var brokenNumbers = new Array() var codeLength = 10 // change this number to increase the code length var timeNow = new Date var startTime = timeNow.getTime() for (x = 0; x < codeLength; x++) { thisNumber = Math.floor(Math.random() * 10) codeNumber += thisNumber.toString() } for (x = 0; x < codeLength; x++) { brokenNumbers[x] = "" } function generateNumber() { codeAttempt = "" for (x = 0; x < codeLength; x++) { thisNumber = Math.floor(Math.random() * 10) codeAttempt += thisNumber.toString() } for (x = 0; x < codeLength; x++) { if (brokenNumbers[x] != "") { substr1 = codeAttempt.substr(0,x) substr2 = codeAttempt.substr(x + 1, codeAttempt.length) codeAttempt = substr1 + brokenNumbers[x] + substr2 } } return codeAttempt } function breakCode() { stop = false thisDiv = document.createElement('div'); thisDiv.setAttribute ('id' , 'div' + count) document.getElementsByTagName('body')[0].appendChild(thisDiv) document.getElementById('div' + count).style.width = "100%" page = "<table cellpadding='0' cellspacing='0' width='100%'><tr>" codeAttempt = generateNumber() for (x = 0; x < codeLength; x++) { page += "<td align='center' " page += "style='color:#" + greens[Math.floor(Math.random() * greens.length)] + ";" Math.random() * 10 > 5 ? page += "font-weight:bold;" : page += "" ; page += "'" page += ">" thisNumber = codeAttempt.substr(x,1) thisNumber == codeNumber.substr(x,1) ? brokenNumbers[x] = thisNumber : false ; page += thisNumber page += "</td>" } page += "</tr></table>" document.getElementById('div' + count).style.position = "absolute" document.getElementById('div' + count).style.top = 0 document.getElementById('div' + count).style.left = 0 document.getElementById('div' + count).innerHTML = page divs = document.getElementsByTagName('div') for (x = 0; x < divs.length; x++) { thisDiv = eval("document.getElementById('" + divs[x].id + "').style") thisDiv.top = parseInt(thisDiv.top) + 20 if (parseInt(thisDiv.top) > document.body.offsetHeight - 40) { thisDiv.display = "none" } } count++ for (x = 0; x < codeLength; x++) { brokenNumbers[x] == codeNumber.substr(x,1) ? match = true : match = false ; if (!match) { break } } if (!match) { setTimeout("breakCode()", 1) } else { var timeNow = new Date endTime = timeNow.getTime() timeTaken = endTime - startTime thisDiv = document.createElement('div'); thisDiv.setAttribute ('id' , 'div' + count) document.getElementsByTagName('body')[0].appendChild(thisDiv) document.getElementById('div' + count).style.position = "absolute" document.getElementById('div' + count).style.top = 0 document.getElementById('div' + count).style.left = 0 document.getElementById('div' + count).style.color = '527B10' document.getElementById('div' + count).innerHTML = "Match found.... code number is " + codeNumber + " (execution time: " + (timeTaken/1000) + " seconds)" for (x = 0; x < divs.length; x++) { thisDiv = eval("document.getElementById('" + divs[x].id + "').style") thisDiv.top = parseInt(thisDiv.top) + 20 if (parseInt(thisDiv.top) > document.body.offsetHeight - 40) { thisDiv.display = "none" } } } } </script> </head> <body onLoad="breakCode()" style="background-color:black; font-size:14pt"> </body> </html> |
|
#3
|
||||
|
||||
|
That's pretty neat, makes me want to pick up more javascript. . . (though I just got out of therapy induced by trying to cross-browser debug it. . .)
Given my purist, control-freakish ways, I just naturally gravitate toward server-side stuff. Pretty cool. . . |
|
#4
|
|||
|
|||
|
That's pretty cool
![]() What exactly is that code matching thing? Is it like generating a random string from the array and trying to match it or something? You know what'd be cool? Do it all with 1's and 0's. Wasn't it done with them in that movie? I think *scratches head*
__________________
K1 |
|
#5
|
||||
|
||||
|
i likes
![]()
__________________
--the key to life is avoiding death-- |
|
#6
|
||||
|
||||
|
man, i wish i had a lot of time to kill like you do.
|
|
#7
|
||||
|
||||
|
binky, which pill did you take, the red one or the blue one?
![]() Impressive though... //NoXcuz
__________________
UN*X is sexy! who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep |
|
#8
|
||||
|
||||
|
Maybe that was why I was off work with a headache though, thinking that one through was tough.
It just generating a number itself, the length of the number is controlled by a variable, then it randomly tries numbers until it finds the correct ones. Suppose it stands to reason that it was 1s and 0s on the film, base2 and not base10 would be right. May change it, or go alpha numeric to make it more complicated. NoXcuz.... if only.. |
|
#9
|
||||
|
||||
|
Very nice binky...
__________________
deepspring - "Netscape 4 users are like lemmings... You can't help but laugh when one falls off a cliff" |
|
#10
|
||||
|
||||
|
Cheers!
![]() |
|
#11
|
||||
|
||||
|
I like it a lot. Now if only you could add the Japanese characters in and have pieces of the code zoom/fade towards the user.
![]() |
|
#12
|
|||
|
|||
|
Matrix - Reloaded
Guys,
here is a bit Javascript that does the Matrix effect even better... html> <head> <title>Matrix-like</title> <script language="JavaScript"> /* filter:fliph; */ </script> <style> body{ font-size:10pt; font-weight:normal; background-color:#000000; color:#000000; } </style> </head> <body scroll=no> <script language="JavaScript"> // definition de quelques valeurs var cw=document.body.clientWidth var ch=document.body.clientHeight var nb_cols=Math.floor(cw/16) // nb_cols-- var nb_rows=Math.floor(ch/30) nb_rows-- var dk_colors=new Array("#173317","#215221") var normal_color="#40A241" var light_color="#A9F0AC" var rnd_gly=new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",",","/","+","-","*","_","{","%","!",".",";","$","1","2","3","4","5","6","7","8","9","0") // boucle collones et char+couleurs for(n_col=0;n_col<=nb_cols-1;n_col++){ document.write("<div id=d"+n_col+" style='position:absolute;top:0px;'><tt></div>") document.getElementById("d"+n_col).style.width=16 document.getElementById("d"+n_col).style.left=(n_col*16) var nb_chars=Math.floor(Math.random()*(nb_rows)) document.getElementById("d"+n_col).style.height=(nb_chars+1)*30 var h_div=parseInt(document.getElementById("d"+n_col).style.height) // pour vérifier ajouter à la ligne en dessous // document.getElementById("d"+n_col).style.top=-h_div document.getElementById("d"+n_col).style.filter="fliph" // mettre des caracteres avec des couleurs for(n_char=0;n_char<=nb_chars;n_char++){ if(n_char<=1){ document.getElementById("d"+n_col).innerHTML+="<tt><font color='"+dk_colors[n_char]+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt><br>" }else if((n_char>1)&&(n_char<nb_chars)){ document.getElementById("d"+n_col).innerHTML+="<tt><font color='"+normal_color+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt><br>" }else{ document.getElementById("d"+n_col).innerHTML+="<tt><font color='"+light_color+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt>" } } // fin de déf des char_colorés ^ } // fin boucle collones ^ var deja_fait_st=new Array() var deja_fait_st_index=0 function del_et_restart(numero){ // del HTML document.getElementById("d"+numero).innerHTML="<tt>" // resiZe var nb_chars=Math.floor(Math.random()*(nb_rows)) document.getElementById("d"+n_col).style.height=(nb_chars+1)*30 var h_div=parseInt(document.getElementById("d"+n_col).style.height) document.getElementById("d"+n_col).style.top=-h_div // re-cholor et text for(n_char=0;n_char<=nb_chars;n_char++){ if(n_char<=1){ document.getElementById("d"+numero).innerHTML+="<tt><font color='"+dk_colors[n_char]+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt><br>" }else if((n_char>1)&&(n_char<nb_chars)){ document.getElementById("d"+numero).innerHTML+="<tt><font color='"+normal_color+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt><br>" }else{ document.getElementById("d"+numero).innerHTML+="<tt><font color='"+light_color+"'>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</font></tt>" } } } bas() function bas(){ for(n_col=0;n_col<=nb_cols-1;n_col++){ if(parseInt(document.getElementById("d"+n_col).style.top)<=ch){ document.getElementById("d"+n_col).style.top=parseInt(document.getElementById("d"+n_col).style.top)+30 }else{ del_et_restart(n_col) } } window.setTimeout("bas()",50) } /* bas_st() function bas_st(){ var current_down=Math.random()*nb_cols // recherche for(i=0;i<=deja_fait_st.length;i++){ if (deja_fait_st.slice(i,i+1).substring(current_down)==-1){ deja_fait_st[deja_fait_st_index]=current_down deja_fait_st_index++ } else break } if(deja_fait_st==nb_cols){ void(0) }else{ document.getElementById("d"+n_col).style.top+=30 bas_st() } } window.alert(nb_cols) window.alert(nb_rows) window.alert(nb_cols*nb_rows) document.write("<nobr>") for(n_col=0;n_col<=nb_cols-1;n_col++){ document.write("<div id=d"+n_col+" style='position:absolute;top:0px;'><tt>"+rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"</div>") document.getElementById("d"+n_col).style.width=16 document.getElementById("d"+n_col).style.left=(n_col*16) document.getElementById("d"+n_col).style.top=0 document.getElementById("d"+n_col).style.height=ch-10 // document.getElementById("d"+n_col).style.filter="fliph" // boucle contenu for(i=0;i<nb_rows;i++){ document.getElementById("d"+n_col).innerHTML+=rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"<br>" } document.getElementById("d"+n_col).innerHTML+=rnd_gly[Math.floor(Math.random()*rnd_gly.length)] } document.write("</nobr>") window.setTimeout("down()", 5) function down(){ for(n_col=0;n_col<=nb_cols-1;n_col++){ document.getElementById("d"+n_col).innerHTML=rnd_gly[Math.floor(Math.random()*rnd_gly.length)]+"<br>"+document.getElementById("d"+n_col).innerHTML // document.getElementById("d"+n_col).innerHTML=document.getElementById("d"+n_col).innerHTML.substring(0, document.getElementById("d"+n_col).innerHTML.lastIndexOf("<br>")) } window.setTimeout("down()", 500) } */ </script> </body> </html> |
|
#13
|
||||
|
||||
|
Two different things....Although both really nice.
Who has the credits on the above post? |
|
#14
|
|
|