From 3e585cade600783e6f405bcceecf0120ade8be64 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 3 Jan 2020 21:13:57 +0100 Subject: Version for video --- glitchyclock.c | 64 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/glitchyclock.c b/glitchyclock.c index 89ba8e3..90e2aaa 100644 --- a/glitchyclock.c +++ b/glitchyclock.c @@ -21,35 +21,36 @@ /* Get LED display fonts from here: https://www.keshikan.net/fonts-e.html */ #include +#include struct glitchyclock { GtkWidget *da; PangoFontDescription *fontdesc; int nglitch; - time_t glitch_base; + double glitch_base; }; const int glitch_times[] = { - 7, 15, + 4, 15, 23, 58, -1, -1 }; -static time_t get_monotonic_seconds() +static double get_monotonic_seconds() { struct timespec tp; clock_gettime(CLOCK_MONOTONIC, &tp); - return tp.tv_sec; + return tp.tv_sec + (double)tp.tv_nsec/1e9; } static void do_glitch(struct glitchyclock *gc) { - if ( glitch_times[2*(gc->nglitch+1)] == -1 ) return; - gc->nglitch++; + //if ( glitch_times[2*(gc->nglitch+1)] == -1 ) return; + //gc->nglitch++; gc->glitch_base = get_monotonic_seconds(); } @@ -60,10 +61,13 @@ static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct glitchyclock *gc int lw, lh; double sf; PangoLayout *layout; - const double screen_w_frac = 0.4; + const double screen_w_frac = 0.6; int glitch_hours, glitch_minutes; char timestr[64]; - int seconds; + double seconds_f; + char col; + double seconds_if; + int hours, minutes, seconds; w = gtk_widget_get_allocated_width(widget); h = gtk_widget_get_allocated_height(widget); @@ -76,19 +80,33 @@ static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct glitchyclock *gc pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_font_description(layout, gc->fontdesc); - glitch_hours = glitch_times[gc->nglitch*2]; - glitch_minutes = glitch_times[gc->nglitch*2+1]; - seconds = get_monotonic_seconds() - gc->glitch_base; - - if ( seconds < 4 ) { - strcpy(timestr, "rK:S8"); - } else { - int hours, minutes; - hours = (seconds/3600 + glitch_hours) % 24; - minutes = (seconds/60 + glitch_minutes) % 60; - snprintf(timestr, 63, "%02i:%02i", hours, minutes); + seconds_f = get_monotonic_seconds() - gc->glitch_base; + col = (modf(seconds_f, &seconds_if) < 0.5) ? ':' : ' '; + seconds = seconds_if; + if ( seconds > 16 ) seconds = 16; + + hours = (seconds/3600 + 4) % 24; + minutes = (seconds/60 + 48) % 60; + seconds += 15; + snprintf(timestr, 63, "%02i%c%02i%c%02i", hours, col, minutes, col, seconds); + + double duty = 0.5; + if ( seconds_f > 17.0 ) { + duty = 0.5 + (seconds_f - 17.0)/10.0; + if ( duty > 1.0 ) duty = 1.0; } - pango_layout_set_text(layout, "88:88", -1); + if ( ((seconds_f > 7.1) && (seconds_f < 7.9)) + || ((seconds_f > 12.2) && (seconds_f < 13.1)) + || ((seconds_f > 17.0)) ) + { + if ( fmod(seconds_f, 0.05) > duty*0.05 ) { + strcpy(timestr, "00:rK:c1"); + } else { + strcpy(timestr, "88:v8:68"); + } + } + + pango_layout_set_text(layout, "88:88:88", -1); pango_cairo_update_layout(cr, layout); pango_layout_get_size(layout, &lw, &lh); @@ -100,10 +118,10 @@ static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct glitchyclock *gc pango_layout_get_size(layout, &lw, &lh); lw /= PANGO_SCALE; lh /= PANGO_SCALE; w /= sf; h /= sf; - cairo_translate(cr, (w-lw)/2.0, h-lh); + cairo_translate(cr, (w-lw)/2.0, h-lh-20.0); pango_cairo_update_layout(cr, layout); - cairo_set_source_rgb(cr, 0.04, 0.0, 0.0); + cairo_set_source_rgb(cr, 0.10, 0.0, 0.0); pango_cairo_show_layout(cr, layout); pango_layout_set_text(layout, timestr, -1); @@ -174,7 +192,7 @@ int main(int argc, char *argv[]) gtk_widget_grab_focus(GTK_WIDGET(gc.da)); gtk_widget_show_all(mainwindow); - g_timeout_add(1000, redraw_cb, &gc); + g_timeout_add(20, redraw_cb, &gc); gtk_main(); -- cgit v1.2.3