Cheer 发表于 2007-4-28 10:58:31

时间日期java-led

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
<script language="javascript">
<!--// copyright 1996 - tomer and yehuda shiran
// this example will appear in our forthcoming book on javascript.
// set messages
var messages = new array()
messages = "welcome to javahouse"
messages = "javascript world!"
messages = "the largest archive"
messages = "on the net!"
messages = "tons of great fun"
messages = "thanks for visiting"
messages = "enjoy the ride"

// set normal spacing between two characters (no whitespace inbetween)
var space = 1

// set height width of each character
var height = 5
var width = 3

// create object of all supported characters in font
var letters = new letterarray()

// initialize image variables
var on = new image(5, 5)
var off = new image(5, 5)

// set image urls
on.src = "ledon.gif"
off.src = "ledoff.gif"

// get number of images already layed out in page
var imagenum = document.images.length

// set maximum message length in characters
var boardwidth = 0

for (var i = 0; i < messages.length; ++i) {   
    var lengthwithnospaces = messages.split(" ").join("").length   
    var numberofspaces = messages.length - lengthwithnospaces   
    var currentboardwidth = lengthwithnospaces * (width + space) - space + numberofspaces * space * 2   
    if (boardwidth < currentboardwidth)      
      boardwidth = currentboardwidth
}
// sign is currently not running
var running = false
var timerid = null

