I was having kinda the same issue earlier, which is why I had to make a new 
window for the button and para. 

Now, I just looked over how the taiji shape works, and tried to optimize it a 
teeny bit. Got rid of a shape or two, can't recall. Then went on to add the 
animation, and clearing just the stack, and it just seems to work, somehow. 

Well, don't let this put you off from using shoes. I think the issue here 
really was that Shoes is still quite slow. But Shoes 3 is supposed to get much 
faster, what with ruby 1.9 support, and the focus on making it faster on 
general (as _why has mentioned).

Anyways, this works, here ya go:

$speed = 7

Shoes.app do

  #=========================================================
  # This is a bagua, not made into a method as it only needs to be done once.
  # No image block either, as that is more useful if the image is reused many 
times, not the case here
  @w=70; @h=10; @d=10

  stroke black

  fill black

  #qian

  rect (255,20,@w,@h)

  rect (255,2...@h+@d,@w,@h)

  rect (255,2...@h*2+@d*2,@w,@h)

  

  #li

  rect (110,215,@h,@w)

  rect (1...@h-@d,215,@h,@w/2-5)

    rect (1...@h-@d,2...@w/2+5,@h,@w/2-5)

  rect (1...@h*2-@d*2,215,@h,@w)

  

  #kan

  rect (460,215,@h,@w/2-5)

    rect (460,2...@w/2+5,@h,@w/2-5)

  rect (4...@h+@d,215,@h,@w)

  rect (4...@h*2+@d*2,215,@h,@w/2-5)

    rect (4...@h*2+@d*2,2...@w/2+5,@h,@w/2-5)

 
  #kun

  rect (255,410,@w/2-5,@h)

    rect (2...@w/2+5,410,@w/2-5,@h)

  rect (255,4...@h+@d,@w/2-5,@h)

    rect (2...@w/2+5,4...@h+@d,@w/2-5,@h)

  rect (255,4...@h*2+@d*2,@w/2-5,@h)

    rect (2...@w/2+5,4...@h*2+@d*2,@w/2-5,@h)

    

  strokewidth(10) 

  #dui

  line(130,155,179,106)

  line(115,140,164,91)

  #line(100,125,149,76)

  line(100,125,121,104)

  line(128,97,149,76)

  

  #zhen

  line(130,325,179,374)

  #line(115,340,164,389)

    line(115,340,136,361)

    line(143,368,164,389)

  #line(100,355,149,404)

  line(100,355,121,376)

  line(128,383,149,404)

  

  #xun

  #line(450,155,401,106)

  line(450,155,429,134)

  line(422,127,401,106)

  line(465,140,416,91)

  line(480,125,431,76)

    

  #gen

  #line(450,325,401,374)

  line(450,325,429,346)

  line(422,353,401,374)

  #line(465,340,416,389)

    line(465,340,444,361)

    line(437,368,416,389)

 
  line(480,355,431,404)

  

  strokewidth(1)  #restore
  # End of Bagua

  #=========================================================
  
  def taiji(left = 0, top = 0)

    image 282, 282, :top => top, :left => left do 

      stroke black; fill white   

      oval 1, 1, :radius =>140  

      fill black; nostroke

      shape do 

        move_to  1, 141 

        arc_to 141, 141, 280, 280, 0, PI
        move_to 211, 141
        arc_to 211, 141, 140, 140, PI, 2*PI

      end     

      fill white

      oval 71, 141, :radius => 70, :center => true
      oval 211, 141, :radius => 20, :center => true

      fill black
      oval 71, 141, :radius => 20, :center => true

    end

  end
  

  para "Rotate Angle:"

  @ang = para "0"; @spin = 0

  button( "Reverse" ) { $speed *= -1 }
  
  @taiji_area = stack(:top => 100, :left => 150)
  animate(20) do
    @spin += $speed; @ang.replace @spin
    @taiji_area.clear { rotate $speed; taiji}
  end
  
end

Subject: Re: I want to draw a taiji animation by shoes
From: [email protected]
To: [email protected]
Date: Sun, 9 Aug 2009 03:39:14 +0800

I make a new version which append 8 gua map.
It seems if use clear method in shoes animation speed will not drop as times 
go.If only clear part of image,speed will drop.
A new problem,rotate method operate on whole area of shoes.Is it possible that 
rotate only operate on a certain part of area?I want 8 gua map keep 
static,taiji map rotate.


taiji8gua.rb  taiji & 8gua both rotate (funny,but not what I want)
taiji8gua-ok.rb  perform right but speed will drop

At first,I thought producing taiji8gua in shoes is a easy job.It is not as I 
assumed.


On Sat, Aug 8, 2009 at 6:32 AM, Ehsanul Hoque <[email protected]> wrote:






Yeah, when you set the rotate method, that rotation sticks around, forgot to 
mention. That's why my first example sped up linearly, I forgot to take that 
into account.

I don't think putting a call to animate() inside a method is going to work 
properly. It would be better if you had a method that changed the speed value 
that is called inside the animate block. Here's an example of how it might work:


