Class: PrideLOL

Inherits:
PrideIO show all
Defined in:
lib/minitest/pride.rb

Overview

inspired by lolcat, but massively cleaned up

Constant Summary collapse

PI_3 =
Math::PI / 3

Constants inherited from PrideIO

PrideIO::ESC, PrideIO::NND

Instance Attribute Summary

Attributes inherited from PrideIO

#io

Instance Method Summary collapse

Methods inherited from PrideIO

#method_missing, #print, #puts

Constructor Details

#initialize(io) ⇒ PrideLOL

Returns a new instance of PrideLOL.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/minitest/pride.rb', line 67

def initialize io
  # walk red, green, and blue around a circle separated by equal thirds.
  #
  # To visualize, type this into wolfram-alpha:
  #
  #   plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)

  # 6 has wide pretty gradients. 3 == lolcat, about half the width
  @colors = (0...(6 * 7)).map { |n|
    n *= 1.0 / 6
    r  = (3 * Math.sin(n           ) + 3).to_i
    g  = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
    b  = (3 * Math.sin(n + 4 * PI_3) + 3).to_i

    # Then we take rgb and encode them in a single number using base 6.
    # For some mysterious reason, we add 16... to clear the bottom 4 bits?
    # Yes... they're ugly.

    36 * r + 6 * g + b + 16
  }

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PrideIO

Instance Method Details

#pride(string) ⇒ Object



91
92
93
94
95
# File 'lib/minitest/pride.rb', line 91

def pride string
  c = @colors[@index % @size]
  @index += 1
  "#{ESC}38;5;#{c}m#{string}#{NND}"
end