Páginas

domingo, 27 de noviembre de 2011

"APLICACION UTILIZANDO LOS OBJETOS GRAFICOS BASICOS DE C#"





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();


this.Text = "Fondo Lineas";

}

Random r = new Random();


private void timer1_Tick(object sender, EventArgs e)
{



}

private void button1_Click(object sender, EventArgs e)
{

}

private void Form1_Paint(object sender, PaintEventArgs e)
{

}

private void Form1_Resize(object sender, EventArgs e)
{
Invalidate();
}

private void timer1_Tick_1(object sender, EventArgs e)
{
Graphics g = CreateGraphics();

LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new Point(r.Next(10, 20)), Color.Violet, Color.White);
g.FillRectangle(lgb, this.ClientRectangle);
lgb.Dispose();


}

private void button1_Click_1(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = true;
}

private void timer2_Tick(object sender, EventArgs e)
{

Graphics g = this.CreateGraphics();
string cad = "Alejandra";

g.DrawString(cad, new Font("Arial", 20), Brushes.RoyalBlue, r.Next(10, 500),30);
Thread.Sleep(500);
}

private void button2_Click(object sender, EventArgs e)
{
timer2.Enabled = false;
timer1.Enabled = false;
this.Refresh();
}
}
}

APLICACION QUE UTILIZA LA LÍNEA DDA



//---------------------------------------------------------------------------

#include
#include
#pragma hdrstop
#include
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
g=new Graficos(Form1->Canvas);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{

x1=X;
y1=Y;

xc=X;
yc=Y;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{


X2=X;
Y2=Y;

if(RadioButton1->Checked)
{
Edit1->Text=x1;
Edit2->Text=y1;
Edit3->Text=X2;
Edit4->Text=Y2;
g->lineaDDA(x1,y1,X2,Y2);
}

if(RadioButton2->Checked)
{
Edit6->Text=xc;
Edit5->Text=yc;
radio=X2-xc;
Edit7->Text=radio;
//g->circulo_4(X2,Y2,radio) ;
g->circ_coord_polares(x1,y1,radio);
}

}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
Form1->Refresh();
Form1->Repaint();

if(RadioButton1->Checked)
{
Edit6->Text=" ";
Edit7->Text=" ";
Edit5->Text=" ";
}


}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
Form1->Refresh();
Form1->Repaint();
if(RadioButton2->Checked)
{

Edit1->Text=" ";
Edit2->Text=" ";
Edit3->Text=" ";
Edit4->Text=" ";
}



}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{

Form1->Refresh();
Form1->Repaint();

int x=ClientWidth/3;
int y=ClientHeight/2;

radio=5;

g->espiral1(x,y,radio);


}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{

Form1->Refresh();
Form1->Repaint();

int x=ClientWidth/3;
int y=ClientHeight/2;

radio=1.0;
g->espiral2(x,y,radio);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button6Click(TObject *Sender)
{
Form1->Refresh();
Form1->Repaint();

int x=ClientWidth/3;
int y=ClientHeight/2;


double teta=7;
double radio=1.2;

//double th=0.3;
g->espiral2efecto(x,y,radio,teta);
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button5Click(TObject *Sender)
{

Form1->Refresh();
Form1->Repaint();

int x=ClientWidth/3;
int y=ClientHeight/2;



double radio=.75;

//double th=0.3;
g->espiral1efecto(x,y,radio);

}
//---------------------------------------------------------------------------

GENERACION DE LA CIRCUNFERENCIA USANDO EL TEOREMA DE PITAGORAS

//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
xc = X;
yc = Y;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
x1=X;
y1=Y;
this->Repaint();
Canvas->Refresh();
radio=x1-xc;
r=radio;
for (double i=x1;i>=xc-radio;i--,r--)
{
y2=sqrt((radio*radio)-(r*r));
f=fmod(y2,1.0);
if(f>=.50)
y2++;
Canvas->Pixels[(int)i][(int)yc+(int)y2]=clBlue;
Sleep(50);
}
r=radio;
for (double i=xc-radio;i<=x1;i++,r--)
{
y2=sqrt((radio*radio)-(r*r));
f=fmod(y2,1.0);
if(f>=.50)
y2++;
Canvas->Pixels[(int)i][(int)yc-(int)y2]=clBlue;
Sleep(50);
}
}

Fractal Sierpinski




//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

//Esta funcion dibujara solo 1 triangulo y entonces empezara la funcion de recursividad a si mismo
void TForm1::drawSierpinski(float x1, float y1, float x2, float y2, float x3, float y3)
{
//Aqui dibujamos las 3 lineas del triangulo, uniendo los 3 puntos para generar lineas
this->Canvas->Pen->Color=(TColor)random(65000);
this->Canvas->MoveTo(x1,y1);
this->Canvas->LineTo(x2,y2);
this->Canvas->MoveTo(x2,y2);
this->Canvas->LineTo(x3,y3);
this->Canvas->MoveTo(x3,y3);
this->Canvas->LineTo(x1,y1);
//Llamamos a la funcion de recursividad y pintara el resto de los tringulos, las 3 esquinas de triangulo son simempre el centro de su posicion
subTriangle
(
1, //Esto representa la primer recursicion
(x1 + x2) / 2, //coordenada x de la primera esquina
(y1 + y2) / 2, //coordenada y de la primera esquina
(x1 + x3) / 2, //coordenada x de la segunda esquina
(y1 + y3) / 2, //coordenada y de la segunda esquina
(x2 + x3) / 2, //coordenada x de la tercera esquina
(y2 + y3) / 2 //coordenada y de la tercera esquina
);
}
//La funcion de recursividad subtriangulo pintara todo lo que esta dentro del tringulo mayor a este
void TForm1::subTriangle(int n, float x1, float y1, float x2, float y2, float x3, float y3)
{
Sleep(10);
//Dibujamos los 3 lados del subtriangulo
this->Canvas->MoveTo(x1,y1);
this->Canvas->LineTo(x2,y2);
this->Canvas->MoveTo(x2,y2);
this->Canvas->LineTo(x3,y3);
this->Canvas->MoveTo(x3,y3);
this->Canvas->LineTo(x1,y1);
//Llamadas a si mismo 3 veces con nuevas esquinas,pero solo si el actual numero de recurrencias es menor que la profundidad maxima
if(n < depth)
{
//Triangulo mas pequeño #1
subTriangle
(
n+1, //numero de recurrencias para la siguiente llamada con aumento de 1
(x1 + x2) / 2 + (x2 - x3) / 2, //coordenada x de la primera esquina
(y1 + y2) / 2 + (y2 - y3) / 2, //coordenada y de la primera esquina
(x1 + x2) / 2 + (x1 - x3) / 2, //coordenada x de la segunda esquina
(y1 + y2) / 2 + (y1 - y3) / 2, //coordenada y de la segunda esquina
(x1 + x2) / 2, //coordendaa x de la tercera esquina
(y1 + y2) / 2 //coordenada y de la tercera esquina
);
//Triangulo mas pequeño #2
subTriangle
(
n+1, //numero de recurrencias para la siguiente llamada con aumento de 1
(x3 + x2) / 2 + (x2 - x1) / 2,
(y3 + y2) / 2 + (y2 - y1) / 2,
(x3 + x2) / 2 + (x3 - x1) / 2,
(y3 + y2) / 2 + (y3 - y1) / 2,
(x3 + x2) / 2,
(y3 + y2) / 2
);
//Triangulo mas pequeño #3
subTriangle
(
n+1, //numero de recurrencias para la siguiente llamada con aumento de 1
(x1 + x3) / 2 + (x3 - x2) / 2,
(y1 + y3) / 2 + (y3 - y2) / 2,
(x1 + x3) / 2 + (x1 - x2) / 2,
(y1 + y3) / 2 + (y1 - y2) / 2,
(x1 + x3) / 2,
(y1 + y3) / 2
);
}
}




void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->Repaint();
Sleep(1);
Button1->Enabled=false;
//Llamamos a la función de Sierpinski (funciona con cualquier esquina dentro de la pantalla)
//Asignamos las coordenadas del tringulo principal "el mas grande"
drawSierpinski(10, h - 10, w - 10, h - 10, w / 2, 10);
Button1->Enabled=true;
Button1->SetFocus();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
depth=7;
this->ClientWidth=640;
this->ClientHeight=480;
w=this->ClientWidth;
h=this->ClientHeight;
}
//---------------------------------------------------------------------------

Dragon y Escena Fractal

DRAGON

