Skip to content

Instantly share code, notes, and snippets.

@finnmglas
Created February 1, 2025 21:19
Show Gist options
  • Save finnmglas/b6ce945cc5b7ba4e88f4a5fe0bb21fee to your computer and use it in GitHub Desktop.
Save finnmglas/b6ce945cc5b7ba4e88f4a5fe0bb21fee to your computer and use it in GitHub Desktop.
For Julia ❤
using Printf, Dates, TerminalMenus
function get_terminal_size()
rows, cols = displaysize(stdout)
return rows, cols
end
function heart_ascii(scale, term_rows, term_cols)
heart = []
heart_width = round(Int, 40 * scale) # Use `round(Int, value)`
heart_height = round(Int, 20 * scale)
center_x = max(0, div(term_cols - heart_width, 2)) # Prevent negative values
center_y = max(0, div(term_rows - heart_height, 2))
for y in range(1.5, stop=-1.5, length=heart_height)
row = " "^center_x # Add horizontal centering
for x in range(-1.5, stop=1.5, length=heart_width)
formula = (x^2 + (y - sqrt(abs(x)))^2 - 1)
row *= (formula < 0) ? "❤" : " " # Heart character
end
push!(heart, row)
end
return "\n"^center_y * join(heart, "\n") # Add vertical centering
end
function animate_heart(frames=100, delay=0.1)
for i in 1:frames
term_rows, term_cols = get_terminal_size()
scale = 0.8 + 0.3 * sin(i * 0.3) # Pulsing effect
heart = heart_ascii(scale, term_rows, term_cols)
print("\033[H\033[J") # Clear screen
println(heart)
sleep(delay)
end
end
animate_heart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment