Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #153: Big to little endian conversion error


comp / comp.lang.tcl / Re: How to center a circle?

SubjectAuthor
* How to center a circle?Helmut Giese
+* Re: How to center a circle?Ralf Fassel
|`* Re: How to center a circle?Helmut Giese
| +* Re: How to center a circle?Ralf Fassel
| |`* Re: How to center a circle?Helmut Giese
| | +- Re: How to center a circle?et99
| | `- Re: How to center a circle?Ralf Fassel
| `- Re: How to center a circle?Rich
`* Re: How to center a circle?Helmut Giese
 +- Re: How to center a circle?saito
 `* Re: How to center a circle?Shaun Deacon
  `- Re: How to center a circle?Helmut Giese

1
Subject: How to center a circle?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Wed, 16 Oct 2024 13:15 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: How to center a circle?
Date: Wed, 16 Oct 2024 15:15:15 +0200
Organization: ratiosoft
Lines: 46
Message-ID: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 16 Oct 2024 15:15:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e9762f795d257d7644cc8b1c5eedd85";
logging-data="2392988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J2PHSQNTcs4rxRSTclTTM"
Cancel-Lock: sha1:faReJ7pw7Q9qNK/VQaFcvntAtbg=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello out there,
I always considered me smart enough to center a circle on a square
canvas - but I was proven wrong which the following program shows. If
you call it normally it uses TkPath, if it sees any argument it uses
Tk. The outcome seems to be the same in both cases - except for the
rugged outline in the Tk version. The added retangle shows it even
more clearly.
---
package require Tk
package require tkpath
foreach ch [winfo children "."] {destroy $ch}

set useTK 0
if {$argc} {
set useTK 1
} if {$useTK} {
set c [canvas .c -background gray50 -width 200 -height 200]
} else {
set c [tkp::canvas .c -background gray50 -width 200 -height 200]
} pack $c -padx 10 -pady 10

set width [$c cget -width]
set height [$c cget -height]

set x1 [expr {$width * 0.04}]
set y1 $x1
set x2 [expr {$width - $width * 0.04}]
set y2 $x2
if {$useTK} {
$c create oval $x1 $y1 $x2 $y2 -fill white -outline white
puts "width: $width, x1/y1 - x2/y2: $x1/$y1 - $x2/$y2"
} else {
set xc [expr {$x1 + ($x2 - $x1) / 2.0}]
set yc [expr {$y1 + ($y2 - $y1) / 2.0}]
set r [expr {($x2 - $x1) / 2.0}]
$c create circle $xc $yc -r $r -fill white -stroke white
puts "width: $width, xc/yc: $xc/$yc, r: $r"
} $c create rectangle $x1 $y1 $x2 $y2 -outline red
---
On a canvas 200 px wide and high it draws a circle at 100/100 and
still it isn't centered. What did I do wrong?
Any enlightenment will be highly appreciated.
Helmut

Subject: Re: How to center a circle?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Wed, 16 Oct 2024 13:29 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 15:29:17 +0200
Lines: 18
Message-ID: <ygah69cxjki.fsf@akutech.de>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net yNMoNPQsoAUVT6aYeMlAigvGLoTwTVlORPngSip8Z7BWgC97w=
Cancel-Lock: sha1:fsRBO+nRg3hGpjhvhRehhHa/7Kg= sha1:ErEU9/G/6f+qAVdDIVdkQ1fjDiM= sha256:sBVrC8xlX5ZCHXItkMZVm3L0GxPnvoH1nv+M2gdFak8=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Helmut Giese <hgiese@ratiosoft.com>
--<snip-snip>--
| On a canvas 200 px wide and high it draws a circle at 100/100 and
| still it isn't centered. What did I do wrong?
| Any enlightenment will be highly appreciated.

Looks pretty centered to me.. although adding +1 to the x1 and x2 coords
makes it even 'more' centered :-) (TK version, since I don't have tkpath at
hand).

set x1 [expr {$width * 0.04 +1}]
...
set x2 [expr {$width - $width * 0.04 +1}]

Could be related to the origin of the coordinate system, and how items
are plotted given their coords...

R'

Subject: Re: How to center a circle?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Wed, 16 Oct 2024 15:00 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 17:00:20 +0200
Organization: ratiosoft
Lines: 11
Message-ID: <7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com> <ygah69cxjki.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 16 Oct 2024 17:00:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e9762f795d257d7644cc8b1c5eedd85";
logging-data="2422186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1951jNYmMt8c+TczJrW+cR8"
Cancel-Lock: sha1:G5fUCka0p5+Tjy0S+1HZ1C9U1Rg=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello Ralf,
>Looks pretty centered to me.. although adding +1 to the x1 and x2 coords
>makes it even 'more' centered :-) (TK version, since I don't have tkpath at
>hand).
looking at my monitor this sounds incredible - it is so obvious. Ok, I
made a mistake: I didn't tell platform and version: I am on Windows
10 and run Tcl 8.6.10.
If I knew a site where I could upload a screen shot everybody would
see what I am talking about.
Thanks
Helmut

Subject: Re: How to center a circle?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Wed, 16 Oct 2024 16:36 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 18:36:36 +0200
Lines: 18
Message-ID: <ygacyk0xawb.fsf@akutech.de>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
<ygah69cxjki.fsf@akutech.de>
<7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net 1r6T26T/WzXlb9EHRqe5IwQe28neDBMm9GGcrCeuUwBKUJxss=
Cancel-Lock: sha1:JzhTF/+wojrCODzBHff569xDjo4= sha1:u1Ou8/vhhlQsISm0KiNjO+fEVGY= sha256:i0ttJsiqtQhZN9r7gXzuY702/WUeZ7efvYeM2Sf/NWs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Helmut Giese <hgiese@ratiosoft.com>
| >Looks pretty centered to me.. although adding +1 to the x1 and x2 coords
| >makes it even 'more' centered :-) (TK version, since I don't have tkpath at
| >hand).
| looking at my monitor this sounds incredible - it is so obvious. Ok, I
| made a mistake: I didn't tell platform and version: I am on Windows
| 10 and run Tcl 8.6.10.

Same results here on Linux and Windows 10 with tk 8.6.15...

| If I knew a site where I could upload a screen shot everybody would
| see what I am talking about.

Select any of
https://www.google.com/search?q=public+upload+site
?

R'

Subject: Re: How to center a circle?
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 16 Oct 2024 17:08 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 17:08:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <veoru9$2b47r$1@dont-email.me>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com> <ygah69cxjki.fsf@akutech.de> <7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com>
Injection-Date: Wed, 16 Oct 2024 19:08:25 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c1dbc23c706900653bfd33e2cb7e8f90";
logging-data="2461947"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3kUDtKCwcFHH/eabC4/19"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:OXYZ8WHGOEeDtzv8AG/zPmKqO24=
View all headers

Helmut Giese <hgiese@ratiosoft.com> wrote:
> If I knew a site where I could upload a screen shot everybody would
> see what I am talking about.

Try:

https://0x0.st

Subject: Re: How to center a circle?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Wed, 16 Oct 2024 17:57 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 19:57:59 +0200
Organization: ratiosoft
Lines: 18
Message-ID: <j0vvgjlhtlkq8rv4c97v3ngjhgnhf1bmu5@4ax.com>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com> <ygah69cxjki.fsf@akutech.de> <7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com> <ygacyk0xawb.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 16 Oct 2024 19:57:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e9762f795d257d7644cc8b1c5eedd85";
logging-data="2476689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19toQmqv23ngCHdHHBCMhYv"
Cancel-Lock: sha1:ZLwhCOQvSSapUyZO9xsRsS2REto=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello Ralf,
>Select any of
> https://www.google.com/search?q=public+upload+site
>?
this was very helpful. The screen shots are now on https://imgbb.com/
with the URLs:
TkPath: https://ibb.co/gg6XsRm
Tk: https://ibb.co/LkGg9mv
Apart from the rugged edge in Tk they look pretty identical to me.
And to me the left and top edges are significant smaller than their
right and bottom counter parts - about less than half I would say.

Am I crazy? Does my monitor play tricks with me? I know that I don't
have perfect eye sight - that's why I am wearing glasses since the age
of ten and so far it has helped me lead a normal life.

A very confused
Helmut

Subject: Re: How to center a circle?
From: et99
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 01:58 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Wed, 16 Oct 2024 18:58:18 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <vepqvq$2jh2h$1@dont-email.me>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
<ygah69cxjki.fsf@akutech.de> <7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com>
<ygacyk0xawb.fsf@akutech.de> <j0vvgjlhtlkq8rv4c97v3ngjhgnhf1bmu5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 03:58:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3ba84d17824dbb2ece4833e295dbb4cc";
logging-data="2737233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e5dRFJe4sOKzjjBJaIO+5"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xhaDwkrkkRUs70v0IatID8nWId0=
Content-Language: en-US
In-Reply-To: <j0vvgjlhtlkq8rv4c97v3ngjhgnhf1bmu5@4ax.com>
View all headers

On 10/16/2024 10:57 AM, Helmut Giese wrote:

> Am I crazy? Does my monitor play tricks with me? I know that I don't
> have perfect eye sight - that's why I am wearing glasses since the age
> of ten and so far it has helped me lead a normal life.
>
> A very confused
> Helmut

I'm on windows 10 and they look completely symmetrical to me. A circle enclosed in a box. I see the same from an android phone.

Do you perchance have more than a few diopters of cylinder (astigmatism) in your glasses? That's the only thing other than it being your computer/monitor that comes to mind :)

Subject: Re: How to center a circle?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Thu, 17 Oct 2024 08:55 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Thu, 17 Oct 2024 10:55:00 +0200
Lines: 23
Message-ID: <yga8qunxg63.fsf@akutech.de>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
<ygah69cxjki.fsf@akutech.de>
<7pkvgjpcqqtejh0cbl85ahbj7eej1tip8f@4ax.com>
<ygacyk0xawb.fsf@akutech.de>
<j0vvgjlhtlkq8rv4c97v3ngjhgnhf1bmu5@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Q7mEGBJzE9pidEMr19o1MwnrGvgXKUVK3S8gC6kYf2onqVbis=
Cancel-Lock: sha1:kAlNJHA3ecyggPMy5+L4WU6Auzg= sha1:A23jQGMZF/Xlcv1g40FvYCebOho= sha256:BZpfotkVjMDYoyUDVaEd0jv59QBNZRRKeWh9ho9Gn68=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Helmut Giese <hgiese@ratiosoft.com>
| The screen shots are now on https://imgbb.com/
| with the URLs:
| TkPath: https://ibb.co/gg6XsRm
| Tk: https://ibb.co/LkGg9mv
| Apart from the rugged edge in Tk they look pretty identical to me.
| And to me the left and top edges are significant smaller than their
| right and bottom counter parts - about less than half I would say.

Ok, this is the same what I see. I was not sure whether this small
difference already counts as 'big' :-p

As I said, they get 'more centered' if you adjust the coordinates by +1:

set x1 [expr {$width * 0.04 +1}]
...
set x2 [expr {$width - $width * 0.04 +1}]

I can only guess as what might be the reason, but my €0.01 would go to a
combination of coordinate origin, rounding effects, DPI of the display,
phase of the moon, and of course currently the comet.

R', just kidding for the last two... ;-)

Subject: Re: How to center a circle?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Thu, 17 Oct 2024 17:45 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Thu, 17 Oct 2024 19:45:11 +0200
Organization: ratiosoft
Lines: 12
Message-ID: <uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 19:45:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="faa9f74a6be70c01c7219565ab6ed537";
logging-data="3001894"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193o+hQGLjYtnK7bYTTHVdy"
Cancel-Lock: sha1:9L0tQx1otG5gJhBiKaMPp0L9ftU=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

I want to thank all of you for responding.
Well, what's the conclusion? If you all say that the circle is
centered who am I to disagree.
It is somewhat troublesome that apparently I cannot trust my own eyes
but, as I said, who am I to disagree.
@et99: Yes, I have always had rather strong glasses but so far I had
never have any reason to mistrust my perception. Ok, it sems that
there always is a first time.
Maybe I should attribute it to age - not a very pleasant thought
either. Well ...
Many thanks again
Helmut

Subject: Re: How to center a circle?
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 17 Oct 2024 18:43 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Thu, 17 Oct 2024 14:43:01 -0400
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <verlrm$2s2jq$1@dont-email.me>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
<uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Oct 2024 20:43:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b21dfa98481f26b7bdf10ed197dfcd6c";
logging-data="3017338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ylewa3PWY08ZRcN8KLUrt"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0DH69WiZbtn6EODz0cN6coCMunk=
Content-Language: en-US
In-Reply-To: <uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com>
View all headers

On 10/17/2024 1:45 PM, Helmut Giese wrote:
> I want to thank all of you for responding.
> Well, what's the conclusion? If you all say that the circle is
> centered who am I to disagree.
> It is somewhat troublesome that apparently I cannot trust my own eyes
> but, as I said, who am I to disagree.

They are identical for me as well, and the Tk verson has rugged edges,
which you noted. I suspect the difference is somewhere between your
monitor and the scaling factor Windows uses.

If you want to see the circle "inside" the rectangle with no edges
touching, I would recommend a slight change: increment the starting
position by 1, but also reduce the size of the circle by 1.

Subject: Re: How to center a circle?
From: Shaun Deacon
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 18 Oct 2024 16:28 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sdeacon@us.socionext.com (Shaun Deacon)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Fri, 18 Oct 2024 09:28:00 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <veu2ai$3cmij$1@dont-email.me>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com>
<uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Oct 2024 18:28:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="750e32748211854dd0d65d99ecea0007";
logging-data="3562067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194lPGkG1DWrzCu+C5mn9Rr"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:QPfu9VRR8LU92Q9dNUPVq9aIN0g=
In-Reply-To: <uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com>
View all headers

Helmut Giese wrote:
> I want to thank all of you for responding.
> Well, what's the conclusion? If you all say that the circle is
> centered who am I to disagree.
> It is somewhat troublesome that apparently I cannot trust my own eyes
> but, as I said, who am I to disagree.
> @et99: Yes, I have always had rather strong glasses but so far I had
> never have any reason to mistrust my perception. Ok, it sems that
> there always is a first time.
> Maybe I should attribute it to age - not a very pleasant thought
> either. Well ...
> Many thanks again
> Helmut
>

Looking at your images, the rectangle and circle are closer to the
top-left corner of the canvas than the bottom-right - is this what you
mean ?

Shaun

Subject: Re: How to center a circle?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Fri, 18 Oct 2024 18:53 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: How to center a circle?
Date: Fri, 18 Oct 2024 20:53:14 +0200
Organization: ratiosoft
Lines: 45
Message-ID: <f5b5hj1v8tpu62vrkkgq86c7hpiat13lfv@4ax.com>
References: <8vdvgjdo7cn84v1nl035oe222d2m82q99k@4ax.com> <uii2hj160au7d9ccbrsdeg9ct15ng9apdb@4ax.com> <veu2ai$3cmij$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Oct 2024 20:53:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="85d0ea73b028f4b07c9ed96ae71789a2";
logging-data="3614840"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183aRtwlJ9RzMkz8dT5itwq"
Cancel-Lock: sha1:hRD7ciwOUXmRX7yhXOhlYkA+ZXM=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

>Looking at your images, the rectangle and circle are closer to the
>top-left corner of the canvas than the bottom-right - is this what you
>mean ?
Yes, exactly. However, meanwhile I got convinced that it was only an
optical illusion (with the help of Tk itself): I enhanced my OP and it
showed that there is no difference.
---
package require Tk
package require tkpath

foreach ch [winfo children "."] {destroy $ch}

set useTK 0
if {$argc} {
set useTK 1
} if {$useTK} {
set c [canvas .c -background gray50 -width 200 -height 200]
} else {
set c [tkp::canvas .c -background gray50 -width 200 -height 200]
} pack $c -padx 10 -pady 10

set width [$c cget -width]
set height [$c cget -height]

set x1 [expr {$width * 0.04}]
set y1 $x1
set x2 [expr {$width - $width * 0.04}]
set y2 $x2
if {$useTK} {
$c create oval $x1 $y1 $x2 $y2 -fill white -outline white
} else {
set xc [expr {$x1 + ($x2 - $x1) / 2.0}]
set yc [expr {$y1 + ($y2 - $y1) / 2.0}]
set r [expr {($x2 - $x1) / 2.0}]
$c create circle $xc $yc -r $r -fill white -stroke white
} $c create rectangle $x1 $y1 $x2 $y2 -outline red
puts "horizontal diff: [expr {$x1}] vs [expr {$width - $x2}]"
puts "vertical diff: [expr {$y1}] vs [expr {$height - $x2}]"
---
So, no matter what the monitor shows (or what we believe it shows) the
output says that all margins are 8 px.
Helmut

1

rocksolid light 0.9.8
clearnet tor