//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
g = new Graficos(this->Canvas);
}
//---------------------------------------------------------------------------
void TForm1::GenerarDragon(int color)
{
int i,j,dx,dy;
j = paso/2;
Form1->Canvas->Pen->Color = (TColor)color + 120;
for(i = 1; i<= 4096; i+= paso)
{
dx = EjeX[paso + i] - EjeX[i];
dy = EjeY[paso + i]- EjeY[i];
signo *= -1;
EjeX[i+j]= EjeX[i] + (dx +(dy * signo))/2 ;
EjeY[i+j]= EjeY[i] + (dy -(dx * signo))/2;
if(color != 0)
{
g->lineaDDA(EjeX[i+j],EjeY[i+j],EjeX[i],EjeY[i]);
g->lineaDDA(EjeX[i + paso],EjeY[i+ paso],EjeX[i+j],EjeY[i+j]);
}
}
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int i;
paso = 4096;
signo = -1;
EjeX[1] = this->Width/4;
EjeX[4097] = 3 * this->Width/4;
EjeY[1] = EjeY[4097] = 2* this->Height/3;
Form1->Canvas->Pen->Color = clBlack;
g->lineaDDA(EjeX[1],EjeY[1],EjeX[4097],EjeY[4097]);
Sleep(700);
for(int i = 1; i< 13;i++ )
{
GenerarDragon(i);
paso/=2;
Sleep(700);
this->Repaint();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------




ESCENA FRACTAL



//---------------------------------------------------------------------------

#include
#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

const double MAXSIZE=1000;
const double MAXLEVEL=6;


__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
double frct1[1000];

void subdivide(int p1 ,int p2,double std,double ratio);

void fractal(int y1,int y2, int maxlevel,double h , double scale)
{
int first,last;

double ratio,std;
first=0;
last= pow(2.0,(double) maxlevel);

frct1[first]=y1;
frct1[last]=y2;
ratio=1.0/pow(2.0,h);
std=scale*ratio;
subdivide(first,last,std,ratio);
}

void subdivide(int p1 ,int p2,double std,double ratio)
{
int midpnt;
double stdmid;
midpnt=(p1+p2)/2;

if(midpnt!=p1 && midpnt!=p2)
{
frct1[midpnt]=(frct1[p1]+frct1[p2])/2+(double)((random(16)-8))/8.0*std;
stdmid=std*ratio;
subdivide(p1,midpnt,stdmid,ratio);
subdivide(midpnt,p2,stdmid,ratio);
}
}

void TForm1::Draw_Fractal(void)
{
int i, x,xinc,l;
l=(int)pow(2.0,(double)MAXLEVEL);
xinc=Form1->PaintBox1->Width/l*3/2;
Form1->PaintBox1->Canvas->MoveTo(0,100);
for(i=0,x=0;i Form1->PaintBox1->Canvas->LineTo(x,(int)frct1[i]);
}


//---------------------------------------------------------------------------



void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
randomize();
PaintBox1->Refresh();

//Cielo
PaintBox1->Canvas->Rectangle(0,0,PaintBox1->Width,PaintBox1->Height);
PaintBox1->Canvas->Brush->Color=RGB(151,232,244);
fractal(100,100,MAXLEVEL,0.5,50.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,1,clBlack,fsBorder);

//aguita
PaintBox1->Canvas->Brush->Color=RGB(151,201,244);
fractal(170,170,MAXLEVEL,0.9,30.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,240,clBlack,fsBorder);

//Sol
PaintBox1->Canvas->Brush->Color=clYellow;
PaintBox1->Canvas->Ellipse(250,20,290,60);
PaintBox1->Canvas->FloodFill(270,50,clBlack,fsBorder) ;

//montañita verde
PaintBox1->Canvas->Brush->Color=RGB(35,221,87);
PaintBox1->Canvas->FloodFill(270,150,clBlack,fsBorder);


}

//---------------------------------------------------------------------------

void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
randomize();
PaintBox1->Refresh();

//Cielo
PaintBox1->Canvas->Rectangle(0,0,PaintBox1->Width,PaintBox1->Height);
PaintBox1->Canvas->Brush->Color=RGB(255,130,0);
fractal(100,100,MAXLEVEL,0.5,50.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,1,clBlack,fsBorder);
// aguita
PaintBox1->Canvas->Brush->Color=RGB(185,134,97);
fractal(170,170,MAXLEVEL,0.9,30.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,240,clBlack,fsBorder);

//Sol
PaintBox1->Canvas->Brush->Color=RGB(255,180,0);
PaintBox1->Canvas->Ellipse(250,20,290,60);
PaintBox1->Canvas->FloodFill(270,50,clBlack,fsBorder) ;

//montañita verde
PaintBox1->Canvas->Brush->Color=RGB(93,50,0);
PaintBox1->Canvas->FloodFill(270,150,clBlack,fsBorder);



}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled=true;
Timer2->Enabled=false;
Timer3->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
Timer2->Enabled=true;
Timer3->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Timer1->Enabled=false;
Timer2->Enabled=false;
Timer3->Enabled=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
randomize();
PaintBox1->Refresh();

//Cielo
PaintBox1->Canvas->Rectangle(0,0,PaintBox1->Width,PaintBox1->Height);
PaintBox1->Canvas->Brush->Color=RGB(1,18,95);
fractal(100,100,MAXLEVEL,0.5,50.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,1,clBlack,fsBorder);
// aguita

PaintBox1->Canvas->Brush->Color=RGB(1,33,167);
fractal(170,170,MAXLEVEL,0.9,30.0);
Draw_Fractal();
PaintBox1->Canvas->FloodFill(1,240,clBlack,fsBorder);

//Sol
PaintBox1->Canvas->Brush->Color=RGB(236,236,236);
PaintBox1->Canvas->Ellipse(250,20,290,60);
PaintBox1->Canvas->FloodFill(270,50,clBlack,fsBorder) ;

//montañita verde
PaintBox1->Canvas->Brush->Color=RGB(0,0,0);
PaintBox1->Canvas->FloodFill(270,150,clBlack,fsBorder);

}
//---------------------------------------------------------------------------

