[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]
Note that you can adjust the following parameters according to your preferences to achieve the desired effect.
VaR G = 6; // acceleration of gravity
VaR t_step = Window. activexobject? 0.5: 0.3; // time unit. The smaller the image, the more delicate it is.
VaR main_blaze_size = 15; // main fireshow size (PX)
VaR blaze_size = 15; // individual fireworks size (PX) after opening)
VaR blaze_count = 20; // Number of fireworks to be blasted
VaR blaze_lasts = 8; // duration of the fireshow
VaR blaze_max_speed = 20; // The maximum initial speed of the fireworks.
VaR track_size = 15; // the size of a single fireshow track
VaR track_interval = 2; // interval of Trajectory Generation
VaR track_lasts = 2; // trajectory duration
VaR fw_style = [["*",". "], [" ^ ",". "], [" * "," * "], [". ",". "], [" O ",". "], [" O "," O "]; // fireworks style. The front is the fireworks style, and the back is the track style.
VaR total_fireworks = 2; // Number of fireworks simultaneously on the screen
<! Doctype HTML public "-// W3C // dtd html 4.01 // en" "http://www.w3.org/TR/html4/strict.dtd"> <br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = utf8 "/> <br/> <title> X fireworks </title> <br/> <style> <br/> body {<br/> background-color: #000; <br/> overflow: hidden; <br/>}< br/> </style> <br/> <SCRIPT type = "text/JavaScript"> <br/>/* A zhangyx production. enjoy it! */<Br/> var H = document.doc umentelement. clientheight; <br/> var W = document.doc umentelement. clientwidth; <br/> var G = 3; <br/> var offset_bottom = 50; <br/> var t_step = Window. activexobject? 0.5: 0.3; <br/> var main_blze_size = 15; <br/> var main_blze_lasts = math. floor (math. SQRT (2 * (H-offset_bottom)/g); <br/> var blaze_size = 15; <br/> var blaze_count = 20; <br/> var blaze_angle = 2 * Math. PI/blaze_count; <br/> var blaze_lasts = 12; <br/> var blaze_max_speed = 20; <br/> var track_size = 15; <br/> var track_interval = 2; <br/> var track_lasts = 4; <br/> var fw_style = [["*",". "], [" ^ ",". "], [" * "," * "], [". ",". "], [" O ",". "], [" O "," O "]; <br/> var total_fireworks = 2; <br/> function fireworks () {<br/> This. engine = new physicalengine (); <br/> This. status = fireworks. init; <br/> This. blazes = []; <br/> This. tracks = []; <br/> This. intervalcounter = 0; <br/>}< br/> fireworks. init = 0 <br/> fireworks. rising = 1; <br/> fireworks. pre_blaze = 2; <br/> fireworks. blaze = 3; <br/> fireworks. de AD = 4; <br/> fireworks. prototype = {<br/> step: function () {<br/> switch (this. status) {<br/> case fireworks. init: <br/> This. blazes. push (this. engine. getmainblaze (); <br/> This. status = fireworks. rising; <br/> break; <br/> case fireworks. rising: <br/> This. _ commonmanagement (); <br/> If (this. blazes [0]. lasts <= 0) {<br/> This. status = fireworks. pre_blaze; <br/>}< br/> break; <br/> case fireworks. pre_blaze: <Br/> This. engine. getblazes (this. blazes); <br/> document. body. removechild (this. blazes [0]); <br/> This. blazes. shift (); <br/> This. status = fireworks. blaze; <br/> break; <br/> case fireworks. blaze: <br/> This. _ commonmanagement (); <br/> If (this. blazes [0]. color. r <= 0) {<br/> This. status = fireworks. dead; <br/>}< br/> break; <br/> case fireworks. dead: <br/> var remove = function (CON) {<br/> while (con. length! = 0) {<br/> document. body. removechild (CON [0]); <br/> con. shift (); <br/>}< br/>}; <br/> remove (this. blazes); <br/> remove (this. tracks); <br/> break; <br/>}< br/>}, <br/> _ commonmanagement: function () {<br/> This. intervalcounter ++; <br/> This. intervalcounter % = track_interval; <br/> var length = This. blazes. length; <br/> for (VAR I = 0; I <length; I ++) {<br/> var blze = This. blazes [I]; <br/> This. engine. transblaze (this. blazes [I]); <br/> If (this. intervalcounter = 0) {<br/> This. tracks. push (this. engine. gettrack (Blaze); <br/>}< br/> var length = This. tracks. length; <br/> for (VAR I = 0; I <length; I ++) {<br/> var track = This. tracks [I]; <br/> This. engine. transtrack (track); <br/> If (track. lasts <= 0) {<br/> This. tracks. shift (); <br/> length --; <br/> I --; <br/> document. body. removechild (track); <br/>}< br/>}; <br/> function physicalengine () {<br/> var style = fw_style [math. round (fw_style.length-1) * Math. random ()]; <br/> This. blazechar = style [0]; <br/> This. trackchar = style [1]; <br/>}< br/> physicalengine. prototype = {<br/> getmainblze: function () {<br/> var blze = document. createelement ("Div"); <br/> blaze. style. position = "absolute"; <br/> blaze. style. zindex = 100; <br/> blaze. lasts = main_blaze_lasts * (1 + math. random ()/2; <br/> blaze. color = {<br/> r: 255 * Math. random (), <br/> G: 255 * Math. random (), <br/> B: 255 * Math. random () <br/>}; <br/> blaze. path = {<br/> X: math. round (w * Math. random (), <br/> Y: H-offset_bottom <br/>}; <br/> blze. speed = {<br/> X: 0, <br/> Y:-G * Blaze. lasts <br/>}; <br/> blaze. size = main_blaze_size; <br/> blaze. color. rD = blaze. color. r/blaze. lasts * t_step; <br/> blaze. color. GD = blaze. color. g/blaze. lasts * t_step; <br/> blaze. color. BD = blaze. color. b/blaze. lasts * t_step; <br/> blaze. speed. XD = 0; <br/> blaze. speed. YD = g * t_step; <br/> blaze. innerhtml = This. blazechar; <br/> This. _ setcss (Blaze); <br/> document. body. appendchild (Blaze); <br/> return blaze; <br/>}, <br/> getblazes: function (blazes) {<br/> var mainblaze = blazes [0]; <br/> var speed = (1 + math. random ()/2 * blaze_max_speed; <br/> var speedtype = math. round (math. random (); <br/> var acctype = math. round (math. random (); <br/> for (VAR I = 0; I <blaze_count; I ++) {<br/> var blaze = document. createelement ("Div"); <br/> blaze. style. position = "absolute"; <br/> blaze. style. zindex = 100; <br/> blaze. lasts = blaze_lasts; <br/> blaze. color = {<br/> r: 255 * Math. random (), <br/> G: 255 * Math. random (), <br/> B: 255 * Math. random () <br/>}; <br/> blaze. path = {<br/> X: mainblaze. path. x, <br/> Y: mainblaze. path. Y <br/>}; <br/> If (speedtype) {<br/> blaze. speed = {<br/> X: Speed * Math. cos (blaze_angle * I), <br/> Y: Speed * Math. sin (blaze_angle * I) <br/>}< br/>} else {<br/> blaze. speed = {<br/> X: (1 + math. random ()/2 * blaze_max_speed * Math. cos (blaze_angle * I), <br/> Y: (1 + math. random ()/2 * blaze_max_speed * Math. sin (blaze_angle * I) <br/>}< br/> blaze. size = blaze_size; <br/> blaze. color. rD = blaze. color. r/blaze_lasts * t_step <br/> blaze. color. GD = blaze. color. g/blaze_lasts * t_step <br/> blaze. color. BD = blaze. color. b/blaze_lasts * t_step <br/> If (acctype) {<br/> blaze. speed. XD = blaze. speed. x/blaze_lasts * t_step; <br/> blaze. speed. YD = (blaze. speed. y/blaze_lasts + G) * t_step; <br/>} else {<br/> blaze. speed. XD = 0; <br/> blaze. speed. YD = 0; <br/>}< br/> blaze. innerhtml = This. blazechar; <br/> This. _ setcss (Blaze); <br/> document. body. appendchild (Blaze); <br/> blazes. push (Blaze); <br/>}< br/>}, <br/> gettrack: function (Blaze) {<br/> var track = document. createelement ("Div"); <br/> track. style. position = "absolute"; <br/> track. style. zindex = 50; <br/> track. lasts = track_lasts <br/> track. color = {<br/> r: blaze. color. r, <br/> G: blaze. color. g, <br/> B: blaze. color. B <br/>}< br/> track. path = {<br/> X: blaze. path. x, <br/> Y: blaze. path. Y <br/>}; <br/> track. size = track_size; <br/> track. color. rD = track. color. r/track. lasts * t_step; <br/> track. color. GD = track. color. g/track. lasts * t_step; <br/> track. color. BD = track. color. b/track. lasts * t_step; <br/> track. innerhtml = This. trackchar; <br/> This. _ setcss (track); <br/> document. body. appendchild (track); <br/> return track; <br/>}, <br/> transblaze: function (blze) {<br/> blze. color. r-= blaze. color. rd; <br/> blze. color. g-= blaze. color. GD; <br/> blaze. color. b-= blaze. color. BD; <br/> blze. path. X + = blaze. speed. x * t_step; <br/> blaze. path. Y + = blaze. speed. y * t_step; <br/> blaze. speed. X + = blaze. speed. XD; <br/> blaze. speed. Y + = blaze. speed. YD; <br/> blaze. lasts-= t_step; <br/> This. _ setcss (Blaze); <br/>}, <br/> transtrack: function (track) {<br/> track. color. r-= track. color. rd; <br/> track. color. g-= track. color. GD; <br/> track. color. b-= track. color. BD; <br/> track. lasts-= t_step; <br/>}, <br/> _ setcss: function (OBJ) {<br/> var style = obj. style; <br/> style. left = math. floor (obj. path. x) + "PX"; <br/> style. top = math. floor (obj. path. y) + "PX"; <br/> style. fontsize = obj. size + "PX"; <br/> style. color = "RGB (" + math. floor (obj. color. r) + "," + math. floor (obj. color. g) + "," + math. floor (obj. color. b) + ")"; <br/>}< br/>}; <br/> function setout () {<br/> var Container = []; <br/> for (VAR I = 0; I <total_fireworks; I ++) {<br/> container. push (New fireworks (); <br/>}< br/> window. setinterval (function () {<br/> for (VAR I = 0; I <total_fireworks; I ++) {<br/> container [I]. step (); <br/> If (container [I]. status = fireworks. dead) {<br/> container [I]. step (); <br/> container [I] = new fireworks (); <br/>}< br/>}, 10 ); <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body onload = "setout (); "> </body> <br/> </ptml>
Ignition[Ctrl + A select all tips: you can modify some code and then press run]