All pastes #1042413 Raw Edit

clueless

public text v1 · immutable
#1042413 ·published 2008-06-08 22:52 UTC
rendered paste body
# Filename: IndivStaff.rb# # This is a class representing a single staff# with specific numbers of leger lines above# and below the staff.require 'rubygems'require 'RMagick'class IndivStaff < Magick::ImageList  def initialize    # thickness in pixels of the staff lines draws    @lineThickness = 2        # how far apart a staff line is from the next (incl leger lines)    @lineSpacing = 15        # how many leger lines above the staff    @upperLegers = 0        # how many leger lines below the staff    @lowerLegers = 0        # how much extra space (in pixels) to allow above the staff and upper legers    @extraTopSpace = 0        # how much space to allow below the staff and lower legers    @extraBottomSpace = 0        # how wide the staff is (not including insets)    @staffWidth = 300        # how much space in pixels to allow on the left and right sides of the staff    @horizontalInset = 30        # @staffX and @staffY are upperleft corner of staff wrt the pane drawn in    @staffX = @horizontalInset    @staffY = @extraTopSpace \               + ((@upperLegers + 1) * @lineSpacing)                 # @paneW and @paneH are width and height of the pane to draw the staff in    @paneW = @staffWidth + @horizontalInset * 2    @paneH = @extraTopSpace \           + (@upperLegers + 1) * @lineSpacing \           + 5 * @lineSpacing \           + @lowerLegers * @lineSpacing \           + @extraBottomSpace               super        self.new_image(@paneW, @paneH)        # @staff is the drawing environemnt for the staff    @staff = Magick::Draw.new    @staff.stroke_width(@lineThickness)    @staff.stroke('black')    @staff.fill_opacity(0)    @staff.stroke_opacity(1)  end    def display    5.times \      {        | i | \          @staff.line(            @staffX,             @staffY + @lineSpacing * i,             @staffX + @staffWidth,             @staffY + @lineSpacing * i          )       }    @staff.draw(self)    super  end    def showVars    puts "@staffX = #{@staffX}"    puts "@staffY = #{@staffY}"    puts "@staffWidth = #{@staffWidth}"    puts "@lineSpacing = #{@lineSpacing}"    puts "@upperLegers = #{@lowerLegers}"    puts "@lowerLegers = #{@lowerLegers}"    puts "@extraTopSpace = #{@extraTopSpace}"    puts "@extraBottomSpace = #{@extraBottomSpace}"    puts "@horizontalInset = #{@horizontalInset}"    puts "@lineThickness = #{@lineThickness}"    puts "@paneW = #{@paneW}"    puts "@paneH = #{@paneH}"  end      end