FRACTAL NEWTON RAPSON (MODIFICADO)






//---------------------------------------------------------------------------

#include
#pragma hdrstop
//---------------------------------------------------------------------------
/*WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
} */
//---------------------------------------------------------------------------


//Fractal de Newton-Raphson



//#include



//--- 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[] = "Fractal de Newton-Raphson";

BYTE ColorRGB[225][1];



void CrearPaleta(void)

{

int i;

for (i=0; i<225; i++)

{

if (i<64)

{

ColorRGB[i][0] = 192 + i;

ColorRGB[i][1] = 0;

ColorRGB[i][2] = 0;

}

else if ((i>63) && (i<128))

{

ColorRGB[i][0] = 0;

ColorRGB[i][1] = (192 +i)-64;

ColorRGB[i][2] = 0;

}

else if ((i>127)&&(i<192))

{

ColorRGB[i][0] = 0;

ColorRGB[i][1] = 0;

ColorRGB[i][2] = (192 + i)-128;

}

}

}





//=== 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

500, 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, x, y, tmp, xx, yy, d;

float xmin = -3.0, ymin=-3.0, xmax=3.0, ymax=3.0;

int maxiter = 2048/4; //2048

int maxcol, maxrow;

int color, row, col, count;



switch( message )

{

// mensaje producido en la creaciÛn de la ventana

case WM_CREATE:

break;

//dibuja el fractal de Newton-Raphson

case WM_PAINT:

CrearPaleta();

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
{

xx = x*x;

yy = y*y;

d = 10.0*((xx - yy)*(xx - yy) + 4.0*xx*yy);

if (d == 0.0)

d = 0.000005;

tmp=x*y;

x = (2.0/3.0)*x + (xx - yy)/d;

y = (2.0/3.0)*y - 2.0*tmp*y/d;

count+=5;

}

if (x>0.0)

color = count%70;

else

{

if ((x<-0.3) && (y>0.0))

color = (count%64) + 64;

else

color = (count%64) + 128;

}

R=ColorRGB[color][0];

G=ColorRGB[color][1];

B=ColorRGB[color][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 ====================================================

MANIPULANDO PIXELES E IMAGENES -ZOOM-




//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
xx=X;
yy=Y;
P2=0;
for(int i=0;iClientWidth;i++)
{
for(int j=0;jClientHeight;j++)
{
Image2->Canvas->Pixels[(i+P2)][(j+P1)]=Image1->Canvas->Pixels[i+xx][j+yy];
Image2->Canvas->Pixels[(i+P2)][(j+(P1+1))]=Image1->Canvas->Pixels[i+xx][j+yy];
Image2->Canvas->Pixels[(i+(P2+1))][(j+P1)]=Image1->Canvas->Pixels[i+xx][j+yy];
Image2->Canvas->Pixels[(i+(P2+1))][(j+(P1+1))]=Image1->Canvas->Pixels[i+xx][j+yy];
}
P1=0;
P2++;
}


}
//---------------------------------------------------------------------------