Class: IRB::RubyModel (Ruby 2.7.5)
Description: Class : IRB::RubyModel - Ruby 2.7.5

### Home Classes Methods

### In Files

- irb/easter-egg.rb

### Parent

Object

### Methods

- ::new
- #init_ruby_model
- #render_frame

### Class/Module Index

Quicksearch

- Binding
- IRB::Abort
- IRB::Canvas
- IRB::Color
- IRB::Color::SymbolState
- IRB::Context
- IRB::ContextExtender
- IRB::ExtendCommandBundle
- IRB::FileInputMethod
- IRB::Frame
- IRB::Frame::FrameOverflow
- IRB::Frame::FrameUnderflow
- IRB::History
- IRB::InputMethod
- IRB::Inspector
- IRB::Irb
- IRB::IrbLoader
- IRB::JobManager
- IRB::LoadAbort
- IRB::MethodExtender
- IRB::Notifier
- IRB::Notifier::AbstractNotifier
- IRB::Notifier::CompositeNotifier
- IRB::Notifier::ErrUndefinedNotifier
- IRB::Notifier::ErrUnrecognizedLevel
- IRB::Notifier::LeveledNotifier
- IRB::Notifier::NoMsgNotifier
- IRB::OutputMethod
- IRB::OutputMethod::NotImplementedError
- IRB::ReadlineInputMethod
- IRB::ReidlineInputMethod
- IRB::RubyModel
- IRB::StdioInputMethod
- IRB::StdioOutputMethod
- IRB::Vec
- IRB::WorkSpace
- Object
- XMP
- XMP::StringInputMethod

No matching classes.

# IRB::RubyModel

### Public Class Methods

new() click to toggle source

                   # File irb/easter-egg.rb, line 63
    def initialize
      @faces = init_ruby_model
    end

### Public Instance Methods

init_ruby_model() click to toggle source

                   # File irb/easter-egg.rb, line 67
    def init_ruby_model
      cap_vertices    = (0..5).map {|i| Vec.new(*Complex.polar(1,  i        * Math::PI / 3).rect, 1) }
      middle_vertices = (0..5).map {|i| Vec.new(*Complex.polar(2, (i + 0.5) * Math::PI / 3).rect, 0) }
      bottom_vertex   = Vec.new(0, 0, -2)

      faces = [cap_vertices]
      6.times do |j|
        i = j-1
        faces << [cap_vertices[i], middle_vertices[i], cap_vertices[j]]
        faces << [cap_vertices[j], middle_vertices[i], middle_vertices[j]]
        faces << [middle_vertices[i], bottom_vertex, middle_vertices[j]]
      end

      faces
    end

render_frame(i) click to toggle source

                   # File irb/easter-egg.rb, line 83
    def render_frame(i)
      angle = i / 10.0
      dir = Vec.new(*Complex.polar(1, angle).rect, Math.sin(angle)).normalize
      dir2 = Vec.new(*Complex.polar(1, angle - Math::PI/2).rect, 0)
      up = dir.cross(dir2)
      nm = dir.cross(up)
      @faces.each do |vertices|
        v0, v1, v2, = vertices
        if v1.sub(v0).cross(v2.sub(v0)).dot(dir) > 0
          points = vertices.map {|p| [nm.dot(p), up.dot(p)] }
          (points + [points[0]]).each_cons(2) do |p1, p2|
            yield p1, p2
          end
        end
      end
    end