function letterarray() {   
    this.a = new array(height)   
    this.a = " * "   
    this.a = "* *"   
    this.a = "***"   
    this.a = "* *"   
    this.a = "* *"   
   
    this.b = new array(height)   
    this.b = "** "   
    this.b = "* *"   
    this.b = "**"   
    this.b = "* *"   
    this.b = "**"   
   
    this.c = new array(height)   
    this.c = "***"   
    this.c = "*"   
    this.c = "*"   
    this.c = "*"   
    this.c = "***"   

    this.d = new array(height)   
    this.d = "** "   
    this.d = "* *"   
    this.d = "* *"   
    this.d = "* *"   
    this.d = "** "   

    this.e = new array(height)   
    this.e = "*** "   
    this.e = "*"   
    this.e = "***"   
    this.e = "*"   
    this.e = "***"   
   
    this.f = new array(height)   
    this.f = "***"   
    this.f = "*"   
    this.f = "***"   
    this.f = "*"   
    this.f = "*"   

    this.g = new array(height)   
    this.g = "***"   
    this.g = "*"   
    this.g = "***"   
    this.g = "* *"   
    this.g = "***"   

    this.h = new array(height)   
    this.h = "* *"   
    this.h = "* *"   
    this.h = "***"   
    this.h = "* *"   
    this.h = "* *"   

    this.i = new array(height)   
    this.i = "***"   
    this.i = " * "   
    this.i = " * "   
    this.i = " * "   
    this.i = "***"   

    this.j = new array(height)   
    this.j = "*"   
    this.j = "*"   
    this.j = "*"   
    this.j = "* *"   
    this.j = "***"      

    this.k = new array(height)   
    this.k = "* *"   
    this.k = "* *"   
    this.k = "**"   
    this.k = "* *"   
    this.k = "* *"   

    this.l = new array(height)   
    this.l = "*"   
    this.l = "*"   
    this.l = "*"   
    this.l = "*"   
    this.l = "***"   
   
    this.m = new array(height)   
    this.m = "* *"   
    this.m = "***"   
    this.m = "***"   
    this.m = "* *"   
    this.m = "* *"   

    this.n = new array(height)   
    this.n = "* *"   
    this.n = "***"   
    this.n = "***"   
    this.n = "***"   
    this.n = "* *"   

    this.o = new array(height)   
    this.o = "***"   
    this.o = "* *"   
    this.o = "* *"   
    this.o = "* *"   
    this.o = "***"   
   
    this.p = new array(height)   
    this.p = "** "   
    this.p = "* *"   
    this.p = "** "   
    this.p = "*"   
    this.p = "*"   

    this.q = new array(height)   
    this.q = "***"   
    this.q = "* *"   
    this.q = "* *"   
    this.q = "***"   
    this.q = "***"   

    this.r = new array(height)   
    this.r = "** "   
    this.r = "* *"   
    this.r = "** "   
    this.r = "* *"   
    this.r = "* *"   

    this.s = new array(height)   
    this.s = "***"   
    this.s = "*"   
    this.s = "***"   
    this.s = "*"   
    this.s = "***"   
   
    this.t = new array(height)   
    this.t = "***"   
    this.t = " * "   
    this.t = " * "   
    this.t = " * "   
    this.t = " * "   

    this.u = new array(height)   
    this.u = "* *"   
    this.u = "* *"   
    this.u = "* *"   
    this.u = "* *"   
    this.u = "***"   

    this.v = new array(height)   
    this.v = "* *"   
    this.v = "* *"   
    this.v = "* *"   
    this.v = "* *"   
    this.v = " * "   

    this.w = new array(height)   
    this.w = "* *"   
    this.w = "* *"   
    this.w = "***"   
    this.w = "***"   
    this.w = "***"   

    this.x = new array(height)   
    this.x = "* *"   
    this.x = "* *"   
    this.x = " * "   
    this.x = "* *"   
    this.x = "* *"   

    this.y = new array(height)   
    this.y = "* *"   
    this.y = "* *"   
    this.y = "***"   
    this.y = " * "   
    this.y = " * "   

    this.z = new array(height)   
    this.z = "***"   
    this.z = "*"   
    this.z = " *"   
    this.z = "*"   
    this.z = "***"   

    this['!'] = new array(height)   
    this['!'] = " * "   
    this['!'] = " * "   
    this['!'] = " * "   
    this['!'] = "   "   
    this['!'] = " * "   

    this[':'] = new array(height)   
    this[':'] = "   "   
    this[':'] = " * "   
    this[':'] = "   "   
    this[':'] = " * "   
    this[':'] = "   "   

    this['.'] = new array(height)   
    this['.'] = "   "   
    this['.'] = "   "   
    this['.'] = "   "   
    this['.'] = "   "   
    this['.'] = " * "            

    this['='] = new array(height)   
    this['='] = "   "   
    this['='] = "***"   
    this['='] = "   "   
    this['='] = "***"   
    this['='] = "   "   
   
    this['='] = new array(height)   
    this['='] = "   "   
    this['='] = "***"   
    this['='] = "   "   
    this['='] = "***"   
    this['='] = "   "   

    this['+'] = new array(height)   
    this['+'] = "   "   
    this['+'] = " * "   
    this['+'] = "***"   
    this['+'] = " * "   
    this['+'] = "   "   

    this['-'] = new array(height)   
    this['-'] = "   "   
    this['-'] = "   "   
    this['-'] = "***"   
    this['-'] = "   "   
    this['-'] = "   "   

    this['/'] = new array(height)   
    this['/'] = "*"   
    this['/'] = "*"   
    this['/'] = " * "   
    this['/'] = "*"   
    this['/'] = "*"   
   
    this['\\'] = new array(height)   
    this['\\'] = "*"   
    this['\\'] = "*"   
    this['\\'] = " * "   
    this['\\'] = "*"   
    this['\\'] = "*"   

    this['\\'] = new array(height)   
    this['\\'] = "*"   
    this['\\'] = "*"   
    this['\\'] = " * "   
    this['\\'] = "*"   
    this['\\'] = "*"   

    this['"'] = new array(height)   
    this['"'] = "* *"   
    this['"'] = "* *"   
    this['"'] = "* *"   
    this['"'] = "   "   
    this['"'] = "   "   
   
    this["'"] = new array(height)   
    this["'"] = " * "   
    this["'"] = " * "   
    this["'"] = " * "   
    this["'"] = "   "   
    this["'"] = "   "   

    this['('] = new array(height)   
    this['('] = "*"   
    this['('] = " * "   
    this['('] = " * "   
    this['('] = " * "   
    this['('] = "*"   

    this[')'] = new array(height)   
    this[')'] = "*"   
    this[')'] = " * "   
    this[')'] = " * "   
    this[')'] = " * "   
    this[')'] = "*"   
   
    this['*'] = new array(height)   
    this['*'] = "   "   
    this['*'] = "***"   
    this['*'] = "***"   
    this['*'] = "***"   
    this['*'] = "   "   

    this['?'] = new array(height)   
    this['?'] = "** "   
    this['?'] = "*"   
    this['?'] = " * "   
    this['?'] = "   "   
    this['?'] = " * "   

    this['0'] = new array(height)   
    this['0'] = " * "   
    this['0'] = "* *"   
    this['0'] = "* *"   
    this['0'] = "* *"   
    this['0'] = " * "   
   
    this['1'] = new array(height)   
    this['1'] = " * "   
    this['1'] = " * "   
    this['1'] = " * "   
    this['1'] = " * "   
    this['1'] = " * "   

    this['2'] = new array(height)   
    this['2'] = "***"   
    this['2'] = "*"   
    this['2'] = "***"   
    this['2'] = "*"   
    this['2'] = "***"   
   
    this['3'] = new array(height)   
    this['3'] = "***"   
    this['3'] = "*"   
    this['3'] = "***"   
    this['3'] = "*"   
    this['3'] = "***"   
   
    this['4'] = new array(height)   
    this['4'] = "* *"   
    this['4'] = "* *"   
    this['4'] = "***"   
    this['4'] = "*"   
    this['4'] = "*"   

    this['5'] = new array(height)   
    this['5'] = "***"   
    this['5'] = "*"   
    this['5'] = "***"   
    this['5'] = "*"   
    this['5'] = "** "   

    this['6'] = new array(height)   
    this['6'] = "** "   
    this['6'] = "*"   
    this['6'] = "***"   
    this['6'] = "* *"   
    this['6'] = "***"   

    this['7'] = new array(height)   
    this['7'] = "***"   
    this['7'] = "*"   
    this['7'] = " * "   
    this['7'] = "*"   
    this['7'] = "*"   

    this['8'] = new array(height)   
    this['8'] = "***"   
    this['8'] = "* *"   
    this['8'] = "***"   
    this['8'] = "* *"   
    this['8'] = "***"   

    this['9'] = new array(height)   
    this['9'] = "***"   
    this['9'] = "* *"   
    this['9'] = "***"   
    this['9'] = "*"   
    this['9'] = "***"

}
function drawblank() {   
    // assign greater than symbol to variable   
    var gt = unescape("%3e")   
    document.write('<table border=2 cellpadding=8' + gt + '<tr' + gt + '<td width=468 bgcolor align="center" valign="center"' + gt)   
    // print entire board of off images   
    for (var y = 0; y < height; ++y) {      
      for (var x = 0; x < boardwidth; ++x) {            
            document.write('<img src="' + off.src + '" height=5 width=5' + gt)      
      }      
      document.write('<br' + gt)   
    }   
    document.write('</td' + gt + '</tr' + gt + '</table' + gt)
}

