Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links

Conjunto de Julia c*sin(z)

Este fractal pertenece a la familia de los Conjuntos de Julia.

z = c * sin(z)

donde z = x + iy, c = a + ib, son números complejos, para evaluar sin(z) utilizo la siguiente realción que me permite separar en la parte real e imaginaria la funcion sin(z)

sin(z) = sin(x + iy) = sin(x)*cosh(y) + i cos(x)*sinh(y)

Código Fuente

El codigo esta en VisualC, y utilizo las APIs de Windows para graficar este fractal la gama de colores la cargo desde un archivo de texto que contiene las componentes RGB, este archivo (chroma.map) lo saque de los que vienen por default con el programa FractInt.
El codigo fuente y el archivo chroma.map lo podes descargar desde aqui sinz.zip

Region del plano complejo graficado
xmin=-Pi, xmax=Pi, ymin=-Pi, ymax=Pi

Un zoom de la region central del plano
xmin=-Pi/4, xmax=Pi/4, ymin=-Pi/4, ymas=Pi/4


//Autor : Ramiro Alcocer
//email : valcoey@hotmail.com
//www   : www.oocities.org/valcoey/index.html

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

#define		Pi	3.141592654

//Declaración de funciones del programa
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
void Loadmap(char *nombre);
void DibujarFractal(HWND hwnd);

//Declaración de variables del programa
char WindowName[]  = "Ventana de Windows";
char WindowTitle[] = "Conjunto de Julia c*sin(z)";
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);
} 

void DibujarFractal(HWND hwnd)
{
PAINTSTRUCT ps;
RECT rect;
BYTE R, G, B;

double deltax, deltay;
double x, y, a, b, tmp;
double  xmin = -Pi/4.0, ymin= -Pi/4.0, xmax=Pi/4.0, ymax=Pi/4.0;
int maxiter = 256;
int maxcol, maxrow;
int row, col, count;
int color;

BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);

a = 1.0;
b = 0.25;
maxcol =  rect.right - rect.left ;
maxrow =  rect.bottom - rect.top;
deltax = (xmax - xmin)/(maxcol-1);
deltay = -(ymax - ymin)/(maxrow-1);
for (col=0; col<=maxcol; col++) {
	for (row=0; row<=maxrow; row++) {
		x = deltax*col + xmin;
		y = deltay*row + ymax;
		count=0;
		while ((count<maxiter) && (x*x+y*y<maxiter)) {
			tmp=x;
			x=sin(x)*cosh(y)*a - cos(x)*sinh(y)*b;
			y=cos(tmp)*sinh(y)*a + sin(tmp)*cosh(y)*b;
			count+=1;
			}
		color=count%256;
		R=ColorRGB[color][0];
		G=ColorRGB[color][1];
		B=ColorRGB[color][2];
		SetPixel(ps.hdc, col, row, RGB(R,G,B));
		}
	}		
EndPaint(hwnd, &ps);
}

//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
		350, 350,                           // 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 )
{
	
	switch( message )
	{
		case WM_CREATE:
			   break;
        //dibuja el fractal de Newton-Raphson
		case WM_PAINT:
				Loadmap("chroma.map");
				DibujarFractal(hwnd);
				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);
}


valcoey@hotmail.com

Ramiro Alcocer, 2001

Principal | Gráficos 3D | Gráficos 2D | Fractales | Math | Códigos | Tutoriales | Links