Skip to content

Instantly share code, notes, and snippets.

@ex
Created May 27, 2012 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ex/2795822 to your computer and use it in GitHub Desktop.
Save ex/2795822 to your computer and use it in GitHub Desktop.
DOS Borland-C++ old source code of mine
//---------------------------------------------------------------
// Mandel.c
//---------------------------------------------------------------
// Fractal de Mandelbrot - Esau R.O
//---------------------------------------------------------------
#include "mandel.h"
#include "graficos.h"
extern double gf_x1;
extern double gf_y1;
extern double gf_x2;
extern double gf_y2;
extern int gn_max_x;
extern int gn_max_y;
extern int gn_pasos;
extern int gn_Estilo;
int Mandelbrot (int inicializar, int metodo)
{
int max_x, max_y,
k, p, q,
pasos, terminar,
color = 1;
double paso_x, paso_y,
pos_x, pos_y,
iter_x, iter_y,
temp_x;
char c;
if (inicializar == TRUE)
{
gf_x1 = -2.5;
gf_y1 = -1.2;
gf_x2 = 0.7;
gf_y2 = 1.2;
gn_pasos = 256;
}
if (metodo == EX_M_INCREMENTAL)
{
cleardevice();
}
MarcarEnProgreso (TRUE);
paso_x = (gf_x2 - gf_x1) / gn_max_x;
paso_y = (gf_y2 - gf_y1) / gn_max_y;
for ((metodo == EX_M_INCREMENTAL)?(q = 64):(q = gn_pasos); q <= gn_pasos; q += 64)
{
for (k = 0; k <= gn_max_x; k++)
{
for (p = 0; p <= gn_max_y; p++)
{
pos_x = gf_x1 + k * paso_x;
pos_y = gf_y2 - p * paso_y;
iter_x = 0.0;
iter_y = 0.0;
terminar = FALSE;
pasos = 0;
while (! terminar)
{
temp_x = (iter_x * iter_x) - (iter_y * iter_y) + pos_x;
iter_y = 2 * (iter_x * iter_y) + pos_y;
iter_x = temp_x;
pasos++;
if ((iter_x * iter_x + iter_y * iter_y) >= 4.0)
{
terminar = TRUE;
}
if (pasos >= q)
{
terminar = TRUE;
}
}
if (pasos < q)
{
if (gn_Estilo == EX_E_CONTRASTE)
{
putpixel (k, p, (pasos - 1) % 15 + 1);
}
else
{
color = (pasos - 1) % 28 + 1;
if (color > 15)
{
color = 30 - color;
}
putpixel (k, p, color);
}
}
else
{
if (metodo == EX_M_DIRECTO)
{
putpixel (k, p, 0);
}
}
}
if (kbhit())
{
c = getch();
//------------------------------------------
// para poder detener con teclas de funcion
if (c == 0)
{
getch();
}
MarcarEnProgreso (FALSE);
return FALSE;
}
}
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment