本帖最后由 zswang 于 2010-01-14 11:19:29 编辑

解决方案 »

  1.   

    顶一下先,要是用 Flash + AS 效果好滴多,JS 做图形真有些费劲
      

  2.   

    我先来第一个,作为示例
    <html>
    <head><title>贺岁霓虹灯 -- 万家灯火 -- 作者:zswang</title></head>
    <style>
    body{overflow:hidden;background-color:Black;}
    </style>
    <body>
    <script text="text/javascript">
    function hsl2color(hsl) {
    if (hsl.h > 360 || hsl.h < 0 || hsl.s > 100 || hsl.s < 0 || hsl.l > 100 || hsl.l < 0)
    return "#000000";
    var rgb = {r: 0, g: 0, b: 0};
    if (hsl.h <= 60) {
    rgb.r = 255;
    rgb.g = 255 / 60 * hsl.h;
    } else if (hsl.h <= 120) {
    rgb.r = 255 - (255 / 60) * (hsl.h - 60);
    rgb.g = 255;
    } else if (hsl.h <= 180) {
    rgb.g = 255;
    rgb.b = (255 / 60) * (hsl.h - 120);
    } else if (hsl.h <= 240) {
    rgb.g = 255 - (255 / 60) * (hsl.h - 180);
    rgb.b = 255;
    } else if (hsl.h <= 300) {
    rgb.r = (255 / 60) * (hsl.h - 240);
    rgb.b = 255;
    } else if (hsl.h <= 360) {
    rgb.r = 255;
    rgb.b = 255 - (255 / 60) * (hsl.h - 300);
    }
    var sat = Math.abs((hsl.s - 100) / 100);
    rgb.r = rgb.r - (rgb.r - 128) * sat;
    rgb.g = rgb.g - (rgb.g - 128) * sat;
    rgb.b = rgb.b - (rgb.b - 128) * sat;
    var lum = (hsl.l - 50) / 50;
    if (lum > 0) {
    rgb.r = rgb.r + (255 - rgb.r) * lum;
    rgb.g = rgb.g + (255 - rgb.g) * lum;
    rgb.b = rgb.b + (255 - rgb.b) * lum;
    } else if (lum < 0) {
    rgb.r = rgb.r + rgb.r * lum;
    rgb.g = rgb.g + rgb.g * lum;
    rgb.b = rgb.b + rgb.b * lum;
    }
    return "#" + ("00000" + (Math.floor(rgb.r) * 256 * 256 + 
    Math.floor(rgb.g) * 256 + Math.floor(rgb.b)
    ).toString(16)).replace(/^.*(.{6}$)/g, "$1");
    }// 霓虹灯
    function Neon(options) {
    options = options || {};
    this.interval = options.interval || 500; // 变化间隔时间,单位毫秒
    this.parent = options.parent || document.body; // 容器
    this.bulbCount = options.bulbCount || 100;
    this.bulbs = {};
    var h = document.body.clientHeight || document.documentElement.clientHeight;
    var w = document.body.clientWidth || document.documentElement.clientWidth;
    for (var i = 0; i < this.bulbCount; i++) {
    this.bulbs[i] = new Bulb({
    size: 10 + Math.random() * 10,
    pos: {x: Math.random() * w, y: Math.random() * h},
    hue: Math.random() * 360,
    lightness: Math.random() * 100
    });
    }
    }Neon.prototype = {
    replay: function() {
    var self = this;
    setInterval(function() { self.tick(); }, this.interval);
    },
    tick: function() {
    for (var i = 0; i < this.bulbCount; i++) {
    this.bulbs[i].lightness = (this.bulbs[i].lightness + 2) % 100;
    this.bulbs[i].doChange();
    }
    }
    }// 灯泡
    function Bulb(options) {
    options = options || {};
    this.parent = options.parent || document.body; // 容器
    this.shape = options.shape || "●"; // 形状
    this.size = options.size || 12; // 大小
    this.pos = options.pos || {}; // 位置
    this.hue = options.hue || 100; // 色相
    this.saturation = options.saturation || 100; // 饱和度
    this.lightness = options.lightness || 50; // 亮度 this.span = document.createElement("span");
    this.parent.appendChild(this.span);
    this.span.style.position = "absolute";
    this.span.style.fontSize = this.size + "px";
    this.span.style.left = this.pos.x + "px";
    this.span.style.top = this.pos.y + "px";
    this.span.innerHTML = this.shape;
    this.doChange();
    }Bulb.prototype = {
    doChange: function() {
    this.span.style.color = hsl2color(
    {h: this.hue, s: this.saturation, l: this.lightness}
    );
    }
    }new Neon().replay();
    </script>
    </body>
    </html>
      

  3.   

    楼主把形状换成
     this.shape = options.shape || "★"; // 形状
    看起来更绚丽些
      

  4.   

    good good study 
    day day upup!