2012年7月5日星期四

rose.asm


;rose.asm
;玫瑰线的极坐标方程如下:
;ρ=acos(nθ)或者ρ=asin(nθ)
;不足之处,敬请指导。
;我想fpu指令还有可以优化的地方。
;QQ:112426112
;Email:leguanyuan at 126 dot com
;Homepage:http://correy.webs.com
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib user32.lib
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib

.code
hInstance dd ?
hWinMain dd ?
stMsg MSG <>
szClassName db "correy",0
szCaptionMain db "made by correy",0
pwndclassex dd 48,3,offset liuchunli,0,0,0,0,0,6,0,offset szClassName,0

x DD ? 
y DD ?
n dw ?
n360 dd 360;每一度画一个点 与 位置 大小 等有关。
three dw 3 ;以三叶玫瑰线为例。

temp real4 0.0 
sina real4 0.0
cosa real4 0.0
sin3a real4 0.0 ;这个名字改为sinna为最好。

liuchunli proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL hdc:HDC, ps:PAINTSTRUCT      
.IF uMsg==WM_PAINT  
  invoke BeginPaint,hWnd, ADDR ps
  mov hdc,eax 
  ;invoke MoveToEx,hdc,n360,n360,0;此行与下面的LineTo是配合画线的。你还可以设置线的颜色。
  mov si,0
  .WHILE si <= 3600;画的点数。在画多叶的时候可以增加这个数。
    finit ;不可以放置在圈外面。
    fldpi
    mov n,si
    fimul n
    fidiv n360
    fst temp ;temp = si*n*n360
    
    fsin 
    fst sina;存储sina
    
    fld temp
    fcos 
    fst cosa;存储cosa
    
    fld temp
    fimul three
    fsin
    fst sin3a;存储sin3a
    
    fld st
    fld sina
    fmul
    fimul n360
    fiadd n360
    fist x;x=n360*sin3a*sina+n360.再不对称的时候,可以再加一个数,使之居中。
    
    fld sin3a
    fld st
    fld cosa
    fmul
    fimul n360
    fiadd n360
    fist y;y=n360*sin3a*cosa+n360
    
    invoke SetPixel,hdc,x,y,x
    ;invoke LineTo,hdc,x,y
    inc si
  .ENDW 
invoke EndPaint,hWnd,ADDR ps
.ELSEIF uMsg==WM_DESTROY
  invoke PostQuitMessage,0
.ELSE
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
liuchunli endp

start:invoke GetModuleHandle,0
mov hInstance,eax
mov pwndclassex+20,eax
invoke LoadIcon,hInstance,1;其实这四行也可以去掉。
mov pwndclassex+24,eax
invoke LoadCursor,0,32512
mov pwndclassex+28,eax
invoke RegisterClassEx,addr pwndclassex
invoke CreateWindowEx,200h,offset szClassName,offset szCaptionMain,0ca0000h,80000000h,80000000h,768,768,0,0,hInstance,0;0cf0000h  0ca0000h
mov hWinMain,eax
invoke ShowWindow,hWinMain,1;不想显示这一两行也可以不要。
invoke UpdateWindow,hWinMain
again:invoke GetMessage,addr stMsg,0,0,0
  cmp eax,0
  je exit
  invoke TranslateMessage,addr stMsg;这一行也可以去掉,特别是不处理字符信息。
  invoke DispatchMessage,addr stMsg
jmp again
exit:invoke ExitProcess,0
end start
;made at 2011.04.20

没有评论:

发表评论