Courbe du dragon

Description

Programme Windows affichant la courbe du dragon. Je présente deux algorithme, l'un récursif et l'autre non.
Voir http://www.mathcurve.com/fractals/dragon/dragon.shtml pour plus d'infos sur cette courbe fractale.

Source / Exemple :


; #########################################################################
;
; Courbe du dragon
; algorithme non récursif
;
; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\gdi32.inc
      
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\gdi32.lib

; #########################################################################

      ;=============
      ; Local macros
      ;=============

    

      m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM

      return MACRO arg
        mov eax, arg
        ret
      ENDM

 
        ;=================
        ; Local prototypes
        ;=================
        WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
        WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

    .data
        szDisplayName db "Dragon",0
        szClassName db "dragon",0
        CommandLine   dd 0
        hWnd          dd 0
        hInstance     dd 0

    .code

start:
        invoke GetModuleHandle, NULL
        mov hInstance, eax

        invoke GetCommandLine
        mov CommandLine, eax

        invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
        invoke ExitProcess,eax

; #########################################################################

WinMain proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

 

        LOCAL wc   :WNDCLASSEX
        LOCAL msg  :MSG

 
        mov wc.cbSize,         sizeof WNDCLASSEX
        mov wc.style,          CS_HREDRAW or CS_VREDRAW 
                         
        mov wc.lpfnWndProc,    offset WndProc
        mov wc.cbClsExtra,     NULL
        mov wc.cbWndExtra,     NULL
        m2m wc.hInstance,      hInst   ;<< NOTE: macro not mnemonic
        mov wc.hbrBackground,  COLOR_WINDOW+1
        mov wc.lpszMenuName,   NULL
        mov wc.lpszClassName,  offset szClassName
          invoke LoadIcon, NULL, IDI_APPLICATION
        mov wc.hIcon,          eax
          invoke LoadCursor,NULL,IDC_ARROW
        mov wc.hCursor,        eax
        mov wc.hIconSm,        0

        invoke RegisterClassEx, ADDR wc

        invoke CreateWindowEx,WS_EX_LEFT,
                              ADDR szClassName,
                              ADDR szDisplayName,
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              785,560,
                              NULL,NULL,
                              hInst,NULL
        mov   hWnd,eax

       
        invoke ShowWindow,hWnd,SW_SHOWNORMAL
        invoke UpdateWindow,hWnd

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain endp

; #########################################################################

WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

        LOCAL hDC  :DWORD
        LOCAL Ps   :PAINTSTRUCT

    
    .if uMsg == WM_PAINT
        invoke BeginPaint,hWin,ADDR Ps
        mov hDC,eax
        pushad

        mov edx,90  ;x
        mov ebx,355  ;y

        mov ecx,20000h ;nombre de points divisé par 2
        mov al,0 
pix:    mov esi,ecx
l1:     shr esi,1
        jnb l1
        shr esi,1
        jb l2
        xor al,1
l2:     or al,al
        jz l3
        sub ebx,2
l3:     inc ebx

        push eax
        push ebx
        push edx
        push ecx
        invoke SetPixel,hDC,edx,ebx,0      
        pop ecx
        pop edx
        pop ebx
        pop eax
        
        test cl,1
        jz l5
        xor al,1
l5:     or  al,al
        jnz l6
        sub edx,2
l6:     inc edx
        
        push eax
        push ebx
        push edx
        push ecx
        invoke SetPixel,hDC,edx,ebx,0      
        pop ecx
        pop edx
        pop ebx
        pop eax
        
        loop pix
         
        popad
        invoke EndPaint,hWin,ADDR Ps
        
        return 0

    
    .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage,NULL
        return 0 

    .endif

    invoke DefWindowProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp

end start

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.