Ниже приведены системы итерируемых функций, которые записаны в формате FRACTINT: [math]Fractal \begin{Bmatrix} a_{1} b_{1} c_{1} d_{1} e_{1} f_{1} p_{1} \\ a_{2} b_{2} c_{2} d_{2} e_{2} f_{2} p_{2} \\ \cdots \\ a_{n} b_{n} c_{n} d_{n} e_{n} f_{n} p_{n} \end{Bmatrix}[/math] Такой записи соответствует следующая система итерируемых функций в пространстве [math]R^{2}[/math] [math]\begin{array}{l} T_1 \left( \begin{array}{r} x \\ y \end{array} \right) = \left( \begin{array}{rr} a_1 & b_1 \\ c_1 & d_1 \\ \end{array} \right) \left( \begin{array}{r} x \\ y \end{array} \right) + \left( \begin{array}{r} e_1 \\ f_1 \end{array} \right), \\ T_2 \left( \begin{array}{r} x \\ y \end{array} \right) = \left( \begin{array}{rr} a_2 & b_2 \\ c_2 & d_2 \\ \end{array} \right) \left( \begin{array}{r} x \\ y \end{array} \right) + \left( \begin{array}{r} e_2 \\ f_2 \end{array} \right), \\ \ldots \\ T_n \left( \begin{array}{r} x \\ y \end{array} \right) = \left( \begin{array}{rr} a_n & b_n \\ c_n & d_n \\ \end{array} \right) \left( \begin{array}{r} x \\ y \end{array} \right) + \left( \begin{array}{r} e_n \\ f_n \end{array} \right). \end{array} [/math] Выход из программ по Esc или Alt+F4 Ель исходный текст и ехе-файл здесь Коэффициенты abcdefp0.10000.00000.00000.16000.00.00.01*10000= 1000.85000.00000.00000.85000.01.60.85*10000=8500-0.1667-0.28870.2887-0.16670.01.60.07*10000= 700-0.16670.2887-0.2887-0.16670.01.60.07*10000= 700 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; 0.1000 0.0000 0.0000 0.1600 0.0 0.0 0.01*10000= 100 ; 0.8500 0.0000 0.0000 0.8500 0.0 1.6 0.85*10000=8500 ;-0.1667 -0.2887 0.2887 -0.1667 0.0 1.6 0.07*10000= 700 ;-0.1667 0.2887 -0.2887 -0.1667 0.0 1.6 0.07*10000= 700 mov XCC,rbx mov YCC,rbx mov i,60000 bucle: call rand mov ecx,10000 xor edx,edx;cdq div ecx cmp edx, 100 ;p1 ja @f movr a,0.1;a = 0.1 mov b,ebx; b = 0 mov c,ebx; c = 0 movr d,0.16 mov f,ebx; f = 0 jmp fin @@: cmp edx, 800 ;p1+p4=100+700=800 ja @f movr a,-0.1667 movr b, 0.2887 movr c,-0.2887 movr d,-0.1667 movr f, 1.6 jmp fin @@: cmp edx,1500 ;p1+p4+p3=800+700=1500 ja @f movr a,-0.1667 movr b,-0.2887 movr c,0.2887 movr d,-0.1667 movr f,1.6 jmp fin @@: movr a,0.8500 mov b,ebx mov c,ebx movr d, 0.85 movr f, 1.60 ; f = 1.60 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fst NewX ;NewX = a * XCC + b * YCC fmul const40 ;st(0) = NewX * 40 fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fstp YCC ;YCC = NewY fadd const320;st(0) = NewX * 40 + cdXSize/2 fistp x ;x = (int) (NewX*40+cdXSize/2) mov ecx, x cmp ecx,cdXSize jae @f fld1 ;st(0) = 1 fsub NewY ;st(0) = 1 - NewY fmul const40 ;st(0) = (1 - NewY)*40 fadd const365;st(0) = (1 - NewY)*40 + cdYSize - 35 fistp y ; y = (int) ((1-NewY)*40+cdYSize-35) cmp y,cdYSize jae @f imul eax,y,2560 add rax,pMainDIB mov dword ptr [rax+rcx*4],0FF00h ;*(pMainDIB + (y<<9)+(y<<7)+x) = 0xFF00; @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Fir Tree Fractal',0 bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const40 dq 40.0 const320 dq 320.0 const365 dq 365.0 end bat-файл Код (Text): cls set masm64_path=\masm64\ set filename=%1 del %filename%.exe %masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit if exist %1.rc ( %masm64_path%bin\RC /r %filename%.rc || exit %masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^ /entry:WinMain %filename%.obj %filename%.res /LARGEADDRESSAWARE:NO ^ /ALIGN:16 /SECTION:.text,W ^ /BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit del %filename%.res ) else ( %masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^ /entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^ /ALIGN:16 /SECTION:.text,W ^ /BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit ) del %filename%.obj Результат
Галактика исходный текст и ехе-файл здесьКоэффициенты abcdefp -0.92-0.090.09-0.920.000.000.1*10000=10000.790.26-0.260.790.210.260.9*10000=9000 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; -0.92 -0.09 0.09 -0.92 0.00 0.00 0.1*10000=1000 ; 0.79 0.26 -0.26 0.79 0.21 0.26 0.9*10000=9000 mov XCC,rbx mov YCC,rbx mov i,45000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,9000 jg @f movr a,-0.92 movr b,-0.09 movr c,0.09 movr d,-0.92 mov e,ebx mov f,ebx jmp fin @@: movr a,0.79 movr b,0.26 movr c,-0.26 movr d,0.79 movr e,0.21 movr f,0.26 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul const300;st(0) = NewX * 300 fadd const320 ;st(0) = NewX * 300 + 320 fistp x ;x = (int) (NewX * 300 + 320) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fmul const300;st(0) = NewY * 300 fsubr const240;st(0) = -NewY * 300 + 240 fistp y ; y = (int) (-NewY * 300 + 240) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FFFFFFh ;*(pMainDIB + y*cdXSize*4 + x*4) = white color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Galaxy Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const300 dd 300.0 const320 dd 320.0 const240 dd 240.0 end Результат
Раковинаисходный текст и ехе-файл здесьКоэффициенты abcdefp-0.92-0.090.09-0.920.000.000.1*10000=10000.790.26-0.260.790.210.260.9*10000=9000 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; -0.92 -0.09 0.09 -0.92 0.00 0.00 0.1*10000=1000 ; 0.79 0.26 -0.26 0.79 0.21 0.26 0.9*10000=9000 mov XCC,rbx mov YCC,rbx mov i,45000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,1000 jg @f movr a,-0.92 movr b,-0.09 movr c,0.09 movr d,-0.92 mov e,ebx mov f,ebx jmp fin @@: movr a,0.79 movr b,0.26 movr c,-0.26 movr d,0.79 movr e,0.21 movr f,0.26 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul const150;st(0) = NewX * 150 fadd const320 ;st(0) = NewX * 150 + 320 fistp x ;x = (int) (NewX * 150 + 320) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fmul const150;st(0) = NewY * 150 fsubr const240;st(0) = -NewY * 150 + 240 fistp y ; y = (int) (-NewY * 150 + 240) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FFFFFFh ;*(pMainDIB + y*cdXSize*4 + x*4) = white color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Seashell Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const150 dd 150.0 const320 dd 320.0 const240 dd 240.0 end Результат
Ветреноисходный текст и ехе-файл здесьКоэффициенты abcdefp0.3585910.329160-0.3340070.580720-5.8890501.9242780.361396*10000=36140.7962180.1369420.0751870.7190741.0869980.4084520.638604*10000=6386 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; 0.358591 0.329160 -0.334007 0.580720 -5.889050 1.924278 0.361396*10000=3614 ; 0.796218 0.136942 0.075187 0.719074 1.086998 0.408452 0.638604*10000=6386 mov rdi,pMainDIB mov ecx,cdYSize*cdXSize mov eax,0FFFFFFh rep stosd mov XCC,rbx mov YCC,rbx mov i,35000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,3160 jg @f cmp edx,3614 jg @f movr a,0.358591 movr b,0.329160 movr c,-0.334007 movr d,0.580720 movr e,-5.889050 movr f,1.924278 jmp fin @@: movr a,0.796218 movr b,0.136942 movr c,0.075187 movr d,0.719074 movr e,1.086998 movr f,0.408452 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC pop fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul const45;st(0) = NewX * 45 fadd const312;st(0) = NewX * 45 + 312 fistp x ;x = (int) (NewX * 470 + 312) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fmul const45 ;st(0) = NewY * 45 fsubr const410;st(0) = -NewY * 45 + 410 fistp y ; y = (int) (-NewY * 45 + 410) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],ebx ;*(pMainDIB + y*cdXSize*4 + x*4) = black color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Windy Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const45 dd 45.0 const312 dd 312.0 const410 dd 410.0 end Результат
Спиральисходный текст и ехе-файл здесьКоэффициенты abcdefp0.935567-0.1649660.1649660.935567000.958*10000=95800.1000.10.75-0.750.011*10000= 1100.1000.1-0.750.750.011*10000= 1100.1000.10.750.750.011*10000= 1100.1000.1-0.75-0.750.009*10000= 90 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ;0.935567 -0.164966 0.164966 0.935567 0 0 0.958*10000=9580 ;0.1 0 0 0.1 0.75 -0.75 0.011*10000= 110 ;0.1 0 0 0.1 -0.75 0.75 0.011*10000= 110 ;0.1 0 0 0.1 0.75 0.75 0.011*10000= 110 ;0.1 0 0 0.1 -0.75 -0.75 0.009*10000= 90 mov XCC,rbx mov YCC,rbx mov i,390000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,90 jg @f movr a,0.1 mov b,ebx mov c,ebx movr d,0.1 movr e,-0.75 movr f,-0.75 jmp fin @@: cmp edx,200 jg @f movr a,0.1 mov b,ebx mov c,ebx movr d,0.1 movr e,0.75 movr f,0.75 jmp fin @@: cmp edx,310 jg @f movr a,0.1 mov b,ebx mov c,ebx movr d,0.1 movr e,-0.75 movr f,0.75 jmp fin @@: cmp edx,420 jg @f movr a,0.1 mov b,ebx mov c,ebx movr d,0.1 movr e,0.75 movr f,-0.75 jmp fin @@: movr a,0.935567 movr b,-0.164966 movr c,0.164966 movr d,0.935567 mov e,ebx mov f,ebx fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul Scale ;st(0) = NewX * 190 fadd ShiftX ;st(0) = NewX * 190 + 320 fistp x ;x = (int) (NewX * 190 + 320) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fmul Scale;st(0) = NewY * 190 fsubr ShiftY;st(0) = -NewY * 190 + 405 fistp y ; y = (int) (-NewY * 190 + 405) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FFFFFFh @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Spiral Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? Scale dd 190.0 ShiftX dd 320.0 ShiftY dd 185.0 end Результат
Когтиисходный текст и ехе-файл здесьКоэффициенты abcdefp0.70.2-0.20.70.00.00.50.0-0.60.60.01.0-0.60.5 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ;0.7 0.2 -0.2 0.7 0.0 0.0 0.5 ;0.0 -0.6 0.6 0.0 1.0 -0.6 0.5 mov XCC,rbx mov YCC,rbx mov i,60000 bucle: call rand mov ecx,1000 xor edx,edx div ecx cmp edx,400 jg @f movr a,0.7 movr b,0.2 movr c,-0.2 movr d,0.7 mov e,ebx mov f,ebx jmp fin @@: mov a,ebx movr b,-0.6 movr c,0.6 mov d,ebx movr e,1.0 movr f,-0.6 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul const340;st(0) = NewX * 340 fadd const120;st(0) = NewX * 340 + 120 fistp x ;x = (int) (NewX * 470 + 120) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fchs ;st(0) = -NewY fmul const340;st(0) = -NewY * 340 fadd const160;st(0) = -NewY * 340 + 160 fistp y ; y = (int) (-NewY * 340 + 160) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FFFFFFh ;*(pMainDIB + y*cdXSize*4 + x*4) = white color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_APPWORKSPACE ;hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Talon Fractal',0 bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const340 dd 340.0 const120 dd 120.0 const160 dd 160.0 end Результат
Кленисходный текст и ехе-файл здесьКоэффициенты abcdefp0.49-0.0100.620.250.020.316*10000=31600.27-0.520.40.360-0.560.316*10000=31600.180.73-0.50.260.88-0.080.316*10000=31600.040.01-0.500.52-0.320.052*10000= 520 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; 0.49 -0.01 0 0.62 0.25 0.02 0.316*10000=3160; ; 0.27 -0.52 0.4 0.36 0 -0.56 0.316*10000=3160;6320 ; 0.18 0.73 -0.5 0.26 0.88 -0.08 0.316*10000=3160;9480 ; 0.04 0.01 -0.5 0 0.52 -0.32 0.052*10000= 520 mov XCC,rbx mov YCC,rbx mov i,48000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,3160 jg @f movr a,0.49 movr b,-0.01 mov c,ebx movr d,0.62 movr e,0.25 movr f,0.02 jmp fin @@: cmp edx,6320 jg @f movr a,0.27 movr b,-0.52 movr c,0.4 movr d,0.36 mov e,ebx movr f,-0.56 jmp fin @@: cmp edx,9480 jg @f movr a,0.18 movr b,0.73 movr c,-0.5 movr d,0.26 movr e,0.88 movr f,-0.08 jmp fin @@: movr a,0.04 movr b,0.01 movr c,-0.5 mov d,ebx movr e,0.52 movr f,-0.32 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fmul const470;st(0) = NewX * 470 fadd const82 ;st(0) = NewX * 470 + 82 fistp x ;x = (int) (NewX * 470 + 82) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fchs ;st(0) = -NewY fmul const470;st(0) = -NewY * 470 fadd const42;st(0) = -NewY * 470 + 42 fistp y ; y = (int) (-NewY * 470 + 42) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,y,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FF8000h ;*(pMainDIB + y*cdXSize*4 + x*4) = orange color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Maple Fractal',0 bi BITMAPINFO <<28h,640,-430,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? const470 dd 470.0 const82 dd 82.0 const42 dd 42.0 end Результат
Лестницыисходный текст и ехе-файл здесьКоэффициенты abcdefp0.50.50000.50.08*10000=8000.50.5000-0.50.08*10000=800 0 0 0.5 0.5 0.5 0 0.08*10000=800000.50.5-0.500.08*10000=8000.85-0.15 0.150.85000.68*10000=6800 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ; a b c d e f p ; 0.5 0.5 0 0 0 0.5 0.08*10000=800 ; 0.5 0.5 0 0 0 -0.5 0.08*10000=800 ; 0 0 0.5 0.5 0.5 0 0.08*10000=800 ; 0 0 0.5 0.5 -0.5 0 0.08*10000=800 ; 0.85 -0.15 0.15 0.85 0 0 0.68*10000=6800 mov XCC,rbx mov YCC,rbx mov i,390000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,800 jg @f movr a,0.5 movr b,0.5 mov c,ebx mov d,ebx mov e,ebx movr f,0.5 jmp fin @@: cmp edx,1600 jg @f movr a,0.5 movr b,0.5 mov c,ebx mov d,ebx mov e,ebx movr f,-0.5 jmp fin @@: cmp edx,2400 jg @f mov a,ebx mov b,ebx movr c,0.5 movr d,0.5 movr e,0.5 mov f,ebx jmp fin @@: cmp edx,3200 jg @f mov a,ebx mov b,ebx movr c,0.5 movr d,0.5 movr e,-0.5 mov f,ebx jmp fin @@: movr a,0.85 movr b,-0.15 movr c,0.15 movr d,0.85 mov e,ebx mov f,ebx fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fadd e ;st(0) = a * XCC + b * YCC + e fst NewX ;NewX = a * XCC + b * YCC + e fimul Scale;st(0) = NewX * 360 fiadd ShiftX ;st(0) = NewX * 360 + 320 fistp x ;x = (int) (NewX * 360 + 320) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fimul Scale;st(0) = NewY * 300 fisubr ShiftY;st(0) = -NewY * 360 + 185 fistp y ; y = (int) (-NewY * 360 + 185) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FFFFFFh ;*(pMainDIB + y*cdXSize*4 + x*4) = white color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Stairway Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? Scale dd 360 ShiftX dd 320 ShiftY dd 185 end Результат
Дерево #1 исходный текст и ехе-файл здесьКоэффициенты abcdefp0000.50000.05*100000=5000.42-0.420.420.4200.2 0.4*100000=40000.420.42-0.420.4200.20.4*100000=40000.1000.100.20.15*10000=1500 Код (ASM): include win64a.inc include msvcrt.inc includelib gdi32.lib includelib msvcrt.lib IMAGE_BASE equ 400000h cdXPos equ 131 cdYPos equ 217 cdYSize equ 430 cdXSize equ 640 movr macro x,y mov x,0 org $-4 dd y endm .code WndProc proc hWnd:QWORD,Msg:QWORD,wParam:QWORD,lParam:QWORD local ps:PAINTSTRUCT local hdc:qword local hOldBmp:qword local hGDITmp:qword local hOldDIB:qword local hBackDC:qword local hMainDIB:qword local bufBMP:qword local i:dword local x:dword local y:dword local a:dword local b:dword local c:dword local d:dword local e:dword local f:dword local NewX:qword local NewY:qword local XCC:qword local YCC:qword push rbp mov ebp, esp sub esp,(50h+sizeof PAINTSTRUCT+11*8+9*4+15)and(-16) mov hWnd,rcx cmp edx, WM_DESTROY jz wmDESTROY cmp edx, WM_PAINT jz wmPAINT cmp edx, WM_CREATE jz wmCREATE leave jmp DefWindowProc ; --------------------------------------------------------------------------- wmDESTROY::mov rdx,hOldBmp mov rcx,hBackDC call SelectObject mov hGDITmp,rax mov rcx,bufBMP call DeleteObject mov rcx,hBackDC call DeleteDC mov rdx,hOldDIB mov rcx,bufDIBDC call SelectObject mov hGDITmp,rax mov rcx,bufDIBDC call DeleteDC mov rcx,hMainDIB call DeleteObject mov rcx,hWnd call DestroyWindow xor ecx,ecx ; nExitCode call ExitProcess ; --------------------------------------------------------------------------- wmPAINT:lea edx,ps call BeginPaint mov hdc,rax mov qword ptr [rsp+40h],SRCCOPY; rop xor edx,edx ; x mov [rsp+38h],rdx ; y1 mov [rsp+30h],rdx ; x1 mov rax,bufDIBDC ; hdcSrc mov [rsp+28h],rax mov rax,cdYSize mov [rsp+20h],rax mov r9,cdXSize ; cx xor r8d,r8d ; cy mov rcx,hdc ; hdc call BitBlt lea edx,ps mov rcx,hWnd call EndPaint jmp wmBYE ; --------------------------------------------------------------------------- wmCREATE:mov rcx,hWnd call GetDC mov hdc,rax mov rcx,rax ; HDC call CreateCompatibleDC mov bufDIBDC,rax mov [rsp+28h],rbx mov [rsp+20h],rbx mov r9d,offset pMainDIB mov r8d,DIB_RGB_COLORS mov edx,offset bi mov rcx,hdc call CreateDIBSection mov hMainDIB,rax mov rdx,rax; hMainDIB mov rcx,bufDIBDC call SelectObject mov rax,hOldDIB mov rdx,hdc mov rcx,hWnd call ReleaseDC; // Libera device context ;Init-------------------------------------------------------- ;a b c d e f p ;0 0 0 0.50 0 0 0.05 500 ;0.42 -0.42 0.42 0.42 0 0.2 0.4 4000 ;0.42 0.42 -0.42 0.42 0 0.2 0.4 4000 ;0.1 0 0 0.1 0 0.2 0.15*10000= 1500 mov XCC,rbx mov YCC,rbx mov i,150000 bucle: call rand mov ecx,10000 xor edx,edx div ecx cmp edx,500 jg @f mov a,ebx mov b,ebx mov c,ebx; c = 0 movr d,0.5 mov f,ebx jmp fin @@: cmp edx,4500 jg @f movr a,0.42 movr b,-0.42 movr c,0.42 movr d,0.42 movr f,0.2 jmp fin @@: cmp edx,8500 jg @f movr a,0.42 movr b,0.42 movr c,-0.42 movr d,0.42 movr f,0.2 jmp fin @@: movr a,0.1 mov b,ebx mov c,ebx movr d,0.1 movr f,0.2 fin: fld a ;st(0) = a fmul XCC ;st(0) = a * XCC fld b ;st(0) = b fmul YCC ;st(0) = b * YCC faddp ;st(0) = a * XCC + b * YCC fst NewX ;NewX = a * XCC + b * YCC fmul Scale ;st(0) = NewX * 900 fadd ShiftX ;st(0) = NewX * 900 + 320 fistp x ;x = (int) (NewX * 900 + 320) mov eax,x cmp eax,cdXSize jae @f fld c ;st(0) = c fmul XCC ;st(0) = c * XCC fld d ;st(0) = d fmul YCC ;st(0) = d * YCC faddp ;st(0) = c * XCC + d * YCC fadd f ;st(0) = c * XCC + d * YCC + f fst NewY ;NewY = c * XCC + d * YCC + f fst YCC ;YCC = NewY fmul Scale;st(0) = NewY * 900 fsubr ShiftY;st(0) = -NewY * 900 + 405 fistp y ; y = (int) (-NewY * 900 + 405) mov ecx, y cmp ecx,cdYSize jae @f imul ecx,cdXSize*4 add rcx,pMainDIB mov dword ptr [rcx+rax*4],0FF00h ;*(pMainDIB + y*cdXSize*4 + x*4) = black color @@: fld NewX ;XCC = NewX fstp XCC dec i jnz bucle wmBYE: leave retn WndProc endp WinMain proc local msg:MSG push rbp mov ebp,esp sub esp,sizeof MSG xor ebx,ebx mov esi,IMAGE_BASE mov edi,offset ClassName push rbx ;hIconSm push rdi ;lpszClassName push rbx ;lpszMenuName push COLOR_WINDOWTEXT; hbrBackground push rbx ;hCursor push rbx ;hIcon push rsi ;hInstance push rbx ;cbClsExtra & cbWndExtra db 68h dd WndProc ;lpfnWndProc push sizeof WNDCLASSEX ;cbSize & style mov ecx,esp ;addr WNDCLASSEX call RegisterClassEx push rbx push rsi ;rsi=400000h push rbx push rbx push cdYSize push cdXSize push cdYPos push cdXPos mov r9d,WS_VISIBLE mov r8,rdi ;offset ClassName mov edx,edi ;offset ClassName xor ecx,ecx sub esp,20h ; dwExStyle call CreateWindowEx @@: lea ecx,msg xor edx,edx xor r8d,r8d xor r9d,r9d call GetMessage cmp msg.wParam,VK_ESCAPE;user press 'Esc'? je wmDESTROY lea ecx,msg call DispatchMessage jmp @b WinMain endp .data ClassName db 'Tree #1 Fractal',0 bi BITMAPINFO <<28h,cdXSize,-cdXSize,1,32,0,0,0,0,0,0>> bufDIBDC dq ? pMainDIB dq ? Scale dd 900.0 ShiftX dd 320.0 ShiftY dd 405.0 end Результат
Добавлю пару простых примеров. Строятся методом хаоса, без IFC-матрицы. Регистрами общего назначения. Целочисленными инструкциями. Случайные числа генерируются функцией CryptGenRandom Треугольник Серпинского Код (ASM): ;x = (x + x_A)/2 mov rax,x add rax,x_A ;x = x + x_A shr rax,1 ;x = x/2 mov x,rax ;Store x ;y = (y + y_A)/2 mov rax,y add rax,y_A ;y = y + y_A shr rax,1 ;y = y/2 mov y,rax ;Store y Ковёр Серпинского Код (ASM): ;x = (x + 2*x_A) / 3 xor rdx,rdx ;Dividend mov rcx,3 ;Divisor mov rax,x add rax,x_A ;x = x + x_A add rax,x_A ;x = x + x_A div ecx ;x = x/3 mov x,rax ;Store x ;y = (y + 2*y_A) / 3 xor rdx,rdx ;Dividend mov rcx,3 ;Divisor mov rax,y add rax,y_A ;y = y + y_A add rax,y_A ;y = y + y_A div ecx ;y = y/3 mov y,rax ;Store y
Фрактал должен быть ярким. Фрактал – это всегда праздник. Sie trinkt in Nachtklubs immer Sekt. Korrekt! Код (ASM): ;RED ;Load Previous r[0] to RAX ;r[0] = [lpGasketData+4] = Variable mov rsi,lpGasketData add rsi,4 ;r[0] xor rax,rax ;Calculate in AX mov al,byte ptr [rsi] ;r = (r + 2*r_A)/3 ;Shift the Pointer to First Vertex g[1] add rsi,3 ;r[1] = [lpGasketData+9] ;Shift to Active Vertex add rsi,rbx ;Add Generated Random twice xor rcx,rcx ;Use to avoid OverFlow mov cl,byte ptr [rsi] add ax,cx add ax,cx ;r = r/3 xor rdx,rdx ;Dividend mov rcx,3 ;Divisor div rcx ;Store New r[0] ;r[0] = [lpGasketData+4] = Variable mov rsi,lpGasketData add rsi,4 ;r[0] mov byte ptr [rsi],al ;Load New r[0] to R9 shl r9,8 ;Prepare empty space add r9b,al
Реализован N-угольник. Распределение цветов по спектру неравномерное, т.к. цвет точки считается тем же фрактальным алгоритмом и зависит от цвета вершины. А цвет вершины считается как 3*FF/N, т.е. зависит от количества вершин, а не от их положения. Истинная равномерность может быть достигнута двумя способами: 1) дополнительно корректировать цвет вершин. Но это сложно. 2) считать цвет точки от её собственных координат. Но это не наш метод. Код (ASM): finit lblNgonCalcVertex: ;Next Step add rsi,4 ;Next X add rdi,4 ;Next Y ;x[i] = r*cos(a)+xC fld dword ptr [rax] ;a fcos ;cos(a) fimul dword ptr [rdx] ;r*cos(a) fiadd dword ptr [r8] ;r*cos(a)+xC fistp dword ptr [rsi] ;Integer ;y[i] = r*sin(a)+yC fld dword ptr [rax] ;a fsin ;sin(a) fimul dword ptr [rdx] ;r*sin(a) fiadd dword ptr [r9] ;r*sin(a)+yC fistp dword ptr [rdi] ;Integer ;Increase Angle fld dword ptr [rax] ;a fadd dword ptr [rbx] ;a = a + a0 fstp dword ptr [rax] ;Real ;Check for Loop dec rcx cmp rcx,0
красиво, но зачем? exe - понимает только ibm-compatible windows system...рисуйте в avi, mp4, mkv, blender в помощь!!!
OpenGL. Идём в 3D По поводу оптимизации - прошу не кидать тапками. Понятно, что надо всё считать в XMM-регистрах. Потом допилю.
Добрались до AVX и FMA-инструкций (требуют RDRAND!, но по причине модульности другой механизм рандомизации внедрябелен)
Допилил. Через полтора года. Но всё сделано: (1) треугольник Серпинского, (2) ковёр Серпинского, (3) пирамида Серпинского, (4) губка Менгера и (5) обобщение в n-угольник Для каждого из фракталов есть реализация: (а) на x87, (б) на SSE, (в) на AVX и (г) на FMA (хотя FMA для такого алгоритма преимуществ не даёт). Написаны на fasm. Метод генерации случайности - RdRand (прошу меня извинить, но это очень соблазнительно - добывать случайность одной инструкцией). Для n-угольника написан корректный расчёт цвета. Теперь на пути: (1) лента Мёбиуса, (2) обобщение в пространственный n-гранник, (3) IFS-матрица, (4) тессеракт с вращением вокруг гиперплоскости и... всё вышеперечисленное в едином MDI-интерфейсе ...И самое главное - новый код для встроенной графики. Зачем мне делать расчёты в XMM-регистрах, а потом через контроллеры, шину и память перекомпоновывать результаты обратно XMM-регисты для вызова OpenGL-функций?! Mikl__, помогите, пожалуйста: я вижу, что отстаю от отрасли на десятки лет. Как программировать встроенную в CPU графику? Почему эти инструкции не документированы?
Обещанное обобщение в пространственный n-гранник. Как показывает практика, для метода хаоса сам процесс построения точки довольно прост. Он сводится к решению линейных уравнений вида y=kx+b, которые FMA решает одной инструкцией. А вот построение вершин-аттракторов может быть очень даже интересным. В будущем построю пространственный фрактал с аффинными преобразованиями. И посчитать цвет для произвольного n-угольника - тоже маленькая задачка. Код (ASM): .BallVertexColorRule1: ;Red mov dword [r13],1.0 ;Red mov dword [r15],0.0 ;Blue ;Green Up finit fld dword [r11] ;st0 = a[i] fdiv dword [c1pi3] ;st0 = a[i]/(pi/3) fstp dword [r14] ;Green jmp .BallVertexColorLoop .BallVertexColorRule2: ;Yellow mov dword [r14],1.0 ;Green mov dword [r15],0.0 ;Blue ;Red Down finit fld dword [r11] ;st0 = a[i] fsub dword [c1pi3] ;st0 = st0-pi/3 fdiv dword [c1pi3] ;st0 = st0/(pi/3) fld1 fsub st0,st1 ;st0 = 1-st1 fstp dword [r13] ;Red jmp .BallVertexColorLoop ... .BallVertexColorRule6: ;Purple mov dword [r13],1.0 ;Red mov dword [r14],0.0 ;Green ;Blue Down finit fld dword [r11] ;st0 = a[i] fsub dword [c5pi3] ;st0 = st0-5*pi/3 fdiv dword [c1pi3] ;st0 = st0/(pi/3) fld1 fsub st0,st1 ;st0 = 1-st1 fstp dword [r15] ;Blue ;jmp .BallVertexColorLoop А пока - для развлечения - построение n-гранника с произвольным количеством вершин. Наверное, в геометрии такое тело имеет название, но не суть... Код (ASM): ;Latitudinal Sections mov rax,qword [m] mov qword [j],rax ;Counter = m add r12,20h ;Next Angle add r13,20h ;Next X add r14,20h ;Next Y add r15,20h ;Next Z .BallNextZ: mov rax,qword [n] mov qword [i],rax ;Counter = n ;zj = cos(dA*j) ;Scale Factor = sin(dA*j) finit fld dword [dA] ;st0 = dA ;fimul because n is an integer fimul dword [j] ;st0 = a[j] fsincos ;st0 = cos(a) ;st1 = sin(a) fstp dword [zPosition] ;zj = cos(a) fstp dword [zFactor] ;k = sin(a) .BallNextXY: ;xi = cos(dA*i) ;yi = sin(dA*i) fld dword [dA] ;st0 = dA ;fimul because n is an integer fimul dword [i] ;st0 = a[i] fst dword [r12] ;a[i] = st0 fsincos ;st0 = cos(a) ;st1 = sin(a) fmul dword [zFactor] ;st0 = k*cos(a) fstp dword [r13] ;x[0] = k*cos(a) fmul dword [zFactor] ;st0 = k*sin(a) fstp dword [r14] ;y[0] = sin(a) mov eax,dword[zPosition] mov dword [r15],eax ;Next Vertex add r12,20h ;Next Angle add r13,20h ;Next X add r14,20h ;Next Y add r15,20h ;Next Z ;Next Vertex dec [i] cmp [i],0 jg .BallNextXY ;Next Latitudinal Section ;Check for Loop dec [j] cmp [j],0 jg .BallNextZ