peter
20-02-2014, 22:21
Hello,
Of course, an api-mandelbrot should not be missed.
Uses "ui"
#INCLUDE "api.inc"
DWord hwnd,hdc
hwnd = Canvas_Window("api_app",xMid(640),yMid(480),640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
Canvas_Font "courier",16, %CANVAS_FONTSTYLE_BOLD
Single lx,ly,x,y,a2,b2,a,b,z,c,x2,y2,t1,t2
lx = 3 / 640
ly = 2 / 480
t1 = ticks
For x=0 To 640
For y=0 To 480
a = 0
b = 0
c = 0
x2 = lx*x-2
y2 = ly*y-1
While c<50
a2 = a*a-b*b
b2 = 2*a*b
a = a2 + x2
b = b2 + y2
z = a*a+b*b
If z >=4 Then Exit While
c +=1
Wend
If c=50 Then
SetPixel hdc,x,y, 0
ElseIf c<17 Then
SetPixel hdc,x,y, Rgb( 245 -((17-c)*3),0, 0)
ElseIf c<33 Then
SetPixel hdc,x,y, Rgb( 245, ((c-16)*16)-16, 0)
Else
Win_SetPixelV hdc,x,y, Rgb( 641 -(c*12), 245, ((c-32)*15))
EndIf
Next
Canvas_Redraw
Next
t2 = ticks
t2 = (t2-t1)/1000
While IsWindow(hwnd) And KeyDown(%VK_ESCAPE)=0
DrawText 0,0,"Needed time " & t2 & " secs", Rgb 255,255,255
Canvas_Redraw
Sleep 10
Wend
Canvas_Window End
Of course, an api-mandelbrot should not be missed.
Uses "ui"
#INCLUDE "api.inc"
DWord hwnd,hdc
hwnd = Canvas_Window("api_app",xMid(640),yMid(480),640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
Canvas_Font "courier",16, %CANVAS_FONTSTYLE_BOLD
Single lx,ly,x,y,a2,b2,a,b,z,c,x2,y2,t1,t2
lx = 3 / 640
ly = 2 / 480
t1 = ticks
For x=0 To 640
For y=0 To 480
a = 0
b = 0
c = 0
x2 = lx*x-2
y2 = ly*y-1
While c<50
a2 = a*a-b*b
b2 = 2*a*b
a = a2 + x2
b = b2 + y2
z = a*a+b*b
If z >=4 Then Exit While
c +=1
Wend
If c=50 Then
SetPixel hdc,x,y, 0
ElseIf c<17 Then
SetPixel hdc,x,y, Rgb( 245 -((17-c)*3),0, 0)
ElseIf c<33 Then
SetPixel hdc,x,y, Rgb( 245, ((c-16)*16)-16, 0)
Else
Win_SetPixelV hdc,x,y, Rgb( 641 -(c*12), 245, ((c-32)*15))
EndIf
Next
Canvas_Redraw
Next
t2 = ticks
t2 = (t2-t1)/1000
While IsWindow(hwnd) And KeyDown(%VK_ESCAPE)=0
DrawText 0,0,"Needed time " & t2 & " secs", Rgb 255,255,255
Canvas_Redraw
Sleep 10
Wend
Canvas_Window End