function setlight(state, x, y) {   
    // set a specific light in sign to on (true) or off (false)   
    if (state)      
      document.images.src = on.src   
    else      
      document.images.src = off.src
}

function drawletter(letter, startx) {   
    // draws a letter at the given x coordinate   
    for (var x = 0; x < width; ++x) {      
      for (var y = 0; y < height; ++y) {            
            setlight(letters.charat(x) == "*", startx + x, y)      
      }   
    }
}

function drawspace(startx) {   
    // create a small space between each two characters   
    for (var x = 0; x < space; ++x) {      
      for (var y = 0; y < height; ++y) {            
            setlight(false, startx + x, y)      
      }   
    }
}

function computeindex(x, y) {   
    // compute the document index of an image in the sign, based on the x-y coordinates   
    return (y * boardwidth + x) + imagenum
}

function floodboard(startx) {   
    // set all lights from startx to off   
    for (var x = startx; x < boardwidth; ++x) {      
      for (var y = 0; y < height; ++y) {            
            setlight(false, x, y)      
      }   
    }
}

function drawmessage(num) {   
    // initialize variable to current message   
    var text = messages      
    // initialize two counters (j - current character in message, i - current x coordinate)   
    var i = 0   
    var j = 0   
    while (1) {      
      if (text.charat(j) != " ") {            
            // draw current letter            
            drawletter(text.charat(j), i)               
            // increment i by the constant width of an image            
            i += width      
      }
      else {            
            // add an extra space (do not advance j yet)            
            drawspace(i)            
            i += space      
      }      
      // if j is less that index of last character      
      if (j < text.length - 1) {            
            drawspace(i)            
            i += space      
      }
      else
            // j is the index of the last character (lsat character already printed)
            break      
            // increment j by one because one letter was printed      
            ++j   
      }   
      // flood the remaining piece of the sign (turn it off)   
      floodboard(i)   
      // if message printed this time was not the last one in the array   
      if (num < messages.length - 1)      
            // val *must* be a global variable for use with the timeout      
            val = ++num   
      else      
            val = 0 // start cycle over again      
            // recursive call after waiting 3 seconds (some of the time already passed during printing)   
            timerid = settimeout("drawmessage(val)", 3000)
      }
      // open form
      document.write('<form>')
      // create initial sign (all sign is off)
      drawblank()

function startsign() {
    // wait 3 seconds and then call function to print first message
    drawmessage(0)
    running = true
}

function stopsign() {
    if(running)   
      cleartimeout(timerid)
      running = false
    }
    document.write('http://code.ik8.com/html/+<input type="button" value="start" onclick="startsign()">')
    document.write('<input type="button" value="stop" onclick="stopsign(); floodboard(0)">')
    document.write('</form>')
// -->
</script>
页: [1]
查看完整版本: 时间日期java-led