how to improve 2d performance and some bugs ?
Posted: Thu Aug 01, 2013 1:15 pm
hi
i am new to pure basic , i wanted to test some 2d drawing .
i have written a radar sweep like program using this code:
there is two problems :
1- it is slow ( i have tried windows screen too)
2- it is supposed for radar to delete previously drawn line when inserting new line but it seems that new line is written with a little different angle ( i guess because of rounding sin and cos )
can any one shed some light on this ?
i am new to pure basic , i wanted to test some 2d drawing .
i have written a radar sweep like program using this code:
Code: Select all
h = 700
w=700
Structure ray
r.i
theta.i
x.i
y.i
sin.f
cos.f
EndStructure
Procedure showmap(height,width,rtheta)
;Delay(1)
EndProcedure
Procedure.f GSin(winkel.f)
ProcedureReturn Sin(winkel*(2*3.14159265/360))
EndProcedure
Procedure.f GCos(winkel.f)
ProcedureReturn Cos(winkel*(2*3.14159265/360))
EndProcedure
Dim rays.ray(360)
For t = 0 To 359
tmp = t
tmp = tmp -90
If (tmp < 0 )
tmp = tmp + 360
EndIf
rtmp.f = Radian(tmp)
xtmp = (w/2) + r * (Int(GCos(tmp)*100)/100)
ytmp = ( h/2) + r * (Int(GSin(tmp)*100)/100)
rays(t)\theta=tmp
rays(t)\x=xtmp
rays(t)\y=ytmp
rays(t)\cos=GCos(tmp)
rays(t)\sin=GSin(tmp)
Next
InitSprite()
OpenWindow(0, 0, 0, h, w, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;OpenWindowedScreen(WindowID(0), 0, 0, h, w, 0, 0, 0, #PB_Screen_WaitSynchronization )
CanvasGadget(0,0,0,h,w)
StartDrawing(CanvasOutput(0))
Box(0,0,h,w,$000000)
StopDrawing()
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Event = 0
r = h / 2
For deg = 0 To 359 Step 1
StartDrawing(CanvasOutput(0))
DrawingMode( #PB_2DDrawing_Transparent)
Circle(w/2,h/2,2,RGB(Random(255), Random(255), Random(255)))
theta = deg
theta = theta -90
If (theta < 0 )
theta = theta + 360
EndIf
rtheta.f = Radian(theta)
rtheta2.f =Radian(theta+1)
rtheta3.f =Radian(theta-1)
r2 = r
LineXY(w/2,h/2,rays(deg+1)\cos*r+w/2,rays(deg+1)\sin*r+h/2,$20f3fa)
If deg = 0
tmpdeg=359
Else
tmpdeg=deg-1
EndIf
LineXY(w/2,h/2,rays(deg)\cos*r+w/2,rays(deg)\sin*r+h/2,$000000)
LineXY(w/2,h/2,rays(tmpdeg)\cos*r+w/2,rays(tmpdeg)\sin*r+h/2,$000000)
For j = 1 To 5
radius = Random(w/2-1)
x.i = Int((w/2) + radius * rays(tmpdeg)\cos)
y.i = Int(( h/2) + radius * rays(tmpdeg)\sin)
Plot(x,y,RGB(Random(255), Random(255), Random(255)))
Next
DrawText(50,650,"theta=" + Str(deg) )
StopDrawing()
Next
Until Quit = 1
1- it is slow ( i have tried windows screen too)
2- it is supposed for radar to delete previously drawn line when inserting new line but it seems that new line is written with a little different angle ( i guess because of rounding sin and cos )
can any one shed some light on this ?