September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
51
Task/Mandelbrot-set/EC/mandelbrot-set-1.ec
Normal file
51
Task/Mandelbrot-set/EC/mandelbrot-set-1.ec
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
void drawMandelbrot(Bitmap bmp, float range, Complex center, ColorAlpha * palette, int nPalEntries, int nIterations, float scale)
|
||||
{
|
||||
int x, y;
|
||||
int w = bmp.width, h = bmp.height;
|
||||
ColorAlpha * picture = (ColorAlpha *)bmp.picture;
|
||||
double logOf2 = log(2);
|
||||
Complex d
|
||||
{
|
||||
w > h ? range : range * w / h,
|
||||
h > w ? range : range * h / w
|
||||
};
|
||||
Complex C0 { center.a - d.a/2, center.b - d.b/2 };
|
||||
Complex C = C0;
|
||||
double delta = d.a / w;
|
||||
|
||||
for(y = 0; y < h; y++, C.a = C0.a, C.b += delta)
|
||||
{
|
||||
for(x = 0; x < w; x++, picture++, C.a += delta)
|
||||
{
|
||||
Complex Z { };
|
||||
int i;
|
||||
double ii = 0;
|
||||
bool out = false;
|
||||
double Za2 = Z.a * Z.a, Zb2 = Z.b * Z.b;
|
||||
for(i = 0; i < nIterations; i++)
|
||||
{
|
||||
double z2;
|
||||
Z = { Za2 - Zb2, 2*Z.a*Z.b };
|
||||
Z.a += C.a;
|
||||
Z.b += C.b;
|
||||
Za2 = Z.a * Z.a, Zb2 = Z.b * Z.b;
|
||||
z2 = Za2 + Zb2;
|
||||
|
||||
if(z2 >= 2*2)
|
||||
{
|
||||
ii = (double)(i + 1 - log(0.5 * log(z2)) / logOf2);
|
||||
out = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(out)
|
||||
{
|
||||
float si = (float)(ii * scale);
|
||||
int i0 = ((int)si) % nPalEntries;
|
||||
*picture = palette[i0];
|
||||
}
|
||||
else
|
||||
*picture = black;
|
||||
}
|
||||
}
|
||||
}
|
||||
135
Task/Mandelbrot-set/EC/mandelbrot-set-2.ec
Normal file
135
Task/Mandelbrot-set/EC/mandelbrot-set-2.ec
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
class Mandelbrot : Window
|
||||
{
|
||||
caption = $"Mandelbrot";
|
||||
borderStyle = sizable;
|
||||
hasMaximize = true;
|
||||
hasMinimize = true;
|
||||
hasClose = true;
|
||||
clientSize = { 600, 600 };
|
||||
|
||||
Point mouseStart, mouseEnd;
|
||||
bool dragging;
|
||||
bool needUpdate;
|
||||
|
||||
float scale;
|
||||
int nIterations; nIterations = 256;
|
||||
ColorAlpha * palette;
|
||||
int nPalEntries;
|
||||
Complex center { -0.75, 0 };
|
||||
|
||||
float range; range = 4;
|
||||
Bitmap bmp { };
|
||||
|
||||
Mandelbrot()
|
||||
{
|
||||
static ColorKey keys[] =
|
||||
{
|
||||
{ navy, 0.0f },
|
||||
{ Color { 146, 213, 237 }, 0.198606268f },
|
||||
{ white, 0.3f },
|
||||
{ Color { 255, 255, 124 }, 0.444250882f },
|
||||
{ Color { 255, 100, 0 }, 0.634146333f },
|
||||
{ navy, 1 }
|
||||
};
|
||||
|
||||
nPalEntries = 30000;
|
||||
palette = new ColorAlpha[nPalEntries];
|
||||
scale = nPalEntries / 175.0f;
|
||||
PaletteGradient(palette, nPalEntries, keys, sizeof(keys)/sizeof(keys[0]), 1.0);
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
~Mandelbrot() { delete palette; }
|
||||
|
||||
void OnRedraw(Surface surface)
|
||||
{
|
||||
if(needUpdate)
|
||||
{
|
||||
drawMandelbrot(bmp, range, center, palette, nPalEntries, nIterations, scale);
|
||||
needUpdate = false;
|
||||
}
|
||||
surface.Blit(bmp, 0,0, 0,0, bmp.width, bmp.height);
|
||||
|
||||
if(dragging)
|
||||
{
|
||||
surface.foreground = lime;
|
||||
surface.Rectangle(mouseStart.x, mouseStart.y, mouseEnd.x, mouseEnd.y);
|
||||
}
|
||||
}
|
||||
|
||||
bool OnLeftButtonDown(int x, int y, Modifiers mods)
|
||||
{
|
||||
mouseEnd = mouseStart = { x, y };
|
||||
Capture();
|
||||
dragging = true;
|
||||
Update(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnLeftButtonUp(int x, int y, Modifiers mods)
|
||||
{
|
||||
if(dragging)
|
||||
{
|
||||
int dx = Abs(mouseEnd.x - mouseStart.x), dy = Abs(mouseEnd.y - mouseStart.y);
|
||||
if(dx > 4 && dy > 4)
|
||||
{
|
||||
int w = clientSize.w, h = clientSize.h;
|
||||
float rangeX = w > h ? range : range * w / h;
|
||||
float rangeY = h > w ? range : range * h / w;
|
||||
|
||||
center.a += ((mouseStart.x + mouseEnd.x) - w) / 2.0f * rangeX / w;
|
||||
center.b += ((mouseStart.y + mouseEnd.y) - h) / 2.0f * rangeY / h;
|
||||
|
||||
range = dy > dx ? dy * range / h : dx * range / w;
|
||||
|
||||
needUpdate = true;
|
||||
Update(null);
|
||||
}
|
||||
ReleaseCapture();
|
||||
dragging = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnMouseMove(int x, int y, Modifiers mods)
|
||||
{
|
||||
if(dragging)
|
||||
{
|
||||
mouseEnd = { x, y };
|
||||
Update(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnRightButtonDown(int x, int y, Modifiers mods)
|
||||
{
|
||||
range = 4;
|
||||
nIterations = 256;
|
||||
center = { -0.75, 0 };
|
||||
needUpdate = true;
|
||||
Update(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnResize(int width, int height)
|
||||
{
|
||||
bmp.Allocate(null, width, height, 0, pixelFormat888, false);
|
||||
needUpdate = true;
|
||||
Update(null);
|
||||
}
|
||||
|
||||
bool OnKeyHit(Key key, unichar ch)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case space: case keyPadPlus: case plus:
|
||||
nIterations += 256;
|
||||
needUpdate = true;
|
||||
Update(null);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Mandelbrot mandelbrotForm {};
|
||||
Loading…
Add table
Add a link
Reference in a new issue