|
root / base / hammerhead-desktop / wallpaper-gen.c
wallpaper-gen.c C 206 lines 6.0 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * wallpaper-gen.c - Zygaena marine-dark wallpaper generator.
 *
 * Renders a 1920x1080 PNG: deep-ocean vertical gradient, low-alpha
 * concentric sonar arcs from a lower-left origin, a low-alpha stylized
 * hammerhead-shark silhouette, and the HAMMERHEAD/ZYGAENA wordmark in
 * the lower-right corner.
 *
 * Build: gcc wallpaper-gen.c $(pkg-config --cflags --libs cairo) -lm -o wg
 * Usage: ./wg /path/to/output.png
 */
#include <cairo.h>
#include <math.h>
#include <stdio.h>

#define W 1920
#define H 1080

/* Zygaena marine-dark palette */
#define BG_TOP_R    0x05/255.0
#define BG_TOP_G    0x08/255.0
#define BG_TOP_B    0x0d/255.0
#define BG_BOT_R    0x0a/255.0
#define BG_BOT_G    0x27/255.0
#define BG_BOT_B    0x33/255.0
#define TEAL_R      0x1f/255.0
#define TEAL_G      0xb6/255.0
#define TEAL_B      0xb6/255.0
#define TEAL_BR_R   0x3f/255.0
#define TEAL_BR_G   0xd0/255.0
#define TEAL_BR_B   0xd0/255.0
#define MUTED_R     0x5a/255.0
#define MUTED_G     0x75/255.0
#define MUTED_B     0x75/255.0

static void
draw_background(cairo_t *cr)
{
    cairo_pattern_t *grad = cairo_pattern_create_linear(0, 0, 0, H);
    cairo_pattern_add_color_stop_rgb(grad, 0.0, BG_TOP_R, BG_TOP_G, BG_TOP_B);
    cairo_pattern_add_color_stop_rgb(grad, 1.0, BG_BOT_R, BG_BOT_G, BG_BOT_B);
    cairo_set_source(cr, grad);
    cairo_paint(cr);
    cairo_pattern_destroy(grad);
}

static void
draw_sonar_arcs(cairo_t *cr)
{
    /* Origin lower-left, off canvas a bit so rings sweep across the
     * bottom-left quadrant. */
    double cx = -80, cy = H + 80;
    int rings = 5;
    double base_r = 260;
    double step_r = 220;

    for (int i = 0; i < rings; i++) {
        double alpha = 0.12 - (i * (0.06 / (rings - 1)));
        if (alpha < 0.06) alpha = 0.06;
        cairo_set_source_rgba(cr, TEAL_R, TEAL_G, TEAL_B, alpha);
        cairo_set_line_width(cr, 2.0);
        cairo_arc(cr, cx, cy, base_r + i * step_r, -M_PI / 2.2, 0.15);
        cairo_stroke(cr);
    }
}

/*
 * Stylized hammerhead-shark silhouette: a wide flattened "hammer" head
 * bar with an eye-dot at each end, a tapering dorsal body, and a
 * crescent tail - all in one low-alpha teal fill, large and off-center
 * (upper-left-of-center so it doesn't collide with the wordmark).
 */
