I'm studying canvas and I decided to make a classic X/Y chart for plotting functions and equations.
It looks good!
# ------------- MAKE WINDOW --------------
package require Tk
wm withdraw .
eval destroy [winfo children .]
set ::w [toplevel .mycanvas]
bind $::w <Escape> {exit 0}
wm protocol $::w WM_DELETE_WINDOW {exit 0}
# -------------- OUTER FRAME -------------
frame $::w.outer
pack $::w.outer -fill both -expand 1
# ----------- MEASURE WINDOW -------------
set wh [winfo screenheight $::w.outer]
set ww [winfo screenwidth $::w.outer]
set midwh [expr $wh / 2]
set midww [expr $ww / 2]
# ----------- DRAW CANVAS ----------------
canvas $::w.outer.canv
$::w.outer.canv configure -height $wh -width $ww
pack $::w.outer.canv
for {set x 0} {$x < $wh} {set x [expr $x + 40]} {
$::w.outer.canv create line 0 $x $ww $x -fill #E5E5E5
}
for {set x 0} {$x < $ww} {set x [expr $x + 40]} {
$::w.outer.canv create line $x 0 $x $wh -fill #E5E5E5
}
$::w.outer.canv create line 0 $midwh $ww $midwh -fill black
$::w.outer.canv create line $midww 0 $midww $wh -fill black
wm attributes $::w -zoomed 1
# ------------------------------------
Now, the 0 coordinate refers to either the leftmost edge (x) or the top
of the screen (y).
Of course I can work with that.
But I would love to be able to "shift" everything so that zero always refers
to the middle vertical line (x) and the middle horizontal line (y) when
writing code, I mean:
Instead of writing
$::w.outer.canv create line 0 540 1920 540 -fill black
I would write
$::w.outer.canv create line -540 0 540 0 -fill black
So the leftmost edge is now negative and the center is zero.
I read the manual page and found a section that explains about COORDINATES
and COORDINATES, but I don't really understand what it says. For example,
"Canvases do not support scaling or rotation of the canvas coordinate system relative to the window coordinate system."
So is it possible to change the entire reference point of a canvas so that
zero is always the center?
--
Luc
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)