Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Community Boards > Just for Kicks Challenges

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-21-2007, 05:50 AM   #1
jsonchiu
Registered User
 
Join Date: Aug 2006
Posts: 482
Default 400 byte Mandelbrot

The challenge: create an image of the Mandelbrot Set by actionscript with only 400 bytes
Rules:
1. no "script is running slow" message, meaning that it must be either fast enough, or it must be a gradual animation like the one shown here

2. Must be good quality - 100 iterations

3. Must be colored by a gradient, not just 2 colors

Mine... 442 bytes (this is the best I can do, download it to view)
http://jsonchiu.prophp.org/flash/Mandelbrot2.swf

The code:
ActionScript Code:
import flash.display.BitmapData; var m:Number = 120; var w:Number = 300; var h:Number = 300; var b:BitmapData = new BitmapData(w, h); var i:Number = 0; var id:Number = setInterval(u, 1); function f(r:Number, i:Number):Number {     var X:Number = 0;     var Y:Number = 0;     var X2:Number = X * X;     var Y2:Number = Y * Y;     var t:Number = 0;     while (t < m && (X2 + Y2) < 100000)     {         var p:Number = X;         X = X2 - Y2 + r;         Y = 2 * p * Y + i;                 X2 = X * X;         Y2 = Y * Y;         t++;     }     return m - t; } function u():Void {     for (var j:Number = 0; j <= w; j++)     {         //in order to input the correct values for calculating         //we need to scale the x (equals j), y (equals i) values         //j -> (j - w / 2) / w * 2.7         //i -> (i - h / 2) / h * 2.7         var r:Number = f((j - w / 2) / w * 2.7 - 0.7, (i - h / 2) / h * 2.7);         //set grey pixels according to the number of iterations left         b.setPixel(j, i, r + r * 0x100 + r * 0x10000);     }     if (i < h)     {         i++;     }     else     {         clearInterval(id);     } } attachBitmap(b, 1);

Note: I strongly type every variable and declare return types because they won't effect the file size anyways. Also, comments don't add to file size either.
jsonchiu is offline   Reply With Quote
Old 04-21-2007, 07:16 PM   #2
jsonchiu
Registered User
 
Join Date: Aug 2006
Posts: 482
Default

394 bytes...
ActionScript Code:
import flash.display.BitmapData; m = 150; w = 300; h = 300; b = new BitmapData(w, h); i = 0; function f(r:Number, i:Number):Number {     var X:Number = 0;     var Y:Number = 0;     var X2:Number = 0;     var Y2:Number = 0;     var t:Number = 0;     while (t < m && (X2 + Y2) < 4)     {         Y = 2 * X * Y + i;         X = X2 - Y2 + r;                 X2 = X * X;         Y2 = Y * Y;         t++;     }     return m - t; } onEnterFrame = function() {     for (var j:Number = 0; j <= w; j++)     {         //in order to input the correct values for calculating         //we need to scale the x (equals j), y (equals i) values         //j -> (j - w / 2) / w * 3         //i -> (i - h / 2) / h * 3         //set green pixels according to the number of iterations left         b.setPixel(j, i, f((j - w / 2) / w * 3 - 1, (i - h / 2) / h * 3) * 256);     }     if (i < h)     {         i++;     }     else     {         onEnterFrame = null;     } } attachBitmap(b, 1);

Anyway to optimize that even more?
jsonchiu is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML socket and termination byte guillermo Flash ActionScript 2.0 3 09-06-2006 09:31 AM
actionscript byte limit metric152 ActionScript 2.0 0 07-07-2005 08:47 PM
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
0 byte terminator? what the? Dark_Element ActionScript 2.0 5 11-02-2004 04:12 AM


All times are GMT. The time now is 05:45 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.