Rev 2097 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* loom.cc
* DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath
* DIN Is Noise is released under GNU Public License 2.0
* For more information, please visit https://dinisnoise.org/
*/
#include "loom.h"
#include "log.h"
loom::loom () {
cell_size = 50;
seam = 0.9;
half_cell_size = cell_size / 2;
for (int i = 0, j = 1; i < sz; ++i) {
pattern0[i]=pattern[i]=j;
j=!j;
control[i]=1;
}
set_moveable (1);
}
void loom::draw () {
int x0 = posx, y0 = posy, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
for (int i = 0; i < sz; ++i) {
y1 = y0 + half_cell_size;
y2 = y1 + half_cell_size;
if (control[i]) flip_pattern ();
for (int j = 0; j < sz; ++j) {
x1 = x0 + cell_size;
x2 = x1 - half_cell_size;
if (pattern[j] == 0) {
draw_rect (x0, y1, x1, y1, 0, 1, 1, 0); // horizontal
draw_rect (x2, y0, x2, y2, 1, 1, 0, 1); // vertical
} else {
draw_rect (x2, y0, x2, y2, 1, 1, 0, 1); // vertical
draw_rect (x0, y1, x1, y1, 0, 1, 1, 0); // horizontal
}
x0 = x1;
}
y0 = y2;
x0 = posx;
}
int szzs = sz * cell_size;
set_extents (posx, posy, posx + szzs, posy + szzs);
memcpy (pattern, pattern0, sz * sizeof(int));
}
void loom::draw_rect (int x1, int y1, int x2, int y2, float r, float g, float b, int v) {
float w = seam * half_cell_size;
glColor3f (r, g, b);
if (v) {
glRectf (x1 - w, y1, x1 + w, y2);
} else {
glRectf (x1, y1 - w, x2, y1 + w);
}
}
void loom::flip_pattern () { // to get one free pattern
for (int i = 0, p; i < sz; ++i) {
p = pattern[i];
pattern[i]=!p;
}
}