Sha256: 949ba045c6ec61b39d7209024c383762a97d81a1fdaf92949024c90fc2e3ff14

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

# https://github.com/casparjones/First-Ruby-Steps/blob/master/shoes-samples/simple-curve.rb
# http://www.cairographics.org/samples/curve_to/

# curve_to with visible control points.
# The ovals represent the control points.
Shoes.app(title: "Expert curve_to control points", width: 500, height: 400) do
   xy = [
      [self.width / 8, self.height / 2], 
      [self.width / 8 * 3, self.height / 4 * 3], 
      [self.width / 8 * 4, self.height / 4], 
      [self.width / 8 * 7, self.height / 2]
   ]

   para "click and drag control points..."
   fill green(0.2)
   move_to *xy[0]
   
   @controller = nil
   xy.each { |n|
      (@controllers ||= []) << oval(:left => n[0], :top => n[1], :radius => 10, :center => true)
   }
   @controllers.each { |n|
      n.click do |btn, left, top|
         n.style :fill => red
         @controller = n
      end
      n.release do |btn, left, top|
         n.style :fill => green(0.2)
         @controller = nil
      end
   }
   
   motion do |left, top|
      unless @controller.nil?
         xy[@controllers.index(@controller)] = left, top
         @controller.left, @controller.top = left, top
      end
   end
   
   @stack = stack :top => 0, :left => 0
   
   animate(10) do
      @stack.clear do
         fill red(0.2)   
         shape do
            move_to *xy[0]
            curve_to *xy[1], *xy[2], *xy[3]
         end
      end
   end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
scarpe-0.4.0 examples/legacy/not_checked/expert/curve-control-point.rb
scarpe-0.3.0 examples/legacy/not_checked/expert/curve-control-point.rb
scarpe-0.2.2 examples/legacy/not_checked/expert/curve-control-point.rb
lacci-0.2.1 examples/legacy/not_checked/expert/curve-control-point.rb
scarpe-0.2.1 examples/legacy/not_checked/expert/curve-control-point.rb
scarpe-0.2.0 examples/legacy/not_checked/expert/curve-control-point.rb