Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > tcl/tk translate

Reply
Thread Tools

tcl/tk translate

 
 
Ed Redman
Guest
Posts: n/a
 
      09-14-2005
I am still fairly new to ruby/tk
I am trying to translate some simple programs from tcl/tk to ruby/tk.
The following stumps me however. Could someone help me translate.
Specifically, the foreach {x y} [$w coords $item]. The $w refers to
TkcPolygons.

proc poly'rotate {w item angle} {
set delta [expr {$angle/180.*acos(-1)}]
foreach {x y} [$w coords $item] {
set r [expr {hypot($y,$x)}]
set a [expr {atan2($y,$x)+$delta}]
lappend coords [expr {cos($a)*$r}] [expr {sin($a)*$r}]

thank you
 
Reply With Quote
 
 
 
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      09-14-2005
From: Ed Redman <(E-Mail Removed)>
Subject: tcl/tk translate
Date: Wed, 14 Sep 2005 10:56:33 +0900
Message-ID: <(E-Mail Removed)>
> proc poly'rotate {w item angle} {
> set delta [expr {$angle/180.*acos(-1)}]
> foreach {x y} [$w coords $item] {
> set r [expr {hypot($y,$x)}]
> set a [expr {atan2($y,$x)+$delta}]
> lappend coords [expr {cos($a)*$r}] [expr {sin($a)*$r}]


For example,
---------------------------------------------------------------
require 'tk'
require 'enumerator'

def poly_rotate(citem, angle)
delta = (angle * Math:I)/180.0
citem.coords = citem.coords.enum_slice(2).collect{|x, y|
r = Math::hypot(y, x)
a = Math::atan2(y, x) + delta
[Math::cos(a) * r, Math::sin(a) * r]
}
end

coords = [[100, 30], [200, 30], [100, 80]]

c = TkCanvas.new(:height=>480, :width=>480,
:scrollregion=>[-240, -240, 240, 240]).pack
poly = TkcPolygon.new(c, coords, :fill=>'red')
p poly.coords

TkcOval.new(c, [[-2, -2], [2, 2]], :fill=>'black')

TkTimer.start(20, -1, proc{poly_rotate(poly, 5)})

Tk.mainloop
---------------------------------------------------------------
--
Hidetoshi NAGAI ((E-Mail Removed))


 
Reply With Quote
 
 
 
 
gregarican
Guest
Posts: n/a
 
      09-14-2005
Hidetoshi NAGAI wrote:

> TkTimer.start(20, -1, proc{poly_rotate(poly, 5)})



When I pasted your sample code into a text file and ran it on my
One-Click Windows install of Ruby 1.8.2 I received the following error
message:

undefined method `start' for TkTimer:Class (NoMethodError)

Then when I tried creating a new instance of a TkTimer class object and
use the start method like this:

timer=TkTimer.new
timer.start(20, -1, proc{poly_rotate(poly, 5)})

I received an error stating Argument '-1' need to be Proc
(ArgumentError).

Just curious if this might be due to the version of Tk that's bundled
with my Ruby distro...

 
Reply With Quote
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      09-15-2005
From: "gregarican" <(E-Mail Removed)>
Subject: Re: tcl/tk translate
Date: Wed, 14 Sep 2005 23:21:34 +0900
Message-ID: <(E-Mail Removed) om>
> > TkTimer.start(20, -1, proc{poly_rotate(poly, 5)})

> When I pasted your sample code into a text file and ran it on my
> One-Click Windows install of Ruby 1.8.2 I received the following error
> message:
> undefined method `start' for TkTimer:Class (NoMethodError)


Hmmm... I commited TkTimer.start at 2004/10/15.
Ruby 1.8.2 must have the method.

TkTimer.start is TkTimer.new + TkTimer#start.
So, instead of TkTimer.start, you can write:

TkTimer.new(20, -1, proc{poly_rotate(poly, 5)}).start

--
Hidetoshi NAGAI ((E-Mail Removed))


 
Reply With Quote
 
gregarican
Guest
Posts: n/a
 
      09-15-2005
Hidetoshi NAGAI wrote:

> Hmmm... I commited TkTimer.start at 2004/10/15.
> Ruby 1.8.2 must have the method.


The start method is present, but I think what's being passed along is
wrong. Note the error message I receive when creating a new TkTimer
object and then using the start method:

timer=TkTimer.new
timer.start(20, -1, proc{poly_rotate(poly, 5)})


ArgumentError: Argument '-1' need to be Proc
(ArgumentError).
from c:/ruby/lib/ruby/1.8/tk/timer.rb:338:in 'start'

 
Reply With Quote
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      09-16-2005
From: "gregarican" <(E-Mail Removed)>
Subject: Re: tcl/tk translate
Date: Fri, 16 Sep 2005 02:51:34 +0900
Message-ID: <(E-Mail Removed). com>
> The start method is present, but I think what's being passed along is
> wrong. Note the error message I receive when creating a new TkTimer
> object and then using the start method:
>
> timer=TkTimer.new
> timer.start(20, -1, proc{poly_rotate(poly, 5)})


You'll misunderstand about arguments of those methods.
Please read my last mail again.

From: Hidetoshi NAGAI <(E-Mail Removed)>
Subject: Re: tcl/tk translate
Date: Thu, 15 Sep 2005 11:31:32 +0900
Message-ID: <(E-Mail Removed) >
> TkTimer.start is TkTimer.new + TkTimer#start.
> So, instead of TkTimer.start, you can write:
>
> TkTimer.new(20, -1, proc{poly_rotate(poly, 5)}).start


That is,
-----------------------------------------------------------------
timer = TkTimer.new(20, -1, proc{poly_rotate(poly, 5)})
timer.start
-----------------------------------------------------------------
--
Hidetoshi NAGAI ((E-Mail Removed))


 
Reply With Quote
 
gregarican
Guest
Posts: n/a
 
      09-16-2005
Hidetoshi NAGAI wrote:

> You'll misunderstand about arguments of those methods.
> Please read my last mail again.


Sorry. I forgot to require enumerable. That's why it bombed. Doooh!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Post Translate Timing yaseenzaidi@NETZERO.com VHDL 3 06-22-2005 06:12 AM
post translate simulation Nisheeth VHDL 2 04-29-2005 05:36 PM
translate this send into perl sfgroups@gmail.com Perl 1 03-16-2005 09:54 PM
Xilinx translate error : Cannot find signal "clk" Rakesh Sharma VHDL 2 10-22-2004 08:03 PM
Modelsim post place and route/Post Translate issues Sridhar Hegde VHDL 2 09-13-2004 02:43 PM



Advertisments