I've been writing something to help me check my ellipse related
calculations.  I think the code should be fairly straightforward,
but if I leave it as it is, it just crashes.  If I delete the
line "class Shoes" and the corresponding "end" (i.e move ellipse_equation
into Object (the default namespace) then I get a window with no
controls. Have I missed something obvious?

Thank you,
Hugh



class Shoes
  def ellipse_equation(x,y,a,b)
    raise "a is zero " if a.zero?
    raise "b is zero " if b.zero?
    result = (((x * x) / (a * a)) +
              ((y * y) / (b * b)));
    return result;
  end
end


Shoes.app do
  @x = 0
  @y = 0
  @a = 1
  @b = 1
  stack do
    flow do
      @xentry = edit_line.text.to_i
      @xbtn = button("x") do
        @x = @xentry.text.to_i
        @result.replace(ellipse_equation(@x,@y,@a,@b).to_s)
      end
    end
    flow do
      @yentry = edit_line.text.to_i
      @ybtn = button("x") do
        @y = @yentry.text.to_i
        @result.replace(ellipse_equation(@x,@y,@a,@b).to_s)
      end
    end

    flow do
      @aentry = edit_line.text.to_i
      @abtn = button("x") do
        @a = @aentry.text.to_i
        @result.replace(ellipse_equation(@x,@y,@a,@b).to_s)
      end
    end
    flow do
      @bentry = edit_line.text.to_i
      @bbtn = button("x") do
        @b = @bentry.text.to_i
        @result.replace(ellipse_equation(@x,@y,@a,@b).to_s)
      end
    end
    @result = para(ellipse_equation(@x,@y,@a,@b).to_s)
  end
end

Reply via email to