Skip to content

Instantly share code, notes, and snippets.

@tomdalling
Created September 18, 2020 07:24
Show Gist options
  • Save tomdalling/2540a1c785d51da2bf0d57164bd26d96 to your computer and use it in GitHub Desktop.
Save tomdalling/2540a1c785d51da2bf0d57164bd26d96 to your computer and use it in GitHub Desktop.
require 'json'
COLORS = {
'#' => '#216e39',
'+' => '#30a14e',
':' => '#40c463',
'-' => '#9be9a8',
'.' => '#ebedf0',
' ' => nil,
}
COLS = 53
ROWS = 7
CELLS = 370
def line(str)
str.chomp("\n").chomp("|").chars.map do |ch|
COLORS.fetch(ch)
end
end
def frame(str)
str
.lines
.map { line(_1) }
end
def serialize(frame)
return nil if frame.nil?
COLS.times.flat_map { |idx| frame.map { _1[idx] } }
end
def scroll(frame)
scroll_in(frame) + [frame] + scroll_out(frame)
end
def scroll_in(frame)
Array.new(COLS - 1) do |idx|
frame.map do |row|
left = [nil] * (COLS - idx)
right = row.take(COLS - left.size)
left + right
end
end
end
def scroll_out(frame)
cols = frame.first.size
Array.new(cols - 1) do |idx|
frame.map do |row|
left = row.drop(idx + 1)
right = [nil] * (cols - left.size)
left + right
end
end
end
def strobe(frame, other_frame = nil)
[frame, frame, frame, other_frame, other_frame, other_frame] * 20
end
def still(frame)
[frame] * 20
end
TOM_IS_NO1 = frame(<<-END_FRAME)
.-----..--..-. .-. .---..----. .-.-. .--. |
.-#####--##--#-.-#-..-###--####-. .-#-#-.-##-. |
.--#---#--#-##-##-. .-#--#-. .-#####-#-#-. |
.-#-.-#--#-#-#-#-. .-#-.-###-. .-#-#-..-#-. |
.-#-.-#--#-#-.-#-. .-#-. .-#-..-#####-.-#-. |
.-#-..-##--#-.-#-..-###-####-. .-#-#--#####-. |
.-. .--..-. .-. .---.----. .-.-..-----. |
END_FRAME
WORKS = frame(<<-END_FRAME)
. ....#.....#.#######.######..#....#..#####...... . |
.....#..#..#.#.....#.#.....#.#...#..#.....#...... |
- ----#--#--#-#-----#-#-----#-#--#---#----------- - |
-----#--#--#-#-----#-######--###-----#####------- |
- ----#--#--#-#-----#-#---#---#--#---------#----- - |
:::::#::#::#:#:::::#:#::::#::#:::#::#:::::#:::::: |
: :::::##:##::#######:#:::::#:#::::#::#####:::::: : |
END_FRAME
REAL = frame(<<-END_FRAME)
. .....######..#######....#....#........... . |
......#.....#.#.........#.#...#............ |
- -----#-----#-#--------#---#--#----------- - |
------######--#####---#-----#-#------------ |
- -----#---#---#-------#######-#----------- - |
::::::#::::#::#:::::::#:::::#:#:::::::::::: |
: :::::#:::::#:#######:#:::::#:#######::::: : |
END_FRAME
HARD = frame(<<-END_FRAME)
. .....#.....#....#....######..######...... . |
......#.....#...#.#...#.....#.#.....#...... |
- -----#-----#--#---#--#-----#-#-----#----- - |
------#######-#-----#-######--#-----#------ |
- -----#-----#-#######-#---#---#-----#----- - |
::::::#:::::#:#:::::#:#::::#::#:::::#:::::: |
: :::::#:::::#:#:::::#:#:::::#:######:::::: : |
END_FRAME
LOTS_OF_COMMITS = frame(<<-END_FRAME)
-:::- -::::::::-:::::::::::-::::::::- -::::::::--::::::::::- -::::::::- -::::::::- -:::- -:::- -:::- -:::- -:::::::::::-:::::::::::-:::::::: |
-:+:- -:+:- -:+:- -:+:- -:+:- -:+:- -:+:- -:+:-:+:- -:+:- -:+:-:+:- -:+:--:+:+:-:+:+:- -:+:+:-:+:+:- -:+:- -:+:- -:+:- -:+: |
-+:+- -+:+- -+:+- -+:+- -+:+- -+:+- -+:+-+:+- -+:+- -+:+- -+:+-+:+-+:+:+-+:+-+:+-+:+:+-+:+- -+:+- -+:+- -+:+- |
-+#+- -+#+- -+:+- -+#+- -+#++:++#++- -+#+- -+:+-:#::+::#- -+#+- -+#+- -+:+-+#+--+:+--+#+-+#+--+:+--+#+- -+#+- -+#+- -+#++:++#++- |
-+#+- -+#+- -+#+- -+#+- -+#+- -+#+- -+#+-+#+- -+#+- -+#+- -+#+-+#+- -+#+-+#+- -+#+- -+#+- -+#+- -+#+- |
-#+#- -#+#- -#+#- -#+#- -#+#- -#+#- -#+#- -#+#-#+#- -#+#- -#+#-#+#- -#+#-#+#- -#+#-#+#- -#+#- -#+#- -#+#- -#+#- -#+#- |
-##########-########- -###- -########- -########--###- -########- -########--###- -###-###- -###-###########- -###- -########- |
END_FRAME
FRAMES = [
strobe(TOM_IS_NO1),
still(WORKS),
still(REAL),
still(HARD),
scroll(LOTS_OF_COMMITS)
].flatten(1)
puts <<~END_JS
var frames = #{JSON.dump(FRAMES.map { serialize(_1) })};
var cells = Array.prototype.slice.call(document.querySelectorAll('rect.day'));
var original_frame = cells.map(e => e.getAttribute('fill'));
frames.push(original_frame);
setInterval(function(){
var this_frame = frames.shift();
frames.push(this_frame);
this_frame = this_frame || original_frame;
cells.forEach((e, idx) => {
e.setAttribute('fill', this_frame[idx] || original_frame[idx]);
})
}, 33)
END_JS
This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment