Created
September 8, 2013 18:18
-
-
Save ryzed/6487141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.events.Event; | |
import flash.geom.Rectangle; | |
import flash.Lib; | |
import flash.text.TextField; | |
import flash.Vector; | |
import net.hires.debug.Stats; | |
/** | |
* ... | |
* @author ... | |
*/ | |
class MandelTest | |
{ | |
public var stW:Int; | |
public var stH:Int; | |
public var srcPixels:Vector<UInt>; | |
public var outPixels:Vector<UInt>; | |
public var bdrc:Rectangle; | |
public var colorModifier:Int; | |
private var bitmapData:BitmapData; | |
private var fps:TextField; | |
public var maxFPS:Int; | |
public function new() | |
{ | |
var stage = Lib.current.stage; | |
var w = Std.int(stage.stageWidth); | |
var h = Std.int(stage.stageHeight); | |
stW = w; | |
stH = h; | |
bitmapData = new BitmapData(w, h, false, 0x000000); | |
stage.addChild( new Bitmap(bitmapData) ); | |
var maxIterations = 128; | |
bdrc = bitmapData.rect; | |
srcPixels = new Vector<UInt>(w * h, true); | |
outPixels = new Vector<UInt>(w * h, true); | |
var beforeTime = flash.Lib.getTimer(); | |
var xtemp; | |
var iteration; | |
var x0:Float = 0; | |
var y0:Float = 0; | |
var adr = 0; | |
var iy = 0; | |
while (iy < h ) | |
{ | |
var ix = 0; | |
while (ix < w) | |
{ | |
x0 = 0; | |
y0 = 0; | |
iteration = 128; | |
while ( x0*x0 + y0*y0 <= 4 && iteration > 0 ) | |
{ | |
xtemp = x0 * x0 - y0 * y0 + (ix - 14 * 5000) / 50000; | |
y0 = 2 * x0 * y0 + (iy - (h / 0.6)) / 50000; | |
x0 = xtemp; | |
iteration--; | |
} | |
srcPixels[adr++] = iteration; | |
ix++; | |
} | |
iy++; | |
} | |
var afterTime = flash.Lib.getTimer(); | |
var tf = new TextField(); | |
tf.width = 400; | |
tf.text = "Generating fractal took "+(afterTime-beforeTime)+" ms"; | |
stage.addChild(tf); | |
fps = new TextField(); | |
fps.width = 400; | |
fps.y = 10; | |
fps.text = "FPS: "; | |
stage.addChild(fps); | |
var st = new Stats(); | |
st.y = 50; | |
stage.addChild(st); | |
colorModifier = 2; | |
var timer:haxe.Timer = new haxe.Timer(5); | |
runLoop(); | |
timer.run = runLoop; | |
} | |
public function runLoop() | |
{ | |
var w = stW; | |
var h = stH; | |
var cm = colorModifier; | |
var bd = bitmapData; | |
var sPixels = srcPixels; | |
var oPixels = outPixels; | |
var len = w * h; | |
var beforeTime = flash.Lib.getTimer(); | |
var adr = 0; | |
while (adr < len) | |
{ | |
var r = sPixels[adr] + cm; | |
var g = r + r; | |
oPixels[adr++] = ((r << 16) | (g << 8) | (r + g)); | |
} | |
bd.setVector(bdrc, oPixels); | |
var afterTime = flash.Lib.getTimer(); | |
var dt = afterTime-beforeTime; | |
var curFPS = Math.round(1000/(afterTime-beforeTime)); | |
if ( curFPS > maxFPS ){ | |
maxFPS = curFPS; | |
} | |
fps.text = "FPS: " + curFPS + ", dt="+dt+"\rMax FPS: " + maxFPS; | |
colorModifier += 2; | |
if(colorModifier > 65530) | |
colorModifier = 0; | |
} | |
static function main() : Void | |
{ | |
new MandelTest(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
while ( x0_x0 + y0_y0 <= 4 && iteration > 0 )
стоит поменять местами операнды в &&