static void
draw_hammerhead_motif(cairo_t *cr)
{
    double ox = 560, oy = 430;   /* motif origin (center of the head bar) */
    double scale = 1.55;

    cairo_save(cr);
    cairo_translate(cr, ox, oy);
    cairo_scale(cr, scale, scale);
    cairo_set_source_rgba(cr, TEAL_R, TEAL_G, TEAL_B, 0.10);

    /* Hammer head: a wide, slightly bowed bar. */
    cairo_move_to(cr, -260, 0);
    cairo_curve_to(cr, -180, -34,  180, -34,  260, 0);
    cairo_curve_to(cr,  180,  34, -180,  34, -260, 0);
    cairo_close_path(cr);
    cairo_fill(cr);

    /* Tapering body/tail sweeping down-right from the head's center. */
    cairo_move_to(cr, -40, 18);
    cairo_curve_to(cr, 120, 60,  260, 160,  360, 340);
    cairo_curve_to(cr, 380, 380,  340, 400,  300, 380);
    cairo_curve_to(cr, 220, 220,  90, 100, -40, 54);
    cairo_close_path(cr);
    cairo_fill(cr);

    /* Tail fluke. */
    cairo_move_to(cr, 340, 320);
    cairo_curve_to(cr, 400, 330, 440, 300, 470, 250);
    cairo_curve_to(cr, 450, 310, 420, 360, 380, 400);
    cairo_curve_to(cr, 360, 370, 345, 345, 340, 320);
    cairo_close_path(cr);
    cairo_fill(cr);

    /* Eye-dots at each end of the hammer bar. */
    cairo_arc(cr, -235, 0, 10, 0, 2 * M_PI);
    cairo_fill(cr);
    cairo_arc(cr, 235, 0, 10, 0, 2 * M_PI);
    cairo_fill(cr);

    cairo_restore(cr);
}

/* Draw text with manual letter-spacing (cairo toy text API has no
 * built-in tracking control). */
static void
draw_tracked_text(cairo_t *cr, const char *s, double x, double y, double tracking)
{
    cairo_text_extents_t ext;
    double cx = x;
    char buf[2] = {0, 0};

    for (const char *p = s; *p; p++) {
        buf[0] = *p;
        cairo_text_extents(cr, buf, &ext);
        cairo_move_to(cr, cx, y);
        cairo_show_text(cr, buf);
        cx += ext.x_advance + tracking;
    }
}

static void
draw_wordmark(cairo_t *cr)
{
    cairo_text_extents_t ext;

    cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
        CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size(cr, 64);
    cairo_set_source_rgb(cr, TEAL_R, TEAL_G, TEAL_B);

    /* Measure full tracked width to right-align at x = W - 120. */
    const char *word = "HAMMERHEAD";
    double tracking = 8.0;
    double total_w = 0;
    char buf[2] = {0, 0};
    for (const char *p = word; *p; p++) {
        buf[0] = *p;
        cairo_text_extents(cr, buf, &ext);
        total_w += ext.x_advance + tracking;
    }
    total_w -= tracking;

    double x = W - 120 - total_w;
    double y = H - 150;
    draw_tracked_text(cr, word, x, y, tracking);

    /* Subtitle */
    cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
        CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size(cr, 22);
    cairo_set_source_rgb(cr, MUTED_R, MUTED_G, MUTED_B);

    const char *sub = "ZYGAENA";
    double sub_tracking = 6.0;
    double sub_w = 0;
    for (const char *p = sub; *p; p++) {
        buf[0] = *p;
        cairo_text_extents(cr, buf, &ext);
        sub_w += ext.x_advance + sub_tracking;
    }
    sub_w -= sub_tracking;

    draw_tracked_text(cr, sub, W - 120 - sub_w, y + 40, sub_tracking);
}

int
main(int argc, char **argv)
{
    const char *outpath = (argc > 1) ? argv[1] : "/tmp/hammerhead.png";

    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, W, H);
    cairo_t *cr = cairo_create(surface);

    draw_background(cr);
    draw_sonar_arcs(cr);
    draw_hammerhead_motif(cr);
    draw_wordmark(cr);

    cairo_status_t st = cairo_surface_write_to_png(surface, outpath);
    if (st != CAIRO_STATUS_SUCCESS) {
        fprintf(stderr, "write_to_png failed: %s\n", cairo_status_to_string(st));
        cairo_destroy(cr);
        cairo_surface_destroy(surface);
        return 1;
    }

    printf("wrote %s (%dx%d)\n", outpath, W, H);

    cairo_destroy(cr);
    cairo_surface_destroy(surface);
    return 0;
}