# DrawPolygon - unexpected behaviour

There must be something I’ve done wrong (or simply forgotten). I’ve used DrawPolygon before to draw some simple shapes into the paint event of a canvas and it worked as expected.

It seems as though the xy point of origin is stuck on the top left of the canvas, which is ok and I understand that it is always there, but the line should not draw from there if you change it in code? I’ve mucked around with this for the last 1/2 hour or so - hopefully it’s one of those simple stupid things that we all fall victim to on occasion.

Here’s the code (in the canvas paint event):

[code] // draw ADC symbol ----------------
Dim sx, sy As Integer //set xy origin
sx = 50
sy = 50

g.ForeColor = kBlueMid

g.PenHeight=2
g.PenWidth=2

And here’s the result:

Some of the code has been remarked out for testing purposes, but I was expecting to just get a point/ dot at 50,50 yet the line draws from 0,0.

You use 2 co-ordinates but pass an array with 4 values (it appears index 0 is ignored)

The last 2 co-ordinates in your array are both 0
So you are asking for a polygon from 50,50 to 0,0

Use them all and you get want you wanted… this code draws a triangle:

[code] Dim ADCsymbol (6) As Integer
Dim sx, sy As Integer
sx = 50
sy = 50

Thanks Jeff,

That triangle code (or similar) is what I’ve used in the past - using just a basic triangle (filled):

[code]Dim p (6) as Integer

g.ForeColor = kBlueMid

p(1)=0 'x
p(2)=0 'y
p(3)=12 'x
p(4)=12 'y
p(5)=0 'x
p(6)=24 'y

g.FillPolygon[/code]

Just to change the point of origin seems like a lot of unnecessary covfefe.

I’ll check it out tomorrow.

What Jeff is saying is that your line is being drawn from 50,50 to 0,0, not the other way around. By initializing the array with 4 integer elements, they all start with a value of 0. Then in your code, you’re only changing the first two.

Ok thanks guys - as suggested the issue was with the initializing of the array.

Seems that if too many elements (xy pairs) are defined but not used, the origin and therefore the ‘closed point’ defaults to 0,0.

eg. Draws a Square:

[code] // draw ADC symbol ----------------
Dim sx, sy As Integer //set xy origin
sx = 19
sy = 28

g.ForeColor = kBlueMid