$speed = 8
Shoes.app :resizable => false do
    transform(:center)
    def taiji
      image 280, 280, :top => 100, :left => 150 do
        # drawing order is important!!!
        stroke black

        nofill     
        oval 0, 0, :radius =>140 
        #angle1 -> angle2 is clockwise, lead to fill surplus semi-circle
        fill black
        shape do
          move_to  70, 50
          arc_to 140,70,140,140,TWO_PI-PI/2,PI/2

          arc_to 140,210,140,140,PI/2,TWO_PI-PI/2
          arc_to 140,140,280,280,PI/2,TWO_PI-PI/2
        end    
        stroke white
        fill white
        oval 70,140,:radius=>70 # erase the surplus black semi-circle

        oval 120, 50, :radius =>20  
        fill black
        oval 120, 190, :radius =>20
      end
    end
    animate(20) do
      clear
      stroke black
      fill white     

      oval 150, 100, :radius =>140 
      $spin += $speed
      $ang.replace "#{$spin}"
      rotate $speed
      taiji
    end
  window :width => 150, :height => 70 do

    para "Rotate Angle:"
    $ang = para "0"; $spin = 0
    button "Reverse" do
      $speed *= -1
    end
  end
end

Subject: Re: I want to draw a taiji animation by shoes

From: [email protected]
To: [email protected]
Date: Fri, 7 Aug 2009 22:03:08 +0800


Thanks a lot!

It seems that each step in animation rotate angle is on the basis of previous 
angle,not from original position.And if use clear method in animation,speed of 
shoes will not be slow.Otherwise,speed will be slower and slower.



I append 2 buttons  try to control rotate direction(clockwise or 
anti-clockwise).But it does not work.Can animate method take effect in method?


On Fri, Aug 7, 2009 at 1:32 AM, Ehsanul Hoque <[email protected]> wrote:







Actually, it seems my code makes the taiji spin faster as time goes, not good. 
This works the right way though:

Speed = 8

Shoes.app :width => 600, :height => 600, :resizable => false do

  transform(:center)

  para "Rotate Angle:"

  ang = para "0"; spin = 0

  
  def taiji
    image 280, 280, :top => 100, :left => 150 do

      # drawing order is important!!!

      stroke black

      nofill     
      oval 0, 0, :radius =>140 

      #angle1 -> angle2 is clockwise, lead to fill surplus semi-circle

      fill black

      shape do

        move_to  70, 50

        arc_to 140,70,140,140,TWO_PI-PI/2,PI/2

        arc_to 140,210,140,140,PI/2,TWO_PI-PI/2

        arc_to 140,140,280,280,PI/2,TWO_PI-PI/2

      end    

      stroke white

      fill white

      oval 70,140,:radius=>70 # erase the surplus black semi-circle

      oval 120, 50, :radius =>20  

      fill black

      oval 120, 190, :radius =>20

    end
  end
  

  animate(20) do |i|

    clear

    stroke black

    fill white     
    oval 150, 100, :radius =>140 

    spin += Speed

    ang.replace "#{spin}"

    rotate Speed #30 * cnt

    taiji

  end

end

Subject: RE: I want to draw a taiji animation by shoes
From: [email protected]
Date: Thu, 6 Aug 2009 17:23:06 +0000


To: [email protected]








Hey, I just hacked together a solution. The problem was that it was taking too 
long to draw, and the angle of spin was quite large. So it looked like it was 
going anti-clockwise, when in fact it went clockwise, but far. Shoes itself is 
also slow now. Anyways, this code works:



Speed = 0.1

Shoes.app :width => 600, :height => 600, :resizable => false do

  transform(:center)

  para "Rotate Angle:"

  ang = para "0"

  
  def taiji
    image 280, 280, :top => 100, :left => 150 do

      # drawing order is important!!!

      stroke black

      nofill     
      oval 0, 0, :radius =>140 

      #angle1 -> angle2 is clockwise, lead to fill surplus semi-circle

      fill black

      shape do

        move_to  70, 50

        arc_to 140,70,140,140,TWO_PI-PI/2,PI/2

        arc_to 140,210,140,140,PI/2,TWO_PI-PI/2

        arc_to 140,140,280,280,PI/2,TWO_PI-PI/2

      end    

      stroke white

      fill white

      oval 70,140,:radius=>70 # erase the surplus black semi-circle

      oval 120, 50, :radius =>20  

      fill black

      oval 120, 190, :radius =>20

    end
  end
  

  animate(20) do |i|

    clear

    #clear backgroud

      stroke black

      fill white     
      oval 150, 100, :radius =>140 

    spin = i*Speed

    ang.replace "#{spin}"

    rotate spin #30 * cnt

    taiji

  end

end

CC: [email protected]
Subject: I want to draw a taiji animation by shoes
From: [email protected]


To: [email protected]
Date: Thu, 6 Aug 2009 22:15:31 +0800

hi,

I'm from China.I want to produce a rotate taiji animation by shoes.But I found 
2 problems.



1st,there is no fill() method(filled an enclose area with specified color) in 
shoes.So I have 

to first draw black area,then draw a white semi-circle to erase part of black 
area to produce 


Taiji map.Maybe someone has better method.

2nd,to make rotate animation,I draw a taiji map then rotate a certain angle in 
each step.The 

angle increased relate to time.Without animate,the taiji map was displalyed in 
correct 




rotated angle.But when I add animate method,the taiji does not rotate as I 
expected.Sometimes 

it rotate clockwise,sometimes it rotate anti-clockwise.I don't know why.

ruby code in attachment.






Jason Zhou


Get free photo software from Windows Live Click here.


Windows Liveā„¢: Keep your life in sync. Check it out.


Get back to school stuff for them and cashback for you. Try Bing now.



_________________________________________________________________
Get back to school stuff for them and cashback for you.
http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1

Reply via email to