Graphics.drawoval

Hello,

I finally figured out how to draw circles, but need to be able to draw them with negative values.

Example:
Graphics.drawOval(-10,-10,20,20)

Is there a way to set the canvas paint property, to go from 0,0 to read show circles with negative values?

Thanks,
Pat

Nothing wrong with what you’ve got right there. Put this in the paint event of a canvas

g.forecolor = &cFF0000 g.drawOval -10, -10, 20, 20

Drawing a circle with negative values will draw them OFF the canvas.

The coodinate system of the canvas is (0,0) -> (width,height) and cannot be changed.

If you are plotting data, then you need to normalize YOUR coordinate system

I am trying to plot the circles like a geometry style graph with x horizontal and y vertical, using both negative and positive values.

The only way I see to do this is to write the numbers with all positive values

Correct… that is what “normalizing your coordinate system” means

If you canvas is 1000 wide and 500 high, and you wish YOUR coordinate system to show (0,0) as the Middle of the canvas
then you take YOUR (x,y) values and add 500 to X and 250 to Y, THEN set the point

Dave is correct. The canvas coordinate system cannot be made to match up with the coordinate system of the graph you’re trying to create. You need to pick a center point and add that offset to your plot values.

On Mac you can translate the Graphics coordinate system like this

Sub translateGraphics(g As Graphics, x As CGFloat, y As CGFloat) #if TargetCocoa then declare sub CGContextTranslateCTM lib "CoreGraphics" (c As Ptr, tx As CGFloat, ty As CGFloat) dim cntxt As Ptr = Ptr( g.Handle(Graphics.HandleTypeCGContextRef) ) CGContextTranslateCTM(cntxt, x, -y) #endif End Sub

and use like this (though an extension method would be more convenient)

[code]Sub Paint(g As Graphics, areas() As REALbasic.Rect)

g.ForeColor = &cFFFFFF
g.FillRect 0, 0, g.Width, g.Height

translateGraphics(g, g.Width/2, g.Height/2) //move origin to center

g.ForeColor = &c008000
g.DrawLine -100, 0, 100, 0
g.DrawLine 0, -100, 0, 100

g.ForeColor = &c00000080
g.FillOval(-50, -50, 200, 50)

End Sub[/code]