Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Don't sweat it -- it's only ones and zeros. -- P. Skelly


devel / comp.lang.tcl / Can I shift the coordinates of a canvas?

SubjectAuthor
* Can I shift the coordinates of a canvas?Luc
`- Can I shift the coordinates of a canvas?Robert Heller

1
Can I shift the coordinates of a canvas?

<20221111134348.1ed71fdf@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10129&group=comp.lang.tcl#10129

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!ac6OoMHkWYPV8qf+a92lSg.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Can I shift the coordinates of a canvas?
Date: Fri, 11 Nov 2022 13:43:48 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221111134348.1ed71fdf@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="42889"; posting-host="ac6OoMHkWYPV8qf+a92lSg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Fri, 11 Nov 2022 16:43 UTC

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
>>

Re: Can I shift the coordinates of a canvas?

<YS6dnbiDqZ-BPfP-nZ2dnZfqn_WdnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10130&group=comp.lang.tcl#10130

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!69.80.99.26.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 11 Nov 2022 19:18:52 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: Can I shift the coordinates of a canvas?
In-Reply-To: <20221111134348.1ed71fdf@lud1.home>
References: <20221111134348.1ed71fdf@lud1.home>
Newsgroups: comp.lang.tcl
Content-Type: text/plain; charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <YS6dnbiDqZ-BPfP-nZ2dnZfqn_WdnZ2d@giganews.com>
Date: Fri, 11 Nov 2022 19:18:52 +0000
Lines: 89
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-eReYcf/VAS8zTJ4yP7fXfyPuHO1EZwnp1ix/t+TIn+ZOPFvwpchOiniVTRHEHmdR+KzfLjMCpJqhVb9!1zTfwholHaCe2OGnLntOVXG4FAwWWajfL8nsyVzJQpK31QQoe3cLO2w0P7m4lkI7VDR3GDalqgdu!r/U=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Received-Bytes: 4431
 by: Robert Heller - Fri, 11 Nov 2022 19:18 UTC

At Fri, 11 Nov 2022 13:43:48 -0300 Luc <no@no.no> wrote:

>
> 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?

Yes. What you do is set the canvas's *Scroll Region*:

$::w.outer.canv configure -scrollregion [list -540 -540 540 540]
# left top right bottom

If the window size of the canvas is 1080 x 1080 (1080 = 540 - (-540)), then
the canvas would not need scrollbars and the canvas coords will behave as you
want (0,0 would be the center of the canvas, -540,-540 would be the top left
corner, etc.).

If the canvas is smaller, you can add a set of scrollbars (see "man 3tk
options" re -xscrollcommand and -yscrollcommand, "man 3tk scrollbar", and
"man 3tk canvas re: xview and yview).

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor