Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rotate a rectangle widget in tcl tk

275 views
Skip to first unread message

Milind Priyadarshi

unread,
Feb 8, 2016, 11:32:26 PM2/8/16
to
Hi,

I am creating a rectangle using canvas widget using tcl tk. Now i want to rotate this rectangle at various angle. Pls suggest for the same.

tessa...@gmail.com

unread,
Feb 9, 2016, 2:50:05 AM2/9/16
to
On Monday, February 8, 2016 at 8:32:26 PM UTC-8, Milind Priyadarshi wrote:
> Hi,
>
> I am creating a rectangle using canvas widget using tcl tk. Now i want to rotate this rectangle at various angle. Pls suggest for the same.

Convert to a 4 coordinate polygon then use the code in Canvas Rotation in the wiki (http://wiki.tcl.tk/8595).

Keith

Rich

unread,
Feb 9, 2016, 6:48:16 AM2/9/16
to
From the canvas manpage:

Individual items may be moved or scaled using widget commands
described below, but they may not be rotated.

So, your only choice will be to erase the original rectangle, perform
the required math to 'rotate' the coordinates of the original
rectangle, and draw a polygon with the new coordinates.

Uwe Klein

unread,
Feb 9, 2016, 11:50:05 AM2/9/16
to
you replace the coords data

$canvas coords $item <list of coords ... )

where you previously have retrieved the set with

set coords [ $canvas coords $item ]

you can translate/scale/rotate the coords list to your liking.

set coords [ transform $translate $scale $rotate $coords ]



over time rounding errors on occasion can give some problems.

If you want to continuously rotate in small increments
it might be a good idea to have one set of "mother coords" and
rotate those over the accumulated angle every time.

uwe

Milind Priyadarshi

unread,
Feb 11, 2016, 11:59:06 PM2/11/16
to
Thanks very much..
But since i am new to programming, can to give me a example which creates a rectangle and allows rotation at 90 degrees..

It would be very helpful in my project if you help me in rotation of rectangles

Thanks very much sir...

Rich

unread,
Feb 12, 2016, 7:25:15 AM2/12/16
to
For 90 degree rotation, get a sheet of paper and do some 'plotting'
with a pencil and ruler. Think about how you would change the
coordinates to draw the same rectangle with 90 degree rotation.

The method you would use with pencil and paper to 'rotate' by 90
degrees is identical to the method you will program to rotate a
rectangle by 90 degrees.


Note - the group tends to take a dim view on answering
homework/exercise questions, and this is one of those questions that
smells of a homework/exercise question.

Message has been deleted

Milind Priyadarshi

unread,
Feb 19, 2016, 5:42:48 AM2/19/16
to
Hello sir,

Thank you very much for your suggestion. Actually i am working on a project where i am supposed to do these things.

Now kindly give me some hints on how select a group of rectangles simultaneously...i want to move them on the canvas.. i had already coded for movement of rectangles.. now i want to move all of them at once...

Rich

unread,
Feb 19, 2016, 8:08:56 AM2/19/16
to
Give each canvas object that you want to "move at once" the identical
tag value (read the canvas manual page about 'tags') that is unique
from all other tag values. Then you can apply an operation upon all of
them at once from the canvas (assuming by "move" you mean shift the x/y
coordinates equally, if you mean rotate, then you'll need to loop
through each one in Tcl performing the rotation and updating its
coordinates appropriately). Note you can still use a common, unique,
tag even for this, because you can ask the canvas for a list of all
item id values associated with the tag, then loop through those values.
0 new messages