Last active
February 25, 2018 05:50
-
-
Save JoshCheek/96d7291035fe65b0c76248a469b2b62b to your computer and use it in GitHub Desktop.
iTerm2 version 3 beta has an option to pass image data in an escape sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this works in Fish, prob works in Bash too, I didn't try it | |
# you'll probably need to install the chunky_png gem: `gem install chunky_png` | |
# docs: http://iterm2.com/documentation-images.html | |
# video: https://vimeo.com/170123782 | |
ruby -r chunky_png -r base64 -e ' | |
radius = 100 | |
num_points = 200 | |
magnitude_delta = 0.1 | |
white = ChunkyPNG::Color.rgb 0xFF, 0xFF, 0xFF | |
clear = ChunkyPNG::Color.rgba 0xFF, 0x00, 0x00, 0x00 | |
to_radians = -> point { 2*Math::PI * point/num_points } | |
to_x = -> radians { Integer radius+radius*Math.cos(radians) } | |
to_y = -> radians { Integer radius+radius*Math.sin(radians) } | |
display_image = -> b64img { "\e]1337;File=preserveAspectRatio=1;inline=1:#{b64img}\a" } | |
save_cursor = "\e[s" | |
restore_cursor = "\e[u" | |
# Use C-c to kill it | |
magnitude = 1 | |
1.upto Float::INFINITY do | |
canvas = ChunkyPNG::Canvas.new 2*radius, 2*radius, clear | |
1.upto num_points do |point| | |
start = to_radians[point] | |
finish = to_radians[point*magnitude] | |
canvas.line to_x[start],to_y[start], to_x[finish],to_y[finish], white | |
end | |
img_data = Base64.encode64 canvas.to_blob(fast_rgba: true) | |
print "#{save_cursor}#{display_image[img_data]}#{"%0.2f"%magnitude}#{restore_cursor}" | |
magnitude += magnitude_delta | |
end' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment