/* This file was generated by scramble.py. */
#line 1 "src/earth.py"
#include "earth.h"
#line 2
#include "bumpmap.h"
#include "rgba.h"
#line 6
static float lerp(float a, float b, float x) {
    return a * (1 - x) + b * x;
}
static uint8_t * base;
#line 11
static void create_frame(Tile * tile, int i) {
    /* 0
     * 1 2 3
     * 4 5 6
     * 7 8 9
     */
#line 18
    int w = tile->w;
    int h = tile->h;
    memmove(tile->rgba, base, tile->w * tile->h * 4);
#line 22
    if (i == 1 || i == 2 || i == 3 || i == 0) {
        for (int y = 0; y < h; y += 1) {
            for (int x = 0; x < w; x += 1) {
                uint8_t * p = rgba_p(tile->rgba, x, y, w);
                float br = p [0] / 255.0;
                float bg = p [1] / 255.0;
                float bb = p [2] / 255.0;
                float v = y * 1.0 / h;
#line 31
                float l = 1 - v * 5;
                if (l < 0) {
                    l = 0;
                }
#line 34
                l *= 0.2;
                float e = v * 4 - 0.5;
                if (e < 0) {
                    e = 0;
                }
#line 38
                if (e > 1) {
                    e = 1;
                }
#line 40
                rgba_color(lerp(0.1 + l, br, e), lerp(0.5 + l, bg, e), lerp(0, bb, e), p);
            }
        }
        Bumpmap * bumpmap = bumpmap_create(w, h);
        bumpmap_perlin(bumpmap, 2.0, 16.0);
        bumpmap_light(bumpmap);
        Stencil * s = stencil_new(w, h);
        stencil_zigzag(s, 20, 60, 4);
        bumpmap_mul_tile(bumpmap, tile, s, 0.5, 1);
        bumpmap_destroy(bumpmap);
        stencil_destroy(s);
    }
    Stencil * s = stencil_new(w, h);
    stencil_shave(s, i);
    tile_cut(tile, s);
    stencil_destroy(s);
    tile_make(tile);
}
Tile * earth_create(void) {
    int w = 128;
    int h = 128;
    Tile * tile = tile_create("earth", w, h);
#line 63
    base = land_calloc(w * h * 4);
#line 65
    tile_frames(tile, 10);
    tile_frame(tile);
#line 68
    for (int y = 0; y < h; y += 1) {
        for (int x = 0; x < w; x += 1) {
            uint8_t * p = rgba_p(tile->rgba, x, y, w);
            rgba_color(0.5, 0.3, 0.1, p);
        }
    }
#line 73
    Bumpmap * bumpmap = bumpmap_create(w, h);
    bumpmap_voronoi(bumpmap, w / 4, 5);
    bumpmap_outline(bumpmap);
    bumpmap_light(bumpmap);
    bumpmap_mul_tile(bumpmap, tile, NULL, 0.8, 1);
    bumpmap_destroy(bumpmap);
#line 80
    memmove(base, tile->rgba, tile->w * tile->h * 4);
#line 82
    for (int i = 0; i < tile->n; i += 1) {
        tile_frame(tile);
        create_frame(tile, i);
    }
    return tile;
}
/* This file was generated by scramble.py. */
