Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links
Este fractal tambien llamado "Lambda fractal" es una variación del de "Julia"
se calcula de forma similar, su ecuación
es:
z = c*z(1-z)
donde z=x+iy es el punto a ser iterado, c=a+ib
es un parametro constante. Al desarrollar esta ecuación obtengo las siguientes
expresiones, las que puedo utilizar en mi código
tmp=x;
x=(x-x*x+y*y)*a-(y-2*x*y)*b;
y=(y-2*tmp*y)*a+(tmp-tmp*tmp+y*y)*b;
donde tmp es una variable que me almacena el valor
de x, ya que estoy iterando sobre x
e y.
En esta imagen utilice la paleta "neon.map", las dimensiones del plano complejo son xmin=-1.0, ymin=-1.5, xmax=2.0, ymax=1.5.
En estas cuatro imagenes utilice la paleta "Gallet01.map", los limites del plano son xmin=-0.25,ymin=-0.25, xmax=0.25, ymas=0.25, tambien fui variando el parametro c.
![]() |
![]() |
c = -0.7 + 0.725i
|
c = -0.7 + 0.75i
|
![]() |
![]() |
c = -0.7 + 0.775i
|
c = -0.7 + 0.8i
|
Código fuente en VisualC++, mapas de colores (neon.map, Gallet01.map) y ejecutable todos en fractal.zip
Cualquier duda o sugerencia sobre este programa a
valcoey@hotmail.com
#include <windows.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <math.h> //--- Declaración de funciones del programa ------------------------------ int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int ); LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); void CrearPaleta(void); //--- Declaración de variables del programa ------------------------------ char WindowName[] = "Ventana de Windows"; char WindowTitle[] = "Galactic Swirls"; BYTE ColorRGB[256][3]; void Loadmap(char *nombre) { FILE *f; char line[100]; int r, g, b; int i; f = fopen(nombre, "r"); if (f==NULL) return; for (i = 0; i<256; i++) { if (fgets(line, 100, f) == NULL) break; sscanf(line, "%d %d %d", &r, &g, &b); ColorRGB[i][0]=r; ColorRGB[i][1]=g; ColorRGB[i][2]=b; } fclose(f); } //=== Función principal WinMain() ======================================== int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { HWND hwnd; // handle a la ventana ppal. MSG msg; // estructura de mensaje WNDCLASSEX wcx; // estructura de la ventana // Definimos la estructura de clase de ventana (campos): wcx.cbSize = sizeof( WNDCLASSEX ); // tamaño de la estructura wcx.style = CS_HREDRAW | CS_VREDRAW; // valores más usuales wcx.lpfnWndProc = WndProc; // función de ventana (Wnd) wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; // informaciones extra wcx.hInstance = hInstance; // instancia actual // icono, cursor, fondo e icono pequeño de la clase de ventana: wcx.hIcon = LoadIcon(NULL, IDI_WINLOGO); wcx.hCursor = LoadCursor(NULL, IDC_ARROW); wcx.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH ); wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO); wcx.lpszMenuName = NULL; // nombre del menú wcx.lpszClassName = WindowName; // nombre de la ventana // Registramos la clase de ventana ya preparada: if( !RegisterClassEx( &wcx ) ) return( FALSE ); // en caso de error, salir // Creamos la ventana con CreateWindowEx(): hwnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, // estilo extendido WindowName, // nombre de la ventana WindowTitle, // título de la ventana WS_OVERLAPPEDWINDOW, // estilo de ventana CW_USEDEFAULT, CW_USEDEFAULT, // Posición (x,y) en pantalla 400, 400, // ancho y alto de la ventana NULL, NULL, // ventana padre e hija+menú hInstance, // instancia actual NULL // no hay más información ); // Comprobamos la creación de la ventana: if( !hwnd ) return( FALSE ); // en caso de error, salir // Hacemos visible la ventana y la actualizamos: ShowWindow( hwnd, nCmdShow ); UpdateWindow( hwnd ); // Bucle de mensajes, envía los mensajes hacia WndProc while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); // convertimos el mensaje DispatchMessage( &msg ); // devolvemos el control a w95 } // devolvemos el valor recibido por PostQuitMessage(). return( msg.wParam ); } //=== Función del procedimiento de ventana WndProc() ===================== LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { HDC hdc; PAINTSTRUCT ps; RECT rect; BYTE R, G, B; double deltax, deltay; double x, y; double tmp; double a=-0.7; double b=0.775; double xmin = -1.0, ymin= -1.5, xmax=2.0, ymax=1.5; int maxiter = 256; int maxcol, maxrow; int row, col, count; switch( message ) { case WM_CREATE: break; case WM_PAINT: Loadmap("neon.map"); hdc = BeginPaint( hwnd, &ps ); GetClientRect(hwnd, &rect); maxcol = rect.right - rect.left ; maxrow = rect.bottom - rect.top; deltax = (xmax - xmin)/maxcol; deltay = (ymax - ymin)/maxrow; for (col=0; col<=maxcol; col++) { for (row=0; row<=maxrow; row++) { x = xmin + col * deltax; y = ymin + row * deltay; count=0; while ((count<maxiter) && (x*x+y*y<4.0)) { tmp=x; x = (x - x*x + y*y)*a - (y - 2*x*y)*b; y = (tmp - tmp*tmp + y*y)*b + (y - 2*tmp*y)*a; count+=1; } R=ColorRGB[count][0]; G=ColorRGB[count][1]; B=ColorRGB[count][2]; SetPixel(hdc, col, row, RGB(R,G,B)); } } EndPaint( hwnd, &ps ); break; // mensaje producido al cerrar la ventana case WM_DESTROY: PostQuitMessage( 0 ); break; // resto de mensajes, dar una respuesta estándar. default: return( DefWindowProc( hwnd, message, wParam, lParam ) ); } return(0); } //=== Fin del archivo ==================================================== |
valcoey@hotmail.com
Ramiro Alcocer, 2001
Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links