Sha256: 529e9d59d4e278924892e9214069e50a85d7563b826fea7c643338abe5ef687c

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

##############################
# electrophoresis.rb whatever
# demonstrates the hbar custom
# terminal. Also weighted rules
# by Martin Prout
##############################
require 'cf3'

def setup_the_gel
  @pcr = ContextFree.define do
    ############ Begin defining custom terminal, a proportional horizontal bar
    class << self   
      define_method(:hbar) do |some_options|
        size, options = *self.get_shape_values(some_options)
        ht = some_options[:ht]|| 0.1    # default hbar width is 0.1
        ratio = ht * size 
        rot = options[:rotation]
        rect_mode(CENTER)
        rotate(rot) if rot 
        rect(-0.5 * size, -0.5 * ratio, 0.5 * size, 0.5 * ratio)
      end
    end
    ########### End definition of custom terminal 'hbar'
 
    shape :gel do
      dna brightness: 1.0
    end
 
    shape :dna do
      split do
        26.times do
          band x: 0.6
          rewind
        end
      end
    end
 
    shape :band do       # narrow band with 0.66' probability        
      hbar size: 0.8, ht: 0.1, brightness: 0.3, alpha: 0.3, hue: 251, saturation: 1.0
      band brightness: 0.5
    end
 
    shape :band, 0.5 do   # double width band with 0.33' probability      
      hbar size: 0.8, ht: 0.15, brightness: 0.8, alpha: 0.6, hue: -36, saturation: 1.0
      band brightness: 0.5
    end
 
    shape :band, 0.08 do  # a low probability empty rule used to end recursion     
    end 
   
    shape :band do             
      band y: -0.23
    end
 
    shape :band do         
      band y: 0.17
    end
 
    shape :band do
       band y: 0.29 
    end

    shape :band do
      band y: -0.33 
    end

  end
end

def setup
  size 500, 300
  background 0, 0, 180
  smooth
  setup_the_gel
  draw_it
end

def draw
  # needed to have a draw loop so we can re-run on mouse click
end

def draw_it
  @pcr.render :gel, start_x: -50, start_y: height/2, 
               size: height/5, color: [252, 0.8, 0.8, 1.0]
end

def mouse_clicked
  draw_it
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cf3-0.0.5 samples/pcr.rb
cf3-0.0.4 samples/pcr.rb
cf3-0.0.3 samples/pcr.rb