/* This file was generated by scramble.py. */
#line 1 "src/stencil.py"
#include "stencil.h"
#line 7
Stencil * stencil_new(int w, int h) {
    Stencil * self;
#line 8
    land_alloc(self);
    self->w = w;
    self->h = h;
    self->mask = land_calloc(w * h * sizeof (* self->mask));
    return self;
}
void stencil_destroy(Stencil * self) {
    land_free(self->mask);
    land_free(self);
}
void stencil_shave(Stencil * self, int f) {
    /* 0
     * 1 2 3
     * 4 5 6
     * 7 8 9
     */
#line 25
    for (int y = 0; y < self->h; y += 1) {
        for (int x = 0; x < self->w; x += 1) {
            float * p = self->mask + x + self->w * y;
            float v2 = 1;
            if (f == 1 || f == 4 || f == 7 || f == 0) {
                float v = x * 1.0 / self->w;
                v *= 10;
                v += 0.5 * sin(y * 2 * LAND_PI / self->h * 4.0);
                if (v > 1) {
#line 33
                    v = 1;
                }
#line 34
                v2 *= v;
            }
#line 35
            if (f == 3 || f == 6 || f == 9 || f == 0) {
                float v = 1.0 - x * 1.0 / self->w;
                v *= 10;
                v += 0.5 * sin(y * 2 * LAND_PI / self->h * 4.0);
                if (v > 1) {
#line 39
                    v = 1;
                }
#line 40
                v2 *= v;
            }
#line 41
            if (f == 7 || f == 8 || f == 9 || f == 0) {
                float v = 1.0 - y * 1.0 / self->h;
                v *= 3;
                v += - 0.5 + 0.5 * pow(sin(x * 2 * LAND_PI / self->w + LAND_PI / 2), 2);
                if (v > 1) {
#line 45
                    v = 1;
                }
#line 46
                v2 *= v;
            }
#line 47
            if (f == 1 || f == 2 || f == 3 || f == 0) {
                float v = y * 1.0 / self->h;
                v *= 20;
                v += 0.2 * sin(x * 2 * LAND_PI / self->w * 4.0);
                if (v > 1) {
#line 51
                    v = 1;
                }
#line 52
                v2 *= v;
            }
#line 53
            if (v2 < 0) {
#line 53
                v2 = 0;
            }
#line 54
            if (v2 > 1) {
#line 54
                v2 = 1;
            }
#line 55
            * p = v2;
        }
    }
}
#line 57
void stencil_zigzag(Stencil * self, int y0, int y1, int n) {
    /* \   \
     * \   \
     * \   \
     * \   \
     * \  /\  /
     * \/  \/
     */
#line 67
    float zw = self->w / n;
    for (int y = 0; y < self->h; y += 1) {
        for (int x = 0; x < self->w; x += 1) {
            float * p = self->mask + x + self->w * y;
            float z = fmod(x, zw);
            if (z > zw / 2) {
                z = zw - z;
            }
#line 74
            int zy = y0 + z * (y1 - y0) * 2 / zw;
            float v = y > zy ? 0 : 1;
            * p = v;
        }
    }
}
/* This file was generated by scramble.py. */
