Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: easter-egg.rb
require "reline"
[0] Fix | Delete
[1] Fix | Delete
module IRB
[2] Fix | Delete
class << self
[3] Fix | Delete
class Vec
[4] Fix | Delete
def initialize(x, y, z)
[5] Fix | Delete
@x, @y, @z = x, y, z
[6] Fix | Delete
end
[7] Fix | Delete
[8] Fix | Delete
attr_reader :x, :y, :z
[9] Fix | Delete
[10] Fix | Delete
def sub(other)
[11] Fix | Delete
Vec.new(@x - other.x, @y - other.y, @z - other.z)
[12] Fix | Delete
end
[13] Fix | Delete
[14] Fix | Delete
def dot(other)
[15] Fix | Delete
@x*other.x + @y*other.y + @z*other.z
[16] Fix | Delete
end
[17] Fix | Delete
[18] Fix | Delete
def cross(other)
[19] Fix | Delete
ox, oy, oz = other.x, other.y, other.z
[20] Fix | Delete
Vec.new(@y*oz-@z*oy, @z*ox-@x*oz, @x*oy-@y*ox)
[21] Fix | Delete
end
[22] Fix | Delete
[23] Fix | Delete
def normalize
[24] Fix | Delete
r = Math.sqrt(self.dot(self))
[25] Fix | Delete
Vec.new(@x / r, @y / r, @z / r)
[26] Fix | Delete
end
[27] Fix | Delete
end
[28] Fix | Delete
[29] Fix | Delete
class Canvas
[30] Fix | Delete
def initialize((h, w))
[31] Fix | Delete
@data = (0..h-2).map { [0] * w }
[32] Fix | Delete
@scale = [w / 2.0, h-2].min
[33] Fix | Delete
@center = Complex(w / 2, h-2)
[34] Fix | Delete
end
[35] Fix | Delete
[36] Fix | Delete
def line((x1, y1), (x2, y2))
[37] Fix | Delete
p1 = Complex(x1, y1) / 2 * @scale + @center
[38] Fix | Delete
p2 = Complex(x2, y2) / 2 * @scale + @center
[39] Fix | Delete
line0(p1, p2)
[40] Fix | Delete
end
[41] Fix | Delete
[42] Fix | Delete
private def line0(p1, p2)
[43] Fix | Delete
mid = (p1 + p2) / 2
[44] Fix | Delete
if (p1 - p2).abs < 1
[45] Fix | Delete
x, y = mid.rect
[46] Fix | Delete
@data[y / 2][x] |= (y % 2 > 1 ? 2 : 1)
[47] Fix | Delete
else
[48] Fix | Delete
line0(p1, mid)
[49] Fix | Delete
line0(p2, mid)
[50] Fix | Delete
end
[51] Fix | Delete
end
[52] Fix | Delete
[53] Fix | Delete
def draw
[54] Fix | Delete
@data.each {|row| row.fill(0) }
[55] Fix | Delete
yield
[56] Fix | Delete
@data.map {|row| row.map {|n| " ',;"[n] }.join }.join("\n")
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
class RubyModel
[61] Fix | Delete
def initialize
[62] Fix | Delete
@faces = init_ruby_model
[63] Fix | Delete
end
[64] Fix | Delete
[65] Fix | Delete
def init_ruby_model
[66] Fix | Delete
cap_vertices = (0..5).map {|i| Vec.new(*Complex.polar(1, i * Math::PI / 3).rect, 1) }
[67] Fix | Delete
middle_vertices = (0..5).map {|i| Vec.new(*Complex.polar(2, (i + 0.5) * Math::PI / 3).rect, 0) }
[68] Fix | Delete
bottom_vertex = Vec.new(0, 0, -2)
[69] Fix | Delete
[70] Fix | Delete
faces = [cap_vertices]
[71] Fix | Delete
6.times do |j|
[72] Fix | Delete
i = j-1
[73] Fix | Delete
faces << [cap_vertices[i], middle_vertices[i], cap_vertices[j]]
[74] Fix | Delete
faces << [cap_vertices[j], middle_vertices[i], middle_vertices[j]]
[75] Fix | Delete
faces << [middle_vertices[i], bottom_vertex, middle_vertices[j]]
[76] Fix | Delete
end
[77] Fix | Delete
[78] Fix | Delete
faces
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
def render_frame(i)
[82] Fix | Delete
angle = i / 10.0
[83] Fix | Delete
dir = Vec.new(*Complex.polar(1, angle).rect, Math.sin(angle)).normalize
[84] Fix | Delete
dir2 = Vec.new(*Complex.polar(1, angle - Math::PI/2).rect, 0)
[85] Fix | Delete
up = dir.cross(dir2)
[86] Fix | Delete
nm = dir.cross(up)
[87] Fix | Delete
@faces.each do |vertices|
[88] Fix | Delete
v0, v1, v2, = vertices
[89] Fix | Delete
if v1.sub(v0).cross(v2.sub(v0)).dot(dir) > 0
[90] Fix | Delete
points = vertices.map {|p| [nm.dot(p), up.dot(p)] }
[91] Fix | Delete
(points + [points[0]]).each_cons(2) do |p1, p2|
[92] Fix | Delete
yield p1, p2
[93] Fix | Delete
end
[94] Fix | Delete
end
[95] Fix | Delete
end
[96] Fix | Delete
end
[97] Fix | Delete
end
[98] Fix | Delete
[99] Fix | Delete
private def easter_egg(type = nil)
[100] Fix | Delete
type ||= [:logo, :dancing].sample
[101] Fix | Delete
case type
[102] Fix | Delete
when :logo
[103] Fix | Delete
File.open(File.join(__dir__, 'ruby_logo.aa')) do |f|
[104] Fix | Delete
require "rdoc"
[105] Fix | Delete
RDoc::RI::Driver.new.page do |io|
[106] Fix | Delete
IO.copy_stream(f, io)
[107] Fix | Delete
end
[108] Fix | Delete
end
[109] Fix | Delete
when :dancing
[110] Fix | Delete
begin
[111] Fix | Delete
canvas = Canvas.new(Reline.get_screen_size)
[112] Fix | Delete
Reline::IOGate.set_winch_handler do
[113] Fix | Delete
canvas = Canvas.new(Reline.get_screen_size)
[114] Fix | Delete
end
[115] Fix | Delete
ruby_model = RubyModel.new
[116] Fix | Delete
print "\e[?1049h"
[117] Fix | Delete
0.step do |i| # TODO (0..).each needs Ruby 2.6 or later
[118] Fix | Delete
buff = canvas.draw do
[119] Fix | Delete
ruby_model.render_frame(i) do |p1, p2|
[120] Fix | Delete
canvas.line(p1, p2)
[121] Fix | Delete
end
[122] Fix | Delete
end
[123] Fix | Delete
buff[0, 20] = "\e[0mPress Ctrl+C to stop\e[31m\e[1m"
[124] Fix | Delete
print "\e[H" + buff
[125] Fix | Delete
sleep 0.05
[126] Fix | Delete
end
[127] Fix | Delete
ensure
[128] Fix | Delete
print "\e[0m\e[?1049l"
[129] Fix | Delete
end
[130] Fix | Delete
end
[131] Fix | Delete
end
[132] Fix | Delete
end
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
IRB.send(:easter_egg, ARGV[0]&.to_sym) if $0 == __FILE__
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function