| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,187
|
You may have seen a 256 byte JavaScript StarField effect being discussed on Digg .
When I first saw it, I was certain I could achieve an equally small and nearly identical effect with ActionScript, but now I'm not so sure. There are 3 parts to this challenge. First, replicate the effect with ActionScript alone, this is good practice for the newbies. Second, condense the text used in your code to a "TXT" or "AS" file no greater than 256 bytes in size. Third, compile your script to a SWF file smaller than 256 bytes. As an example, the following code compiles to a 376 byte SWF file (use 550x400, black background and 32 FPS). ActionScript Code:
The above code with white space removed looks like the following and creates a 273 byte TXT or AS file: Code:
i=0;_x=275;_y=200;m=Math;onEnterFrame=function(){c=createEmptyMovieClip("c"+i,++i);c.lineStyle(2,0xFFFFFF);c.lineTo(1,0);c._alpha=0;c.d=1;c.r=m.random()*m.PI*2;c.onEnterFrame=function(){with(this){d*=1.1;if(d>300)removeMovieClip();_alpha=d/2;_x=m.cos(r)*d;_y=m.sin(r)*d;}}}
Good luck and happy Flashing. -PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. Last edited by pixelwit; 03-14-2007 at 06:10 PM.. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Apr 2003
Location: Salinas, California
Posts: 210
|
Interesting challenge
![]() First of all here is your code shortened to 236 bytes (when whitespace is removed): ActionScript Code:
and the compressed version: ActionScript Code:
The .swf version is now 344 bytes. Here are the changes I made: 1. Most of the bytes were saved by not removing the movieclips when d > 300. Instead the movieclips are written over by creating new mcs at the same depth. 2. set root _y = _x instead of different values. 3. Instead of using Math.PI*2 just rounded to 6 |
|
|
|
|
|
|
|
|
#3 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,187
|
Nice.
Overwriting the clips sounds like a good idea, as long as it doesn't create a memory issues I'm all for it. I really like the ++% bit. I've always been a fan of both ++ and % but never thought to combine them as such. I considered setting _x and _y to the same coordinates but a square screen varies a bit from the JavaScript original. I'd hoped to post a link directly to a SWF file (not embedded in a HTML page) which would load in the browser and replicate the JS effect as closely as possible. I'm willing to make concessions though. ![]() 6 is nowhere near 6.28318530717959! Good thinking. If you're going to use an integer, you could get away with using random(7) rather than m.random()*6. (EDIT: Oops, never mind, that only returns integers.)Looks like getting a 256B SWF is going to be a real tough one to crack. Thanks for taking up the challenge. -PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. Last edited by pixelwit; 03-15-2007 at 02:12 AM.. |
|
|
|
|
|
#4 |
|
Registered User
Join Date: Apr 2007
Posts: 2
|
Hello,
I wrote the above ( or is it below ? ) mentionned 256b 3D Starfield in JavaScript. It's nice to see some ActionScript'ers giving a try at hardcore size optimization. The only ActionScript I made was a tiny ( ~170bytes ) mp3 player for JavaScript were I passed the URL of the music in GET and had a method to start/stop the replay once a variable exposed to JavaSscript was set. All this was done using a Flash 8 assembler/disassembler. Is there any more practical tool ... and free. ActionScript 3 look really interresting. If ever 256b is not challenging enough, I shrinked the 3D Starfield effect to 209 bytes ( and even 207b but it doesn't look as good ), and also made a 256b Mandelbrot rotozoom in JavaScript. Happy optimization ![]() |
|
|
|
|
|
#5 | |
|
Registered User
Join Date: Apr 2003
Location: Salinas, California
Posts: 210
|
Quote:
I use Flashdevelop for Actionscript projects, it can be setup to compile AS3: http://www.flashdevelop.org/community/ I think the flash code for just opening a movie is too much overhead to make a 256byte swf but it is a challenge trying. ![]() |
|
|
|
|
|
|
#6 |
|
Registered User
Join Date: Apr 2007
Posts: 2
|
Thanks for hint.
There's a couple of Flash entries in the 256b.htm contests. But that was probably Flash 7 or less at the time. |
|
|
|
|
|
#7 |
|
Registered User
Join Date: Jun 2005
Posts: 20
|
160 bytes, using the same math trick as in the JS starfield
Code:
_x=_y=k=200
c=Math.cos
onEnterFrame=function(){
clear()
for(i=0;i<65;){
z=2000/(73-(++i+k++&63))
lineStyle(2,-1,z-20)
moveTo(x=z*c(i*.9),y=z*c(i))
lineTo(x+1,y)
}
}
|
|
|
|
|
|
#8 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,187
|
Hey, it's good to see there's still some interest in this.
Hi P01, glad you could stop by to see the challenge which you helped inspire. The ASCII Mandelbrot is pretty neat too. Nice adaptation of the JS code Monsieurfil. I might have tried the same but I wasn't comfortable using code I didn't fully understand. I'm guessing 63 is related to PI, but other than that I'm at a loss. I'm not sure if anyone will be able to get the SWF file size down to 256 bytes, but Monsieurfil's code compiles to a 315 byte SWF and that's as close as anyone has come so far. -PiXELWIT http://www.pixelwit.com
__________________
There are no answers, only choices. |
|
|
|
|
|
#9 |
|
Registered User
Join Date: Jun 2005
Posts: 20
|
The JS code is a pretty clever mathematical trick wich has nothing to do with PI (and I can't pretend I got it fully).
I think that getting under 256bytes will require to manually optimize the SWF binary - I'll try that ![]() |
|
|
|
|
|
#10 |
|
as[org].addListener(this)
Join Date: Dec 2005
Location: LA, California
Posts: 838
|
Ah interesting.....never saw something written like that.....
the &63 in (++i+k++&63) is a bitwise AND evaluation between the left side and 63. The significance of 63 is that its one less than 64 (2^6). This becomes 111111 in binary...which means it always satisfies the evaluation of the first 6 binary digits, and none after that. Basically this results in a loop effect of the value being returned. It could have just as easily been written as (++i+k++%64) |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Starfield Class | MichaelxxOA | ActionScript 2.0 | 8 | 05-26-2006 08:35 PM |
| stop starfield? | Bsouth | ActionScript 1.0 (and below) | 2 | 02-13-2006 05:13 PM |
| Modified starfield effect. (Changing many movieclips after creation) | cmh84 | ActionScript 2.0 | 4 | 03-09-2005 03:38 AM |
| Sending 1 byte data over 127?! | anarkizt | ActionScript 2.0 | 2 | 12-27-2004 08:27 AM |
| That dreaded null byte again | apesaga | Server-Side Scripting | 0 | 12-16-2004 12:14 PM |