/** * 25-Line ActionScript Contest Entry * * Project: Dandelion (interactive) * Author: David Wilhelm (dewilhelm@gmail.com) * Date: 19 November 2008 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ // 3 free lines! Alter the parameters of the following lines or remove them. // Do not substitute other code for the three lines in this section [SWF(width=800, height=800, backgroundColor=0x000000, frameRate=30)] stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; // 25 lines begins here! var vertices:Vector. = new Vector.(); var pvts:Vector. = new Vector.(); var spores:Vector. = new Vector.(); var sporesDct:Dictionary = new Dictionary(true); for(var lat:Number= 0; lat < Math.PI; lat+=0.01){ vertices.push( 10*Math.cos(lat*50)*Math.sin(lat), 10*Math.cos(lat), 10*Math.sin(lat*50)*Math.sin(lat), 70*Math.cos(lat*50)*Math.sin(lat), 70*Math.cos(lat), 70*Math.sin(lat*50)*Math.sin(lat), (70 + 10)*Math.cos(lat*50-Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat-Math.random()*0.05), (70 + 10)*Math.sin(lat*50-Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat*50+Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat-Math.random()*0.05), (70 + 10)*Math.sin(lat*50+Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat*50+Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat+Math.random()*0.05), (70 + 10)*Math.sin(lat*50+Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat*50-Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat+Math.random()*0.05), (70 + 10)*Math.sin(lat*50-Math.random()*0.1)*Math.sin(lat+Math.random()*0.05)); spores[spores.push(addChild(new Sprite()))-1].transform.matrix = new Matrix(1,0,0,1,stage.stageWidth/2,stage.stageHeight/2); sporesDct[spores[spores.length-1]] = {xp:70*Math.cos(lat*50)*Math.sin(lat),yp:70*Math.cos(lat),zp:70*Math.sin(lat*50)*Math.sin(lat), firstVertex: vertices.length-18, lastVertex: vertices.length-1, velocity: {xv:0, yv:0, zv:0, xr:0, yr:0, zr:0} }; spores[spores.length-1].addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {sporesDct[event.target]["velocity"]={xv:Math.random()*2 - 1, yv:Math.random()*2 - 1, zv:Math.random()*2 - 1, xr:Math.random()*2 - 1, yr:Math.random()*2 - 1, zr:Math.random()*2 - 1}}); } addEventListener(Event.ENTER_FRAME, function(event:Event):void { var m:Matrix3D = new PerspectiveProjection().toMatrix3D(); m.prependTranslation(0,0,10); spores.forEach(function(spore:Sprite, ind:int, a:Vector.):void { var spv:Vector. = new Vector.(); var m2:Matrix3D = new Matrix3D(); m2.appendTranslation(sporesDct[spore].velocity.xv,sporesDct[spore].velocity.yv,sporesDct[spore].velocity.zv); m2.appendRotation(0.5, sporesDct[spore].velocity.xv == 0 ? Vector3D.Y_AXIS:new Vector3D(sporesDct[spore].velocity.xr,sporesDct[spore].velocity.yr,sporesDct[spore].velocity.zr)); m2.transformVectors(vertices.slice(sporesDct[spore].firstVertex,sporesDct[spore].lastVertex+1),spv); vertices.splice(sporesDct[spore].firstVertex,18,spv[0],spv[1],spv[2],spv[3],spv[4],sporesDct[spore].zp = spv[5],spv[6],spv[7],spv[8],spv[9],spv[10],spv[11],spv[12],spv[13],spv[14],spv[15],spv[16],spv[17]); }); Utils3D.projectVectors(m, vertices, pvts, Vector.([])); for(var i:int = 0; i < pvts.length; i+=12){ spores[i/12].graphics.clear(); spores[i/12].graphics.drawGraphicsData(Vector.([new GraphicsStroke((100 - 2*sporesDct[spores[i/12]].zp)/100,false,LineScaleMode.NORMAL,CapsStyle.NONE,JointStyle.ROUND,3,new GraphicsSolidFill(0xFFFFFF,sporesDct[spores[i/12]].zp > -135 ? 1: 0)),new GraphicsPath(Vector.([1,2,2,1,2,1,2,1,2]),Vector.([ pvts[i],pvts[i+1], pvts[i+2],pvts[i+3], pvts[i+4],pvts[i+5], pvts[i+2],pvts[i+3], pvts[i+6],pvts[i+7], pvts[i+2],pvts[i+3], pvts[i+8],pvts[i+9], pvts[i+2],pvts[i+3], pvts[i+10],pvts[i+11]]))])); } }); // 25 lines ends here!