Awesome! Works great - at least, the vector class seems to be working
properly. Still need to do some work polishing things up, but I can keep
moving now. Thanks for the help.

Chris

On Sat, Jan 3, 2009 at 8:26 PM, Garret Buell <[email protected]> wrote:

> Try moving everything but the "Shoes.app do" block to its own file and
> then including it. I had what may be a related problem playing with
> ActiveRecord. It seems Shoes gets confused interpreting classes in the
> main file besides Shoes inherited ones but if its in a separate
> included file it works fine. Worth a try.
>
> -Garret Buell
>
>
> On Sat, Jan 3, 2009 at 8:09 PM, Christopher Small
> <[email protected]> wrote:
> > Ok, I played with this a bit more. When I try running this simple program
> >
> > require "matrix"
> >
> > Shoes.app do
> >   Vector[1,2]
> > end
> >
> > I don't get any complaints from the console. However, when I run my
> actual
> > program which is for drawing fractals, I get the errors I described. Here
> is
> > the code.
> >
> >
> > require "matrix"
> >
> > class Vector
> >   def angle_from(v = Vector[1,0])
> >     ans = Math.atan2(self[1],self[0])
> >     ans -= v.angle unless v == Vector[1,0]
> >     return ans
> >   end
> >   def rotate(theta)
> >     Matrix.rot_mat(theta) * self
> >   end
> > end
> >
> > class Matrix
> >   def self.rot_mat(theta)
> >
> >
> self[[Math.cos(theta),Math.sin(theta)],[-Math.sin(theta),Math.cos(theta)]]
> >   end
> > end
> >
> > module Fractalizer
> >   def self.fractalize(points,its)
> >     vi, vf = points.first, points.last
> >     theta_l = Math.atan2(yf-yi,xf-xi)
> >     ll = (vf-vi).r
> >     segments = (1..points.length).map { |n| [points[n-1],points[n]] }
> >     answer = []
> >     segments.each do |seg|
> >       theta_s = seg[1].angle_from seg[0]
> >       ls = (seg[1]-seg[0]).r
> >       newpoints = points.map do |pt|
> >         npt = (pt - points.first)*(ls/ll)
> >         npt = npt.rotate(theta_s - thetal)
> >         npt += points.first
> >       end
> >       newpoints.delete_at -1
> >       answer += newpoints
> >     end
> >     answer << points.last
> >   end
> > end
> >
> > Shoes.app do
> >   button "Fractalize!" do
> >     @points = Fractalizer.fractalize(@points, @e.text.to_f)
> >   end
> >   para "Number of Iterations"
> >   @e = edit_line :width => 30
> >   @f = flow
> >   @points = []
> >   animate do
> >     if self.mouse[0]==1
> >       pos = Vector[mouse[1], mouse[2]]
> >       @points << pos
> >       if @points.size > 1
> >         @f.append {line(@points[-2][0],@points[-2][1],*(@points[-1]))}
> >       end
> >     end
> >   end
> > end
> >
> >
> >
> > Is there something I'm doing wrong here that is making the code not work?
> > Can anyone else run this code and see if they get errors? The basic idea
> is
> > that this program is intended to let you draw a connected set of line
> > segments by clicking on the shoes window. Once you click the fractalize
> > button, it runs takes each segment and replaces it with the whole shape.
> So,
> > if things run properly on your machine, when you click at two different
> > points in the shoes window, you should get a line segment drawn. If not,
> it
> > should be because one of the errors that I described earlier. Thanks for
> the
> > help.
> >
> > Chris
> >
> > On Sun, Dec 28, 2008 at 10:39 PM, <[email protected]> wrote:
> >>
> >> I did require "matrix" but had no luck with that.
> >>
> >> Chris
> >> Sent from my BlackBerry Smartphone provided by Alltel
> >>
> >> -----Original Message-----
> >> From: Ernest Prabhakar <[email protected]>
> >>
> >> Date: Mon, 29 Dec 2008 12:06:38
> >> To: <[email protected]>
> >> Subject: Re: Vector class
> >>
> >>
> >> Hi Christopher,
> >>
> >> > There seems to be a bug with the Vector class in the shoes version
> >> > of ruby. I'm making vectors of coordinates using this line:
> >>
> >> That sounds like the same problem I had with tankspank.  Did you:
> >>
> >> require 'matrix'
> >>
> >> ?
> >>
> >> I don't think I needed to do that in pure Ruby, but I did in Shoes.
> >>
> >> -- Ernie P.
> >> On Dec 29, 2008, at 3:23 AM, Christopher Small wrote:
> >>
> >> > There seems to be a bug with the Vector class in the shoes version
> >> > of ruby. I'm making vectors of coordinates using this line:
> >> >
> >> > pos = Vector[mouse[1], mouse[2]]
> >> >
> >> > Before I was doing this with arrays, but realized that using vectors
> >> > would help me out in the long run. Once I switched to vectors, I got
> >> > this error in the shoes console:
> >> >
> >> > undefined method '[]' for #<Class:0x1249a54>::Vector
> >> >
> >> > Has anyone come across this? It seems like this should work just
> >> > fine. I'm using the latest .dmg release of Raisins on Leopard.
> >> >
> >> > Thanks
> >> >
> >> > Chris
> >>
> >
> >
>

Reply via email to