Sha256: 75829e966a5f7ed456ad36a6480018c10199b51284f8ac8ed95b3174a85aced4

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

# -*- encoding : utf-8 -*-
# Scales the comp being exported by a specific factor, together with the tracker keyframes
class Tracksperanto::Tool::Scaler < Tracksperanto::Tool::Base
  DEFAULT_FACTOR = 1
  
  parameter :x_factor,  :cast => :float, :desc => "Factor to scale by", :default => DEFAULT_FACTOR
  parameter :y_factor,  :cast => :float, :desc => "Factor to scale by", :default => 0.5
  
  def self.action_description
    "Scale the comp by a specified factor"
  end
  
  # Called on export start
  def start_export( img_width, img_height)
    set_residual_factor
    @w, @h = (img_width * x_factor).to_i.abs, (img_height * y_factor).to_i.abs
    super(@w, @h)
  end
  
  def y_factor
    @y_factor || DEFAULT_FACTOR
  end
  
  def x_factor
    @x_factor || DEFAULT_FACTOR
  end
  
  def export_point(frame, float_x, float_y, float_residual)
    return super if @y_factor == DEFAULT_FACTOR && @x_factor == DEFAULT_FACTOR
    
    super(frame,
      x_factor < 0 ? (@w + (float_x * x_factor)) : (float_x * x_factor),
      y_factor < 0 ? (@h + (float_y * y_factor)) : (float_y * y_factor),
      (float_residual * @residual_factor)
    )
  end
  
  private
    def set_residual_factor
      @residual_factor = Math.sqrt((x_factor ** 2) + (y_factor ** 2))
    end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
tracksperanto-3.2.2 lib/tools/scaler.rb
tracksperanto-3.2.1 lib/tools/scaler.rb
tracksperanto-3.2.0 lib/tools/scaler.rb
tracksperanto-3.1.0 lib/tools/scaler.rb
tracksperanto-3.0.1 lib/tools/scaler.rb
tracksperanto-3.0.0 lib/tools/scaler.rb