Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

DESSINATEUR DE FRACTALES


Information sur la source

Catégorie :Graphique Classé sous : fractales, mandelbrot, assembleur Niveau : Expert Date de création : 25/04/2006 Date de mise à jour : 05/05/2009 00:23:22 Vu : 3 487

Note :
Aucune note

Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
Dessine la courbe de Mandelbrot. Code optimise, a compiler avec mingw32 ( ou DevCpp ). Les calculs sont faits en assembleurs. Cependant, la partie affichage ggnerait à être améliorée pour ne pas réafficher le fractale à chaque dessinage de la fenetre.
 

Source

  • #include <windows.h>
  • #include <stdio.h>
  • #include <math.h>
  • #define ID_BUTTON_DESSINER 100
  • #define ID_EDIT_CRMIN 101
  • #define ID_EDIT_CRMAX 102
  • #define ID_EDIT_CIMIN 103
  • #define ID_EDIT_CIMAX 104
  • #define ID_EDIT_N 105
  • #define ID_STATIC_CR 106
  • #define ID_STATIC_CI 107
  • /* Declare Windows procedure */
  • LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
  • /* Make the class name into a global variable */
  • char szClassName[ ] = "WindowsApp";
  • COLORREF fractal[600][800];
  • double crmax,crmin, cimax,cimin, crpas,cipas;
  • HWND hwndmain, hbouton, hedit_crmin, hedit_crmax, hedit_cimin, hedit_cimax, hedit_n, hstatic_cr, hstatic_ci;
  • MSG messages; /* Here messages to the application are saved */
  • int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil){
  • WNDCLASSEX wincl; /* Data structure for the windowclass */
  • /* The Window structure */
  • wincl.hInstance = hThisInstance;
  • wincl.lpszClassName = szClassName;
  • wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
  • wincl.style = CS_DBLCLKS; /* Catch double-clicks */
  • wincl.cbSize = sizeof(WNDCLASSEX);
  • /* Use default icon and mouse-pointer */
  • wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  • wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  • wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
  • wincl.lpszMenuName = NULL; /* No menu */
  • wincl.cbClsExtra = 0; /* No extra bytes after the window class */
  • wincl.cbWndExtra = 0; /* structure or the window instance */
  • /* Use light-gray as the background of the window */
  • wincl.hbrBackground =(HBRUSH) GetStockObject(LTGRAY_BRUSH);
  • /* Register the window class, if fail quit the program */
  • if(!RegisterClassEx(&wincl)) return 0;
  • /* The class is registered, let's create the program*/
  • hwndmain = CreateWindowEx(
  • 0, /* Extended possibilites for variation */
  • szClassName, /* Classname */
  • "Mandelbrot", /* Title Text */
  • WS_OVERLAPPEDWINDOW, /* default window */
  • CW_USEDEFAULT, /* Windows decides the position */
  • CW_USEDEFAULT, /* where the window ends up on the screen */
  • 1015, /* The programs width */
  • 627, /* and height in pixels */
  • HWND_DESKTOP, /* The window is a child-window to desktop */
  • NULL, /* No menu */
  • hThisInstance, /* Program Instance handler */
  • NULL /* No Window Creation data */
  • );
  • int i,j;
  • for(i=0;i<600;i++)
  • for(j=0;j<800;j++)
  • fractal[i][j]=RGB(0,0,0);
  • /* Make the window visible on the screen */
  • hbouton=CreateWindowEx (0,"BUTTON","dessiner",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,805,260,100,25,
  • hwndmain,(HMENU)ID_BUTTON_DESSINER,hThisInstance,NULL);
  • hedit_crmin=CreateWindowEx (0,"EDIT","-2.1",WS_CHILD|WS_VISIBLE|WS_BORDER ,805,30,200,20,
  • hwndmain,(HMENU)ID_EDIT_CRMIN,hThisInstance,NULL);
  • hedit_crmax=CreateWindowEx (0,"EDIT","0.9",WS_CHILD|WS_VISIBLE|WS_BORDER,805,80,200,20,
  • hwndmain,(HMENU)ID_EDIT_CRMAX,hThisInstance,NULL);
  • hedit_cimin=CreateWindowEx (0,"EDIT","-1.2",WS_CHILD|WS_VISIBLE|WS_BORDER,805,130,200,20,
  • hwndmain,(HMENU)ID_EDIT_CIMIN,hThisInstance,NULL);
  • hedit_cimax=CreateWindowEx (0,"EDIT","1.2",WS_CHILD|WS_VISIBLE|WS_BORDER,805,180,200,20,
  • hwndmain,(HMENU)ID_EDIT_CIMAX,hThisInstance,NULL);
  • hedit_n=CreateWindowEx (0,"EDIT","255",WS_CHILD|WS_VISIBLE|WS_BORDER,805,230,75,20,
  • hwndmain,(HMENU)ID_EDIT_N,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","Cr min =",WS_CHILD|WS_VISIBLE,805,5,60,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","Cr max =",WS_CHILD|WS_VISIBLE,805,55,60,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","Ci min =",WS_CHILD|WS_VISIBLE,805,105,60,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","Ci max =",WS_CHILD|WS_VISIBLE,805,155,60,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","N =",WS_CHILD|WS_VISIBLE,805,205,30,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","cr =",WS_CHILD|WS_VISIBLE,805,500,30,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • CreateWindowEx (0,"STATIC","ci =",WS_CHILD|WS_VISIBLE,805,550,30,20,
  • hwndmain,(HMENU)0,hThisInstance,NULL);
  • hstatic_cr= CreateWindowEx (0,"STATIC","",WS_CHILD|WS_VISIBLE,805,525,200,20,
  • hwndmain,(HMENU)ID_STATIC_CR,hThisInstance,NULL);
  • hstatic_ci= CreateWindowEx (0,"STATIC","",WS_CHILD|WS_VISIBLE,805,575,200,20,
  • hwndmain,(HMENU)ID_STATIC_CI,hThisInstance,NULL);
  • ShowWindow(hwndmain, nFunsterStil);
  • /* Run the message loop. It will run until GetMessage( ) returns 0 */
  • while(GetMessage(&messages, NULL, 0, 0))
  • {
  • /* Translate virtual-key messages into character messages */
  • TranslateMessage(&messages);
  • /* Send message to WindowProcedure */
  • DispatchMessage(&messages);
  • }
  • /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
  • return messages.wParam;
  • }
  • COLORREF Palette(int e){
  • int k=((int)sqrt(e)*48)%768;
  • COLORREF r;
  • if(k<256) r=RGB(k,0,255-k);
  • if(k<512 && k>=256) r=RGB(511-k,k-256,0);
  • if(k>=512) r=RGB(0,767-k,k-512);
  • if(r==0){
  • char tampontxt[100];
  • sprintf(tampontxt,"k=%d m=%d",k,e);
  • MessageBox(hwndmain,tampontxt,"",MB_OK);
  • }
  • return r;
  • }
  • /* This function is called by the Windows function DispatchMessage( ) */
  • LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  • {
  • HDC hdc;
  • PAINTSTRUCT ps;
  • int x,y,i,j;
  • switch (message) /* handle the messages */
  • {
  • case WM_DESTROY:
  • PostQuitMessage(0); /* send a WM_QUIT to the message queue */
  • break;
  • case WM_COMMAND:
  • if ((LOWORD(wParam) == ID_BUTTON_DESSINER) && (HIWORD(wParam) == BN_CLICKED)){
  • long double cr,ci;
  • char tampontxt[10000];
  • int Nmax;
  • GetDlgItemText(hwndmain,ID_EDIT_CRMIN,tampontxt,100);
  • sscanf(tampontxt,"%lf",&crmin);
  • GetDlgItemText(hwndmain,ID_EDIT_CRMAX,tampontxt,100);
  • sscanf(tampontxt,"%lf",&crmax);
  • GetDlgItemText(hwndmain,ID_EDIT_CIMIN,tampontxt,100);
  • sscanf(tampontxt,"%lf",&cimin);
  • GetDlgItemText(hwndmain,ID_EDIT_CIMAX,tampontxt,100);
  • sscanf(tampontxt,"%lf",&cimax);
  • Nmax=GetDlgItemInt(hwndmain,ID_EDIT_N,NULL,FALSE);
  • crpas=(crmax-crmin)/800;
  • cipas=(cimax-cimin)/600;
  • hdc=GetDC (hwnd);
  • for (x=0;x<800;x++){
  • cr=x*crpas+crmin;
  • for (y=0;y<600;y++){
  • ci=y*cipas+cimin;
  • char diverge=1;
  • asm volatile("fld1\n"
  • "fadd %%st(0)\n"
  • "fadd %%st(0)\n"//pour charger 4
  • "fldt %1\n"
  • "fldt %0\n"
  • "fldz\n"
  • "fldz"
  • :
  • : "m"(cr), "m"(ci)
  • );
  • int k;
  • for (k=0;k<Nmax && diverge;k++){
  • asm volatile( "movb $0,%0\n"
  • //calcul de zi
  • "fld %%st(0)\n"
  • "fmul %%st(2)\n"
  • "fadd %%st(0)\n" //multiplie par 2
  • "fadd %%st(4)\n"
  • //calcul de zr
  • "fld %%st(1)\n"
  • "fmul %%st(0)\n" //élève au carré
  • "fld %%st(3)\n"
  • "fmul %%st(0)\n"
  • "fsubrp\n"
  • "fadd %%st(4)\n"
  • //on remet les données a leur place
  • "fstp %%st(2)\n"
  • "fstp %%st(2)\n"
  • //comparaison de la valeur absolue pour voir si on sort
  • "fld %%st(0)\n"
  • "fmul %%st(0)\n" //élève au carré
  • "fld %%st(2)\n"
  • "fmul %%st(0)\n"
  • "faddp\n"
  • "fcomip %%st(5),%%st(0)\n"
  • "sbbb $0,%0"
  • :"=g" (diverge)
  • );
  • }
  • // on libère le FPU
  • asm volatile( "fstp %%st(0)\n"
  • "fstp %%st(0)\n"
  • "fstp %%st(0)\n"
  • "fstp %%st(0)\n"
  • "fstp %%st(0)\n":::"st");
  • if (diverge){
  • fractal[y][x]=RGB(0,0,0);
  • SetPixel(hdc,x,y,RGB(0,0,0));
  • } else {
  • fractal[y][x]=Palette(k);
  • SetPixel(hdc,x,y,Palette(k));
  • }
  • }
  • }
  • ReleaseDC(hwnd,hdc);
  • } else return DefWindowProc(hwnd, message, wParam, lParam);
  • break;
  • case WM_PAINT:
  • hdc=BeginPaint(hwndmain,&ps);
  • for (i=0;i<800;i++)
  • for (j=0;j<600;j++)
  • SetPixel(hdc,i,j,fractal[j][i]);
  • EndPaint(hwndmain,&ps);
  • break;
  • case WM_MOUSEMOVE:
  • x=LOWORD(lParam);
  • y=HIWORD(lParam);
  • if (x>0 && x<800 && y>0 && y<600){
  • char tampon[1000];
  • sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
  • SetWindowText(hstatic_cr,tampon);
  • sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
  • SetWindowText(hstatic_ci,tampon);
  • }
  • break;
  • case WM_LBUTTONDOWN:
  • x=LOWORD(lParam);
  • y=HIWORD(lParam);
  • if (x>0 && x<800 && y>0 && y<600){
  • char tampon[1000];
  • sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
  • SetWindowText(hedit_crmin,tampon);
  • sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
  • SetWindowText(hedit_cimin,tampon);
  • }
  • break;
  • case WM_LBUTTONUP:
  • x=LOWORD(lParam);
  • y=HIWORD(lParam);
  • if (x>0 && x<800 && y>0 && y<600){
  • char tampon[1000];
  • sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
  • SetWindowText(hedit_crmax,tampon);
  • sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
  • SetWindowText(hedit_cimax,tampon);
  • }
  • break;
  • default: /* for messages that we don't deal with */
  • return DefWindowProc(hwnd, message, wParam, lParam);
  • }
  • return 0;
  • }
#include <windows.h>
#include <stdio.h>
#include <math.h>

#define ID_BUTTON_DESSINER 100
#define ID_EDIT_CRMIN 101
#define ID_EDIT_CRMAX 102
#define ID_EDIT_CIMIN 103
#define ID_EDIT_CIMAX 104
#define ID_EDIT_N 105
#define ID_STATIC_CR 106
#define ID_STATIC_CI 107

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
COLORREF fractal[600][800];
double crmax,crmin, cimax,cimin, crpas,cipas;
HWND hwndmain, hbouton, hedit_crmin, hedit_crmax, hedit_cimin, hedit_cimax, hedit_n, hstatic_cr, hstatic_ci;
MSG messages;            /* Here messages to the application are saved */
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil){
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof(WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use light-gray as the background of the window */
    wincl.hbrBackground =(HBRUSH) GetStockObject(LTGRAY_BRUSH);



    /* Register the window class, if fail quit the program */
    if(!RegisterClassEx(&wincl)) return 0;

    /* The class is registered, let's create the program*/
    hwndmain = CreateWindowEx(
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Mandelbrot",         /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           1015,                 /* The programs width */
           627,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    int i,j;
    for(i=0;i<600;i++)
      for(j=0;j<800;j++)
         fractal[i][j]=RGB(0,0,0);
    /* Make the window visible on the screen */



    hbouton=CreateWindowEx (0,"BUTTON","dessiner",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,805,260,100,25,
                           hwndmain,(HMENU)ID_BUTTON_DESSINER,hThisInstance,NULL);

    hedit_crmin=CreateWindowEx (0,"EDIT","-2.1",WS_CHILD|WS_VISIBLE|WS_BORDER ,805,30,200,20,
                               hwndmain,(HMENU)ID_EDIT_CRMIN,hThisInstance,NULL);
    hedit_crmax=CreateWindowEx (0,"EDIT","0.9",WS_CHILD|WS_VISIBLE|WS_BORDER,805,80,200,20,
                               hwndmain,(HMENU)ID_EDIT_CRMAX,hThisInstance,NULL);
    hedit_cimin=CreateWindowEx (0,"EDIT","-1.2",WS_CHILD|WS_VISIBLE|WS_BORDER,805,130,200,20,
                               hwndmain,(HMENU)ID_EDIT_CIMIN,hThisInstance,NULL);
    hedit_cimax=CreateWindowEx (0,"EDIT","1.2",WS_CHILD|WS_VISIBLE|WS_BORDER,805,180,200,20,
                               hwndmain,(HMENU)ID_EDIT_CIMAX,hThisInstance,NULL);
    hedit_n=CreateWindowEx (0,"EDIT","255",WS_CHILD|WS_VISIBLE|WS_BORDER,805,230,75,20,
                               hwndmain,(HMENU)ID_EDIT_N,hThisInstance,NULL);

    CreateWindowEx (0,"STATIC","Cr min =",WS_CHILD|WS_VISIBLE,805,5,60,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);
    CreateWindowEx (0,"STATIC","Cr max =",WS_CHILD|WS_VISIBLE,805,55,60,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);
    CreateWindowEx (0,"STATIC","Ci min =",WS_CHILD|WS_VISIBLE,805,105,60,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);
    CreateWindowEx (0,"STATIC","Ci max =",WS_CHILD|WS_VISIBLE,805,155,60,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);
    CreateWindowEx (0,"STATIC","N =",WS_CHILD|WS_VISIBLE,805,205,30,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);

    CreateWindowEx (0,"STATIC","cr =",WS_CHILD|WS_VISIBLE,805,500,30,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);
    CreateWindowEx (0,"STATIC","ci =",WS_CHILD|WS_VISIBLE,805,550,30,20,
                    hwndmain,(HMENU)0,hThisInstance,NULL);

    hstatic_cr= CreateWindowEx (0,"STATIC","",WS_CHILD|WS_VISIBLE,805,525,200,20,
                               hwndmain,(HMENU)ID_STATIC_CR,hThisInstance,NULL);
    hstatic_ci= CreateWindowEx (0,"STATIC","",WS_CHILD|WS_VISIBLE,805,575,200,20,
                               hwndmain,(HMENU)ID_STATIC_CI,hThisInstance,NULL);

    ShowWindow(hwndmain, nFunsterStil);



    /* Run the message loop. It will run until GetMessage( ) returns 0 */
    while(GetMessage(&messages, NULL, 0, 0))
    {
           /* Translate virtual-key messages into character messages */
           TranslateMessage(&messages);
           /* Send message to WindowProcedure */
           DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
    return messages.wParam;
}

COLORREF Palette(int e){
         int k=((int)sqrt(e)*48)%768;
         COLORREF r;
         if(k<256) r=RGB(k,0,255-k);
         if(k<512 && k>=256) r=RGB(511-k,k-256,0);
         if(k>=512) r=RGB(0,767-k,k-512);
         if(r==0){
           char tampontxt[100];
           sprintf(tampontxt,"k=%d m=%d",k,e);
           MessageBox(hwndmain,tampontxt,"",MB_OK);
         }
         return r;
}

/* This function is called by the Windows function DispatchMessage( ) */
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    int x,y,i,j;
    switch (message)                  /* handle the messages */
    {
           case WM_DESTROY:
                PostQuitMessage(0);        /* send a WM_QUIT to the message queue */
           break;
           case WM_COMMAND:

                if ((LOWORD(wParam) == ID_BUTTON_DESSINER) && (HIWORD(wParam) == BN_CLICKED)){
                   long double cr,ci;
                   char tampontxt[10000];
                   int Nmax;


                   GetDlgItemText(hwndmain,ID_EDIT_CRMIN,tampontxt,100);
                   sscanf(tampontxt,"%lf",&crmin);

                   GetDlgItemText(hwndmain,ID_EDIT_CRMAX,tampontxt,100);
                   sscanf(tampontxt,"%lf",&crmax);


                   GetDlgItemText(hwndmain,ID_EDIT_CIMIN,tampontxt,100);
                   sscanf(tampontxt,"%lf",&cimin);

                   GetDlgItemText(hwndmain,ID_EDIT_CIMAX,tampontxt,100);
                   sscanf(tampontxt,"%lf",&cimax);

                   Nmax=GetDlgItemInt(hwndmain,ID_EDIT_N,NULL,FALSE);

                   crpas=(crmax-crmin)/800;
                   cipas=(cimax-cimin)/600;

                   hdc=GetDC (hwnd);
                   for (x=0;x<800;x++){
                       cr=x*crpas+crmin;

                       for (y=0;y<600;y++){
                           ci=y*cipas+cimin;
                           char diverge=1;
                           asm volatile("fld1\n"
                                "fadd %%st(0)\n"
                                "fadd %%st(0)\n"//pour charger 4
                                "fldt %1\n"
                                "fldt %0\n"
                                "fldz\n"
                                "fldz"
                                :
                                : "m"(cr), "m"(ci)
                                );
                           int k;
                           for (k=0;k<Nmax && diverge;k++){
                             asm volatile( "movb $0,%0\n"
                                  //calcul de zi
                                  "fld %%st(0)\n"
                                  "fmul %%st(2)\n"
                                  "fadd %%st(0)\n"    //multiplie par 2
                                  "fadd %%st(4)\n"
                                  //calcul de zr
                                  "fld %%st(1)\n"
                                  "fmul %%st(0)\n"  //élève au carré
                                  "fld %%st(3)\n"
                                  "fmul %%st(0)\n"
                                  "fsubrp\n"
                                  "fadd %%st(4)\n"
                                  //on remet les données a leur place
                                  "fstp %%st(2)\n"
                                  "fstp %%st(2)\n"
                                  //comparaison de la valeur absolue pour voir si on sort
                                  "fld %%st(0)\n"
                                  "fmul %%st(0)\n"  //élève au carré
                                  "fld %%st(2)\n"
                                  "fmul %%st(0)\n"
                                  "faddp\n"
                                  "fcomip %%st(5),%%st(0)\n"
                                  "sbbb $0,%0"                                 
                                  :"=g" (diverge)
                                  );
                                  
                           }
                           // on libère le FPU
                           asm volatile( "fstp %%st(0)\n"
                                "fstp %%st(0)\n"
                                "fstp %%st(0)\n"
                                "fstp %%st(0)\n"
                                "fstp %%st(0)\n":::"st");
                           
                           if (diverge){
                              fractal[y][x]=RGB(0,0,0);
                              SetPixel(hdc,x,y,RGB(0,0,0));
                           }   else {
                              fractal[y][x]=Palette(k);
                              SetPixel(hdc,x,y,Palette(k));
                           }
                       }
                       
                   }
                   ReleaseDC(hwnd,hdc);
                } else return DefWindowProc(hwnd, message, wParam, lParam);
           break;
           case WM_PAINT:
                hdc=BeginPaint(hwndmain,&ps);
                for (i=0;i<800;i++)
                    for (j=0;j<600;j++)
                        SetPixel(hdc,i,j,fractal[j][i]);
                EndPaint(hwndmain,&ps);

           break;
           case WM_MOUSEMOVE:
                x=LOWORD(lParam);
                y=HIWORD(lParam);
                if (x>0 && x<800 && y>0 && y<600){
                   char tampon[1000];
                   sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
                   SetWindowText(hstatic_cr,tampon);
                   sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
                   SetWindowText(hstatic_ci,tampon);
                }
           break;
           case WM_LBUTTONDOWN:
                x=LOWORD(lParam);
                y=HIWORD(lParam);
                if (x>0 && x<800 && y>0 && y<600){
                   char tampon[1000];
                   sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
                   SetWindowText(hedit_crmin,tampon);
                   sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
                   SetWindowText(hedit_cimin,tampon);
                }
           break;
           case WM_LBUTTONUP:
                x=LOWORD(lParam);
                y=HIWORD(lParam);
                if (x>0 && x<800 && y>0 && y<600){
                   char tampon[1000];
                   sprintf(tampon,"%.20lf",(double)(x*crpas+crmin) );
                   SetWindowText(hedit_crmax,tampon);
                   sprintf(tampon,"%.20lf",(double)(y*cipas+cimin) );
                   SetWindowText(hedit_cimax,tampon);
                }
           break;
           default:                   /* for messages that we don't deal with */
                return DefWindowProc(hwnd, message, wParam, lParam);


    }
    return 0;
}

Conclusion

Pour zoomer, il faut appuyer le bouton de la souris en haut a gauche du rectangle que l'on veut voir et relacher le bouton de la souris en bas a droite.
N, c'est le nombre d'itérations, il faut l'augmenter si on zoome pas mal.
 

Historique

05 mai 2009 00:23:22 :
Ajout exmplications.

Commentaires et avis

signaler à un administrateur
Commentaire de ymca2003 le 26/04/2006 16:13:02

Pas tu tout optimiser en ce qui concerne l'affichage
SetPixel est très lent.
Il faut créer un bitmap en mémoire, sous forme de tableau de pixel, y mettre les couleurs
puis afficher avec un BitBlt ou similaire

signaler à un administrateur
Commentaire de jourgun le 26/04/2006 18:24:26

En effet, j'avais pense a faire ca mais il y avait pas mal de problemes techniques. Et puis je pense que l'affichage des pixels n'est pas ce qui prend le plus de temps a partir du moment ou on commence a explorer ce fractale. Si quelqu'un connait bien le fonctionnement de setpixel, il peut adapter mon code, je lui en serait reconnaissant (je n'ai pas le temps d'aller chercher ce genre de choses dans msdn )

signaler à un administrateur
Commentaire de ymca2003 le 26/04/2006 18:40:00

Dans mes sources tu pourra trouver des exemple de manipulation de bitmap.
Il te suffir ade stocker tes COLOOREF directement dans un tableau spécial associé à un bitmap
et de l'afficher

signaler à un administrateur
Commentaire de Forman le 30/08/2007 19:50:34

Tu peux améliorer l'image pour avoir un <<lissage>> des couleurs en appliquant la formule:

n-ln(1+ln(r+1))/ln(2)

Cette formule donne un nouvel indice dans la palette de couleurs avec:
+  n qui est le nombre d'itérations à partir duquel le module de la suite complexe a dépassé le seuil rmax (ou le nombre maximal d'itérations si le seuil n'a pas été dépassé)
+  r qui est le module atteint lorsque la suite a dépassé le seuil (sinon le module de la suite si le nombre maximal d'itérations a été atteint)

Cette formule fonctionne bien lorsque le seuil choisi est grand (par exemple 1.0E6). L'intérêt est d'avoir des images beaucoup plus lisses, avec un coloriage de gradient à peu près uniforme (contrairement à l'algo brutal qui consiste à donner l'indice en fonction du nombre d'itérations, et qui donne des frontières brusques entre les zones correspondant à des nombres d'itérations différents).

J'ai des exemples de fractales obtenues avec ce système sur un vieux site web:
http://www.normalesup.org/~feuvrier/images/mandel0.jpg
http://www.normalesup.org/~feuvrier/images/mandel1.jpg
http://www.normalesup.org/~feuvrier/images/mandel2.jpg
http://www.normalesup.org/~feuvrier/images/mandel3.jpg

signaler à un administrateur
Commentaire de jourgun le 31/08/2007 13:22:22

Merci du conseil, j'adapterais mon code lorsque je trouverais le temps.

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Mandelbrot, Julia [ par Novae ] J'essaye de programmer un log. de dessin de fractales Mandelbrot ou Julia, l'algorithme ca va mais je n'arrive pas a tracer koi ke ce soit avec graphi Debugage assembleur [ par crocejf2000 ] Salut,Qq'un pourrai il peut etre m'aider, j'ai une méchante érreur et jmy connais pas trop en assembleur, Borland c++ 5 me renvoi ceci : Il s'arrete a mettre de l'assembleur en ligne sous Visual C++ [ par alain34270 ] alainBonjour,Voilà. J'ai un problème avec mon disque dur. je voudrais lire les secteurs physiques de mon disque dur, si possible à partir de visual C+ récupérer code assembleur [ par none77 ] Bonjour,j'aimerai savoir si lorsque je programme en C il m'est possible de récupérer le code assembleur automatiquement.Je demande ca car je dois util Macro assembleur pour microcontroleur [ par Tyozhebes ] Bonjour à tous ! Je suis actuellement sur la programmation d'un 68HC11 et, pour des raisons de mémoire (seulement 2ko), il me faut le programmer en [Asm][Devc++] [ par Gonath ] Bon voilà, je programme sur devc++ depuis peu. Je voudrais y insérer des codes en assembleur vu que je connais l'assembleur. Mais le prob, c qu'il n'a interruprion assembleur [ par seito ] SVP est ce que quelqu'un sait comment éxecuter les interuptions assembleurs dans Visual Cmerci Pb avec l'assembleur dev-cpp [ par 6co ] Voici une source vue sur cppfrance et corrigée pour l'assembleur de Dev-Cpp#include &lt;iostream&gt;#include &lt;stdlib.h&gt;#include &lt;conio.c&gt;# ecriture dans un fichier en assembleur [ par ptitchep ] bonjourje voudrais écrire dans un fichier texte en assembleur. j'ai réussi à l'ouvrir à le lire mais quand je veux y écrire des données, l'interruptio assembleur dans du code c [ par guillaume80 ] bjour a tous,dans un code c récupéré, j'ai pris le code pr le compiler sauf qu'il y a eu des soucis, il m'en reste un, c'est le suivant :char *ecran =


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,406 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.