From: Hidetoshi NAGAI Date: 2006-01-16T02:02:20+09:00 Subject: Re: "Programming Ruby", ed. 2, P747. Script generated different image to book's example From: "David Vallner" Subject: Re: "Programming Ruby", ed. 2, P747. Script generated different image to book's example Date: Mon, 16 Jan 2006 01:32:31 +0900 Message-ID: > >> #errors generated > >> jayeola@tp20$ /usr/lib/ruby/1.8/tk.rb:2313: warning: redefine encoding= > >> /usr/lib/ruby/1.8/tk.rb:2316: warning: redefine encoding Please ignore this warning. That has no problem. > >> TkcLine.new(canvas, > >> points[0],[0], points[0],[1], > >> points[1],[0], points[1],[1], > >> points[2],[0], points[2],[1], > >> 'smooth' => 'on', > >> 'width' => 7, > >> 'fill' => col, > >> 'capstyle' => 'round') > Diff results after tweaking all the whitespace differences between the two > files (the first is the PDF version, the second the code you posted): > > 2a3 > > > 23,25c24,26 > < points[0][0], points[0][1], > < points[1][0], points[1][1], > < points[2][0], points[2][1], > --- > > points[0],[0], points[0],[1], > > points[1],[0], points[1],[1], > > points[2],[0], points[2],[1], On current Ruby/Tk, a canvas Item can accept an array or arrays as its coords. That is, all of the followings are valid. ---------------------------------------------------------------- (0) TkcLine.new(canvas, points[0][0], points[0][1], points[1][0], points[1][1], points[2][0], points[2][1], :smooth=>'on', :width =>7, :fill=>col, :capstyle=>'round') (1) TkcLine.new(canvas, points[0], points[1], points[2], :smooth=>'on', :width =>7, :fill=>col, :capstyle=>'round') (2) TkcLine.new(canvas, points.flatten, :smooth=>'on', :width =>7, :fill=>col, :capstyle=>'round') (3) TkcLine.new(canvas, points, :smooth=>'on', :width =>7, :fill=>col, :capstyle=>'round') ---------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)