【编程游戏】贺岁霓虹灯。(参观33楼zswang的霓虹灯)

【编程游戏】贺岁霓虹灯。(第一名奖励10000可用分)

效果图

评分

参观 [目前Firefox中好使,其他浏览器需复制到本地,存为html文件看效果] <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>
参观 [目前Firefox中好使,其他浏览器需复制到本地,存为html文件看效果]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值