' ----------------------------------------------------------------
' Oct 25, 2015 Thanks Peter Wirbelauer, http://www.oxygenbasic.org
' ----------------------------------------------------------------
' ------------------------- Compiler Stuff -----------------------
#Define page CreateCompatibleDC
Macro CalcClient() = SetRect(@R, 50, 50, 562, 562) + AdjustWindowRectEx(@R, &HCF0000, FALSE, &H100)
Macro CreatePage() = Resize(ME, 0, 0, R[2] - R[0], R[3] - R[1]) + Fbsl.GetClientRect(ME, 0, 0, W, H) _
+ CreateCompatibleDC(GetDC(ME)) + DeleteObject(SelectObject(page, CreateCompatibleBitmap(GetDC, W, H))) _
+ SetStretchBltMode(GetDC, 4) + SetBkColor(page, 0) + DeleteObject(SelectObject(page, _
CreateFont(-MulDiv(6, GetDeviceCaps(page, 90), 72), MulDiv, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Courier")))
Macro ResizePage() = InvalidateRect(ME, NULL, TRUE) + LoWord(CBLPARAM) + HiWord(CBLPARAM) + PlotPage()
Macro ShowWindow() = FbslSetText(ME, "-= FBSL Binary Mandelbrot =-") + Center(ME) + Show(ME) + PostMessage(ME, &H5, 0, (H << 16) + W)
Macro PaintPage() = ValidateRect(ME, NULL) + PlotPage(page,W,H) + StretchBlt( _
GetDC, 0, 0, LoWord, HiWord, page, 0, 0, W, H, &HCC0020) + InvalidateRect(ME, NULL, TRUE)
Macro Wait(t) = Sleep(t) + InvalidateRect(ME, NULL, FALSE)
Macro Quit() = IIf(CBWPARAM = 2, PostMessage(ME, &H10, 0, 0), 0) ' WM_CLOSE
' ------------------------- App Starts Here ----------------------
Dim W = 0, H = 0, %R[3]
CalcClient()
CreatePage()
ResizePage()
ShowWindow()
Begin Events
Select Case CBMSG
Case &H111 ' WM_COMMAND
Quit()
Case &H5 ' WM_SIZE
ResizePage()
Case &H14 ' WM_ERASEBKGND
Wait(15)
Return 1
Case &HF ' WM_PAINT
PaintPage()
End Select
End Events
' ------------------------ That's All Folks! ---------------------
' -------------------------- Painting Proc -----------------------
DynC PlotPage(%p = page, %width = W, %height = H)
void __attribute__((stdcall)) SetTextColor(int, int);
void __attribute__((stdcall)) TextOutA(int, int, int, char*, int);
void main(int page, int w, int h)
{
char digit[4];
int x, y, c, cl;
float sx = -2.2f, sy = -1.7f, sw = 3.4f, sh = 3.4f;
float gx, gy, zx, zy, nzx;
for (x = 0; x <= h; x += 10) {
for (y = 0; y <= w; y += 10) {
gx = (float)x / w * sw + sx;
gy = (float)y / h * sh + sy;
zx = gx; zy = gy;
for (c = 0; c <= 255; c++) {
nzx = zx * zx - zy * zy + gx;
zy = 2 * zx * zy + gy;
zx = nzx;
cl = c;
if ((zx * zx + zy * zy) > 4.0f) {
cl = c;
break;
}
}
sprintf(digit, "%c", rand() % 2 + 48);
SetTextColor(page, (((cl << 6) & 0xFF) << 16) | (((cl << 5) & 0xFF) << 8) | cl);
TextOutA(page, x, y, digit, 1);
}
}
}
End DynC