2012年7月5日星期四

Feigenbuam.asm


; Generating the Feigenbuam diagram, which illustrates the onset of chaos.

; by  Ron Thomas 19/5/99 

;   Ron Thomas Ron_Thom@Compuserve.com 15/5/99 
;---------------------------------------------
;Feigenbaum Diagram

;This example illustrates Feigenbaum's period doubling demonstation of the onset of chaos.
;Refer to "Chaos and Fractals" by Peitgen, Jurgerns and Saupe if you want to delve into 
;this interesting branch of mathematics.

;Enjoy

;Ron Thomas

;Ron_Thom@Compuserve.com

;www.rbthomas.freeserve.co.uk

;19/5/99
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;以上是原作者的说明,
;这是我从国外(俄国)的一个网站下载的。
;这个也算是经典的分形图。
;这个程序我存放半年多了,特放出来与需要的人共享。
;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
includelib kernel32.lib

include user32.inc
includelib user32.lib

include gdi32.inc 
includelib gdi32.lib 

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

cxClient DD ?
cyClient DD ?

x  DD ?  ; Coordinates of point to be plotted
y  DD ?
xx  DD ?  ; X coord we actually plot
hide  DD 10 ; Iteration control (small >more detail)
two40  DD 240  ; Selected to give the best picture
temp  DD ?
  
STATUS dw 0  ; Status word

k  real4 ?
p  real4 0.01
one  real4 1.0
scaleX  real4 0.0

CompareFP PROC 
  FCOM                    ; a,b
  FSTSW   STATUS          ; Store status word
  FWAIT
  MOV     AH,BYTE PTR STATUS + 1
  SAHF                    ; AH > flags register
  JA      SHORT  BIGGER   ; Jump if a > b
  CLC
  RET 
BIGGER: STC   ; Flag that a > b
  RET
CompareFP   ENDP

liuchunli proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
LOCAL hdc:HDC, ps:PAINTSTRUCT, msg:MSG
.if uMsg == WM_CLOSE;放置后面会反应更快点。
  invoke DestroyWindow,hWinMain
  invoke PostQuitMessage,0
.elseif uMsg == WM_SIZE
  finit 
  mov eax,lParam
  and eax,0FFFFh

  mov cxClient,eax

  fild cxClient  ; Compute scaling factor
  mov temp,800 
  fidiv temp
  fstp scaleX  

  mov ebx,lParam
  shr ebx,16

  mov cyClient,ebx
.elseif uMsg == WM_PAINT  
  invoke BeginPaint,hWnd, ADDR ps
  mov    hdc,eax

  finit   ;Initialise the coprocessor

  mov x,1
  mov edi, 720

  .WHILE x < edi   ; Move along x axis
    fild x
    fidiv two40   ; i/240
    fadd one   ; 1 + i/240 
    fstp k   ; New K value

    mov esi,1   
next_point:
    fld1
    fsub p   ; 1-p
    fmul p   ; p*(1-p)
    fmul k   ; k*p*(1-p)
    fstp p   ; Update p

    cmp esi,hide  ; iterate a few times 
    jl skip

    fld1    ; Push 1.0 onto stack
    fld p   ; p,1

    invoke CompareFP  ; p > 1 ?

    jc skip   ; Jump if true

    fldz    ; 0,p,1
    fstp st(2)   ; > st=0,p
    invoke CompareFP  ; p < 0 ?   
    jnc skip   ; jump if less than 0

    fild x
    fmul scaleX   ; scale x value
    fistp xx  

    fld1    ; 1
    fsub p   ; 1 - p
    fimul cyClient  ; scaled value 
    fistp y   ; Y = scaled value

    invoke SetPixel, hdc, xx, y, 255

skip:fstp st   ; Flush 2 values off stack
    fstp st 
    inc esi
    cmp esi,400   ; Test against iteration number
    ; Use 800 for more detail - it is however slower
    jl next_point  ; Go round again

    inc x
  .ENDW
  invoke EndPaint,hWnd, ADDR ps
.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 LoadCursor,0,32512;加载箭头鼠标。
mov pwndclassex+28,eax

invoke RegisterClassEx,addr pwndclassex
invoke CreateWindowEx,200h,offset szClassName,offset szClassName,0Cf0000h,80000000h,80000000h,80000000h,80000000h,0,0,hInstance,0;0Ca0000h
mov hWinMain,eax

invoke ShowWindow,hWinMain,1;若不想显示,此行也可以去掉。
again:invoke GetMessage,addr stMsg,0,0,0
  cmp eax,0
  je exit
  invoke DispatchMessage,addr stMsg
jmp again

exit:invoke ExitProcess,0
end start
;made at 2011.09.24 

没有评论:

发表评论