forked from andrewheiss/gif_timer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8b16ecc
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Libraries | ||
library(animation) | ||
library(dplyr) | ||
library(lubridate) | ||
library(ggplot2) | ||
|
||
# Blank ggplot theme | ||
blank_theme <- theme_bw() + | ||
theme(line = element_blank(), rect = element_blank(), | ||
strip.text = element_blank(), axis.text = element_blank(), | ||
plot.title = element_blank(), axis.title = element_blank(), | ||
plot.margin = structure(c(0, 0, -1, -1), unit = "lines", | ||
valid.unit = 3L, class = "unit")) | ||
|
||
# Create data frame of all the times to display | ||
df <- data_frame(timer = rev(format(seq(ymd_hms("2015-04-08 00:00:00"), | ||
ymd_hms("2015-04-08 00:00:00") + minutes(1), | ||
by="sec"), "%M:%S"))) | ||
|
||
# Start recording | ||
ani.record(reset=TRUE) | ||
|
||
# Plot each time as text | ||
for (i in 1:nrow(df)) { | ||
p <- ggplot(slice(df, i), aes(x=1, y=1, label=timer)) + | ||
geom_text(size=50, family="Source Sans Pro Light") + | ||
blank_theme | ||
print(p) | ||
ani.record() | ||
} | ||
|
||
# Save final animation | ||
# TODO: Looping doesn't work (maybe an ImageMagick/GIF problem though) | ||
saveGIF(ani.replay(), interval=1, movie.name="timer_r.gif", | ||
ani.width=600, ani.height=400, loop=1) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# `brew install imagemagick --with-x11` to support `display` and `animate` commands | ||
# Verify x11 support with `convert --version` | ||
from wand.image import Image | ||
from wand.drawing import Drawing | ||
from wand.color import Color | ||
|
||
# Helpful links and documentation | ||
# http://docs.wand-py.org/en/0.4.0/guide/sequence.html | ||
# http://stackoverflow.com/questions/16544399/wand-python-multi-size-icon | ||
|
||
# TODO: Transparency doesn't work---previous images are overlaid and not antialiased | ||
# TODO: Make the gif not loop | ||
# MAYBE: Make font red for last 10ish seconds? | ||
|
||
# Timer settings | ||
filename = "timer_python.gif" | ||
bg_color = "white" | ||
seconds = 1 * 60 | ||
|
||
# Generate time labels | ||
def nice_time(seconds): | ||
m, s = divmod(seconds, 60) | ||
# m can be subdivided to hours if needed: | ||
# h, m = divmod(m, 60) | ||
return("{0:02d}:{1:02d}".format(m, s)) | ||
|
||
# from datetime import timedelta | ||
# lambda x: str(timedelta(seconds=x)) works great, but it doesn't let you | ||
# format the string however you want | ||
|
||
labels = list(map(nice_time, reversed(range(seconds + 1)))) | ||
|
||
with Image() as gif: | ||
for label in labels: | ||
with Drawing() as draw: | ||
draw.font = "SourceSansPro-Light.otf" | ||
draw.font_size = 140 | ||
draw.text_alignment = "center" | ||
draw.text_antialias = True | ||
|
||
with Image(width=600, height=400, background=Color(bg_color)) as img: | ||
x = int(img.width / 2) | ||
y = int(img.height / 2) | ||
draw.text(x, y, label) | ||
draw.draw(img) | ||
gif.sequence.append(img) | ||
|
||
for frame in gif.sequence: | ||
with frame: | ||
frame.delay = 100 # Centiseconds | ||
|
||
gif.save(filename=filename) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.