Re: How to center a circle?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: How to center a circle?
De : hgiese (at) *nospam* ratiosoft.com (Helmut Giese)
Groupes : comp.lang.tcl
Date : 18. Oct 2024, 19:53:14
Autres entêtes
Organisation : ratiosoft
Message-ID : <f5b5hj1v8tpu62vrkkgq86c7hpiat13lfv@4ax.com>
References : 1 2 3
User-Agent : Forte Free Agent 1.93/32.576 English (American)
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

Date Sujet#  Auteur
16 Oct 24 * How to center a circle?12Helmut Giese
16 Oct 24 +* Re: How to center a circle?7Ralf Fassel
16 Oct 24 i`* Re: How to center a circle?6Helmut Giese
16 Oct 24 i +* Re: How to center a circle?4Ralf Fassel
16 Oct 24 i i`* Re: How to center a circle?3Helmut Giese
17 Oct 24 i i +- Re: How to center a circle?1et99
17 Oct 24 i i `- Re: How to center a circle?1Ralf Fassel
16 Oct 24 i `- Re: How to center a circle?1Rich
17 Oct 24 `* Re: How to center a circle?4Helmut Giese
17 Oct 24  +- Re: How to center a circle?1saito
18 Oct 24  `* Re: How to center a circle?2Shaun Deacon
18 Oct 24   `- Re: How to center a circle?1Helmut Giese

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal