#define PI 3.1415926535897932384626433832795 kernel JuliaViewer < namespace : "Newgrounds"; vendor : "Newgrounds"; version : 1; description : "Julia Set Fractal Viewer"; > { parameter float2 viewPos< minValue: float2( -4.0, -4.0); maxValue: float2(4.0, 4.0); defaultValue: float2(0.0, 0.0); >; parameter float viewZoom< minValue: 0.5; maxValue: 200.0; defaultValue: 1.0; >; parameter float2 c< minValue: float2(-2.0, -2.0); maxValue: float2(2.0, 2.0); defaultValue: float2(0.0, 0.0); >; parameter float colorShift< minValue: -1.0; maxValue: 1.0; defaultValue: 0.0; >; const float RENDER_HEIGHT = 512.0; const float RENDER_WIDTH = 512.0; const int MAX_ITERATIONS = 256; const float MAX_DIST = 4.0; const pixel4 SET_COLOR = pixel4(0, 0, 0, 1.0); output pixel4 dst; region needed( region output_region, imageRef input_image ) { return nowhere(); } region changed( region input_region, imageRef input_image ) { return nowhere(); } region generated() { return region(float4(0, 0, RENDER_WIDTH, RENDER_HEIGHT)); } void evaluatePixel() { float2 z = float2( (outCoord().x*2.0/RENDER_WIDTH - 1.0 )/viewZoom + viewPos.x, (outCoord().y*2.0/RENDER_WIDTH - 1.0 )/viewZoom - viewPos.y ); float dist; float colorVal; int count = 0; do { z = float2(z.x*z.x - z.y*z.y + c.x, 2.0*z.x*z.y + c.y); dist = z.x*z.x + z.y*z.y; count++; } while(dist < MAX_DIST && count < MAX_ITERATIONS); if(count < MAX_ITERATIONS) { colorVal = float(count) + 1.0 - log2(log2(dist)); colorVal /= 50.0; colorVal += colorShift; dst = pixel4( abs( mod(colorVal, 2.0) - 1.0), abs( mod(colorVal+.33, 2.0) - 1.0), abs( mod(colorVal+.66, 2.0) - 1.0), 1.0 ); } else dst = SET_COLOR; } }