/** * 25-Line ActionScript Contest Entry * * Project: Jared Tarbell's Substrate in 25 lines * Author: Oliver "gencha" Salzburg ( gencha@dirty-motherfucker.org ) * Date: 2008-11-21 * * 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=1024, height=768, backgroundColor=0xffffff, frameRate=120)] stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; // 25 lines begins here! if( null == stack ) { var stack:Object = new Object(); stage.addChild( stack.t = new TextField() ); stack.timer = new Timer( ( ( stack.walker = new Array( stack.t.defaultTextFormat = new TextFormat( "Arial", 15 ) ) ) && ( this.addChild( new Bitmap( stack.canvas = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0xffffff ) ) ) ) ) ? 1 : 1 ); for( var walkerIdx:uint = ( stack.t.autoSize = TextFieldAutoSize.LEFT ); walkerIdx < int( stack.t.filters = [ new GlowFilter( 0xffffff, 1.0, 6.0, 6.0, 255.0 ) ] ) + 10; ++walkerIdx ) { stack.walker[ walkerIdx ] = new Object(); stack.walker[ walkerIdx ].birth = function( rebirth:uint ):void { if( rebirth & 1 ) stack.canvas.setPixel( Math.random() * stage.stageWidth, Math.random() * stage.stageHeight, int( Math.random() * 360 ) ); this.pos = new Point( Math.random() * stage.stageWidth, Math.random() * stage.stageHeight * ( stack.t.text = "Jared Tarbell's Substrate in 25 lines by gencha" ) ); if( ( rebirth & 2 ) && stack.walker.length < 400 ) stack.walker[ stack.walker.push( { birth:this.birth } ) - 1 ].birth( 4 ); while( ( rebirth & 4 ) && 0xffffff == stack.canvas.getPixel( this.pos.x, this.pos.y ) ) { this.pos = new Point( Math.random() * stage.stageWidth, Math.random() * stage.stageHeight ); } this.dir = ( uint( stack.canvas.getPixel( this.pos.x, this.pos.y ) + 90 * ( ( Math.random() > 0.5 ) ? 1 : -1 ) ) % 360 ) + ( Math.random() * 4 - 2 ); this.cur = ( Math.random() > 0.9 ) ? ( Math.random() * 0.4 - 0.2 ) : 0; } stack.walker[ walkerIdx ].birth( 1 | 4 ); } stack.timer.addEventListener( TimerEvent.TIMER, function mainLoop( event:TimerEvent ):void { if( 952 > stack.timer.currentCount ) for each( var walker:Object in stack.walker ) { stack.canvas.setPixel( int( 1 / int( walker.dir += walker.cur ) ) + walker.pos.x, walker.pos.y, ( Math.random() > 0.95 ) ? 0xfffffe : walker.dir ); walker.pos = walker.pos.add( new Point( 0.9 * Math.cos( walker.dir * ( Math.PI / 180 ) ), 0.9 * Math.sin( walker.dir * ( Math.PI / 180 ) ) ) ); if( !new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight ).containsPoint( walker.pos.add( new Point( 0.9 * Math.cos( walker.dir * ( Math.PI / 180 ) ), 0.9 * Math.sin( walker.dir * ( Math.PI / 180 ) ) ) ) ) || stack.canvas.getPixel( walker.pos.add( new Point( 0.9 * Math.cos( walker.dir * ( Math.PI / 180 ) ), 0.9 * Math.sin( walker.dir * ( Math.PI / 180 ) ) ) ).x, walker.pos.add( new Point( 0.9 * Math.cos( walker.dir * ( Math.PI / 180 ) ), 0.9 * Math.sin( walker.dir * ( Math.PI / 180 ) ) ) ).y ) != 0xffffff ) walker.birth( 2 | 4 ); } else { stack.canvas.fillRect( new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight ), 0xffffff ); var n:Boolean = ( ( stack.walker.splice( 10 ) ) && ( stack.timer.reset() == undefined ) && ( stack.timer.start() == undefined ) ); for each( var w:Object in stack.walker ) w.birth( 1 | 4 ); } } ); stack.timer.start(); } // 25 lines ends here!