Sha256: 84b5ca42709421992414e8b5c0579edc55994c77614ac22971a3ad915c187945

Contents?: true

Size: 840 Bytes

Versions: 5

Compression:

Stored size: 840 Bytes

Contents

require_relative 'easing'
require_relative 'frameset'

module WhirledPeas
  module Animator
    class Producer
      def self.produce(consumer, refresh_rate)
        producer = new(consumer, refresh_rate)
        yield producer
        consumer.process
      end

      def initialize(consumer, refresh_rate)
        @consumer = consumer
        @refresh_rate = refresh_rate
      end

      def add_frame(name, duration: nil, args: {})
        frameset(duration || 1 / refresh_rate) do |fs|
          fs.add_frame(name, args: args)
        end
      end

      def frameset(duration, easing: :linear, effect: :in_out, &block)
        fs = Frameset.new((duration * refresh_rate).round, easing, effect)
        yield fs
        consumer.add_frameset(fs)
      end

      private

      attr_reader :consumer, :refresh_rate
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
whirled_peas-0.11.1 lib/whirled_peas/animator/producer.rb
whirled_peas-0.11.0 lib/whirled_peas/animator/producer.rb
whirled_peas-0.10.0 lib/whirled_peas/animator/producer.rb
whirled_peas-0.9.1 lib/whirled_peas/animator/producer.rb
whirled_peas-0.9.0 lib/whirled_peas/animator/producer.rb