[Programming Game] presents a gift at the age of a new year. (Ignition of fireworks at yonghengdexingxing on floor 1-172)

Source: Internet
Author: User
[Programming Game] presents a gift at the age of a new year. (The first prize is 10000 available points)
Author:
Ignition[Ctrl + A select all tips: you can modify some code and then press run]

<HTML> <br/> <pead> </P> <p> <style type = "text/CSS"> <br/> body {<br/> background: #000000; <br/>}</P> <p>. firework {<br/> Height: 3px; <br/> width: 3px; <br/> overflow: hidden; <br/>}< br/> </style> </P> <p> <SCRIPT type = "text/JavaScript"> <br/> // position class <br /> // ================================================= ====< br/> function position (X, y) {<br/> This. X = x; <br/> This. y = y; <br/>}</P> <p> // velocity class <br/> // = =======================================================< Br /> Function Velocity (VX, vy) {<br/> This. VX = VX; <br/> This. vy = Vy; <br/>}</P> <p> // fallingbody class <br/> // ================== ======================================< br/> function fallingbody (color, initposition, initvelocity, inittime, lifespan, domnode, explodable) {<br/> This. initposition = initposition; <br/> This. initvelocity = initvelocity; <br/> This. inittime = inittime; <Br/> This. lifespan = lifespan; <br/> This. domnode = domnode; <br/> This. explodable = explodable; <br/> This. color = color; <br/>}</P> <p> fallingbody. prototype. show = function () {<br/> var interval = environment. clock-this. inittime; <br/> If (interval <0) return true; <br/> If (this. lifespan <= interval) {<br/> If (this. explodable) This. explode (250, 0.4); <br/> This. dispose (); <br/> return false; <br />}</P> <p> var x = math. ceil (this. initposition. X + this. initvelocity. VX * interval); <br/> var y = math. ceil (this. initposition. Y + this. initvelocity. vy * interval-environment. gravity * interval/2.0); <br/> If (! This. explodable) This. domnode. style. filter = "alpha (opacity =" + (1-interval/This. lifespan) * 100 + ")"; <br/> This. domnode. style. display = "Block"; <br/> This. domnode. style. left = x; <br/> This. domnode. style. top = y; <br/> return true; <br/>}</P> <p> fallingbody. prototype. dispose = function () {<br/> This. initposition = NULL; <br/> This. initvelocity = NULL; <br/> This. inittime = NULL; <br/> This. lifespa N = NULL; <br/> environment. screen. removechild (this. domnode); <br/> This. domnode = NULL; <br/>}</P> <p> fallingbody. prototype. explode = function (velocity, timespan) {<br/> var interval = environment. clock-this. inittime; <br/> var vx = This. initvelocity. VX; <br/> var Vy = This. initvelocity. vy-environment. gravity * interval; <br/> var x = math. ceil (this. initposition. X + this. initvelocity. VX * Inter Val); <br/> var y = math. ceil (this. initposition. Y + this. initvelocity. vy * interval-environment. gravity * interval/2.0); <br/> for (VAR I = 0; I <25; I ++) {<br/> var angle = math. random () * 360; <br/> environment. addfirework (this. color, new position (x, y), new velocity (VX + velocity * Math. cos (angle), Vy + velocity * Math. sin (angle), Environment. clock, timespan, false); <br/>}</P> <p> // init envir Ment <br/> // ====================================== ========< br/> var environment = new object (); </P> <p> environment. colors = ["# ff0000", "#00ff00", "# 000aff", "# ff00ff", "# ffa500", "# FFFF00", "#00ff00 ", "# ffffff", "# fffff0", "# ffa500", "#55ff66", "# ac9dfc", "# fff000", "# fffff0"]; </P> <p> environment. addfirework = function (color, initposition, initvelocity, inittime, lifespan, explodable) {<br/> var DIV = document. createeleme NT ("Div"); <br/> Div. style. position = "absolute"; <br/> Div. style. display = "NONE"; <br/> environment. screen. appendchild (DIV); <br/> Div. classname = "Firework"; <br/> Div. style. background = color; <br/> var fallingbody = new fallingbody (color, initposition, initvelocity, inittime, lifespan, Div, explodable); <br/> environment. fireworkarray. push (fallingbody); <br/>}</P> <p> environment. clocktick = Function () {<Br/> environment. clock + = environment. integer/1000.0; <br/> for (VAR I = environment. fireworkarray. length; I> 0; I --) {<br/> If (! Environment. fireworkarray [I-1]. show () environment. fireworkarray. splice (I-1, 1); <br/>}< br/> If (environment. fireworkarray. length> 0) setTimeout (environment. clocktick, environment. interval); <br/> else {<br/> environment. generate (); <br/> setTimeout (environment. clocktick, environment. interval); <br/>}</P> <p> environment. generate = function () {<br/> // environment. addfirework (environment. colors [math. floor (math. random () * environment. colors. length)], new position (300 + 600 * Math. random (), 600), new velocity (100,-330), Environment. clock, 1 + math. random () * 0.3, true); <br/> // environment. addfirework (environment. colors [math. floor (math. random () * environment. colors. length)], new position (300 + 600 * Math. random (), 600), new velocity (0,-300), Environment. clock, 1 + math. random () * 0.3, true); <br/> for (var k = 0; k <3; k ++) environment. addfirework (environment. colors [math. floor (math. random () * environment. colors. length)], new position (300 + 2 * Math. random (), 600), new velocity (20 * Math. random (),-360 + 100 * Math. random (), Environment. clock, 1-math.random () * 0.3, true); <br/> for (var k = 0; k <3; k ++) environment. addfirework (environment. colors [math. floor (math. random () * environment. colors. length)], new position (600 + 2 * Math. random (), 600), new velocity (20 * Math. random (),-360 + 100 * Math. random (), Environment. clock, 1-math.random () * 0.3, true); <br/>}</P> <p> window. onload = function () {<br/> environment. gravity =-10.0; <br/> environment. clock = 0.0; <br/> environment. interval = 10; // 0.1 seconds <br/> environment. screen = document. getelementsbytagname ("body") [0]; <br/> environment. fireworkarray = new array (); <br/> environment. generate (); <br/> setTimeout (environment. clocktick, environment. interval ); <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body> <br/> </body> <br/> </ptml> <br/>
Ignition[Ctrl + A select all tips: you can modify some code and then press run]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.