Page 1 of 1

Posted: Sat Jun 22, 2002 6:55 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.

Hi all. :)

I'm using the plot command to draw a sine curve in a window.

The curve looks a bit "dotty" despite using increments of 1. Is there any way of joining up the dots?
I think this may be because the plot command only accepts integer values.

Should I be looking at the pen commands in the WINAPI?

Any advice/suggestions welcome. Thanks!

;------------------------ start of progamme------------------------------------
width=800
height=600
p=6.28
rf=255
gf=255
bf=255
rb=0
gb=0
bb=0
screen_height=getsystemmetrics_(#SM_CYSCREEN) ; get users screen settings
screen_width=getsystemmetrics_(#SM_CXSCREEN) ; get users screen settings
; center the screen
posx=screen_width/2-width/2
posy=screen_height/2-height/2

If OpenWindow(0,posx ,posy , width, height, #PB_Window_SystemMenu , "Graph plotter")
EndIf

Gosub drawscreen:
Gosub drawgraph:


Repeat
EventID.l = WaitWindowEvent()

If EventID = #PB_Event_CloseWindow
quit = 1
EndIf

If EventID = #PB_Event_Repaint
Gosub drawscreen:
Gosub drawgraph:
EndIf

Until quit = 1

End
;---------------------------------- subroutines ---------------------------------------

drawscreen:

StartDrawing(WindowOutput())
Box(30, 20,600 , 300 ,RGB(rb,gb,bb))
StopDrawing()

Return


drawgraph:

StartDrawing(WindowOutput())

For x=1 To 600 Step 2
a=a+1
y=(20*Sin(p*a))
Plot(x+30,y+150,RGB(255,255,255))

Next x

FrontColor(255,255,255)
BackColor(rb,gb,bb)
Locate(30,2)
DrawText("Function xyz")


StopDrawing()

Return



Edited by - branston on 22 June 2002 19:58:37

Posted: Sat Jun 22, 2002 7:12 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Your program works well; the curve seems dotty because, even if you increment "x" by one (not true, you're doing it by two), "y" results differ in distance. One way to have equivalent distances between points would be to calculate the distance between two given points of a curve. But, of course, that calculation is much complex than the one you're using and, so, much slower. I'm sorry if I don't make myself very clear with this paragraph.
The curve looks a bit "dotty" despite using increments of 1. Is there any way of joining up the dots?
I would draw a line between the last drawed dot and the current one, this would add very few lines of code.

Hope it helps,

El_Choni

Posted: Sat Jun 22, 2002 8:30 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.

EL_Choni,

Thanks for your help :)

I hadn't noticed that I was stepping by 2, it should have been 1! :)
I would draw a line between the last drawed dot and the current one, this would add very few lines of code.
Could you give me an example?

I did try using the Line command, but I'm not sure how the "Width" and "Height" fields work in the command. The help file doesn't say :( If the Line command were just Line(x1,y1,x2,y2) I'd see how I could use it!
I'm sorry if I don't make myself very clear with this paragraph.
Not at all. You made yourself very clear :)

Posted: Sat Jun 22, 2002 9:01 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

With v3.20, you have a LineXY() which works as you want..

Fred - AlphaSND

Posted: Sat Jun 22, 2002 9:17 pm
by BackupUser
Restored from previous forum. Originally posted by Branston.
With v3.20, you have a LineXY() which works as you want..

Fred - AlphaSND
Thanks Fred. Perfect! It works beautifully! I've changed the code to this now.

;------------------------ start of progamme------------------------------------

DefType.f a,y ; Make variables a and y floating point?
width=800 ; Graph plotter width
height=600 ; Graph plotter height
p=6.28 ; The constant 2*PI (2*3.14)
rf=255 ; RGB Red colour value
gf=255 ; RGB Green colour value
bf=255 ; RGB Blue colour value
rb=0 ; RGB Red coloyr value
gb=0 ; RGB Green colour value
bb=0 ; RGB Blue colour value


Dim array(600) ; Array to hold graph plotter values.

screen_height=getsystemmetrics_(#SM_CYSCREEN) ; get users screen settings
screen_width=getsystemmetrics_(#SM_CXSCREEN) ; get users screen settings



; center the screen
posx=screen_width/2-width/2
posy=screen_height/2-height/2


If OpenWindow(0,posx ,posy , width, height, #PB_Window_SystemMenu , "Graph plotter")
EndIf


Gosub drawscreen:
Gosub drawgraph:
Repeat

EventID.l = WaitWindowEvent()


If EventID = #PB_Event_CloseWindow
quit = 1
EndIf

If EventID = #PB_Event_Repaint
Gosub drawscreen:
Gosub drawgraph:
EndIf

Until quit = 1

End


drawscreen:


StartDrawing(WindowOutput())

Box(30, 20,600 , 300 ,RGB(rb,gb,bb)) ; main display window

StopDrawing()

Return


drawgraph:

StartDrawing(WindowOutput())

For x=0 To 600 Step 1
a=a+0.01
y=100*Sin(p*a)+30*Sin(3*p*a)
array(x)=y
Next x

For x=0 To 599 Step 1
LineXY(x+30,array(x)+150,x+31,array(x+1)+150,RGB(0,255,0))
Next x

For x=0 To 600 Step 1
Plot(x+30,array(x)+150,RGB(255,0,0))
Next x



FrontColor(255,255,255)
BackColor(rb,gb,bb)
Locate(30,2)
DrawText("Function y=100*Sin(x)+30*Sin(3*x)")


StopDrawing()

Return

Edited by - branston on 22 June 2002 23:40:33

Edited by - branston on 23 June 2002 00:02:53