Implement custom colors

It's an idea that might save the world and all I'm doing now
is flashing the lightsies.
This commit is contained in:
Marcel Plch 2024-10-25 11:38:25 +02:00
parent 3b6b133001
commit bb532ea5ef
Signed by: dormouse
GPG key ID: 2CA77596BC4BDFFE
3 changed files with 37 additions and 8 deletions

View file

@ -22,6 +22,7 @@ int modelRegistry_register(ModelRegistry *, Model *);
void modelRegistry_free(ModelRegistry *); void modelRegistry_free(ModelRegistry *);
GLfloat * model_applyTransformations(Model *); GLfloat * model_applyTransformations(Model *);
void model_colorFromPosition(Model *); void model_colorFromPosition(Model *);
void model_colorXYZ(Model *, int R, int G, int B);
void model_colorRed(Model *); void model_colorRed(Model *);
void model_colorGreen(Model *); void model_colorGreen(Model *);
void model_colorBlue(Model *); void model_colorBlue(Model *);

View file

@ -127,12 +127,33 @@ model_colorFromPosition(Model *self) {
} }
} }
void model_colorXYZ(Model *self, int R, int G, int B) {
for (int i = 0; i < self->bufsize; i++) {
for (int j = 0; j < 4; j++) {
switch(j) {
case 0:
self->colors[i*3+j] = R;
break;
case 1:
self->colors[i*3+j] = G;
break;
case 2:
self->colors[i*3+j] = B;
break;
default:
continue;
}
}
}
}
void void
model_colorRed(Model *self) { model_colorRed(Model *self) {
for (int i = 0; i < self->bufsize; i++) { for (int i = 0; i < self->bufsize; i++) {
self->colors[i*3] = 1.0f; self->colors[i*3] = 1.0f;
} }
} }
void void
model_colorGreen(Model *self) { model_colorGreen(Model *self) {
for (int i = 0; i < self->bufsize; i++) { for (int i = 0; i < self->bufsize; i++) {

View file

@ -69,23 +69,26 @@ float *
neural_process(Neural_Network *self, float *input) { neural_process(Neural_Network *self, float *input) {
float *retval = NULL; float *retval = NULL;
Neural_Layer *nl = self->layers[0]; Neural_Layer *nl = self->layers[0];
Tensor *neural_vector, *synapse_matrix, *temp_buffer;
retval = malloc(self->layers[self->layer_count-1]->layer_size * sizeof(float));
for (int i = 0; i < self->layers[0]->layer_size; i++) { for (int i = 0; i < self->layers[0]->layer_size; i++) {
nl->neurons[i].value = input[i]; nl->neurons[i].value = input[i];
} }
neural_vector = tensor_new(1, nl->layer_size);
for (int i = 0; i < self->layer_count; i++) { for (int i = 0; i < self->layer_count; i++) {
nl = self->layers[i]; nl = self->layers[i];
float dot_prod = 0; synapse_matrix = tensor_new(nl->layer_size_next, nl->layer_size);
for (int j = 0; j < nl->layer_size; j++) { for (int j = 0; j < nl->layer_size; j++) {
neural_vector->data[j] = nl->neurons[j].value;
for (int k = 0; k < nl->layer_size_next; k++) { for (int k = 0; k < nl->layer_size_next; k++) {
synapse_matrix->data[j*nl->layer_size_next+k] = nl->neurons[j].synapses[k];
}
}
// MATH GOES BRRRRRRRR temp_buffer = tensor_multip(synapse_matrix, neural_vector);
dot_prod += nl->neurons[j].value tensor_free(neural_vector);
* nl->neurons[j].synapses[j]; tensor_free(synapse_matrix);
} neural_vector = temp_buffer;
}
} }
retval = malloc(nl->layer_size * sizeof(float)); retval = malloc(nl->layer_size * sizeof(float));
@ -102,6 +105,7 @@ neural_getMesh(ModelRegistry *mr, Neural_Network *nn) {
for (int j = 0; j < nn->layer_count; j++) { for (int j = 0; j < nn->layer_count; j++) {
Neural_Layer *nl = nn->layers[j]; Neural_Layer *nl = nn->layers[j];
for (int i = 0; i < nl->layer_size; i++) { for (int i = 0; i < nl->layer_size; i++) {
unsigned int brightness;
for (int k = 0; k < nl->layer_size_next; k++) { for (int k = 0; k < nl->layer_size_next; k++) {
model = model_line((-.90) model = model_line((-.90)
+ ((GLfloat)2 * i * .90/(nl->layer_size-1)), + ((GLfloat)2 * i * .90/(nl->layer_size-1)),
@ -115,10 +119,14 @@ neural_getMesh(ModelRegistry *mr, Neural_Network *nn) {
.001 // girth .001 // girth
); );
brightness = nl->neurons[i].synapses[k] <= 1.0 ? nl->neurons[i].synapses[k] : 255;
model_colorXYZ(model, brightness, 0, 0);
modelRegistry_register(mr, model); modelRegistry_register(mr, model);
} }
model = model_circle(0, (GLfloat)1/64); model = model_circle(0, (GLfloat)1/64);
brightness = nl->neurons[i].value <= 1.0 ? nl->neurons[i].value : 255;
model_colorXYZ(model, 0, brightness, 0);
Tensor *translation_matrix = tensor_new(4, 4); Tensor *translation_matrix = tensor_new(4, 4);
Tensor *aspectRatio_matrix = tensor_new(4, 4); Tensor *aspectRatio_matrix = tensor_new(4, 4);
aspectRatio_matrix->data[0] = (GLfloat)9/16; aspectRatio_matrix->data[0] = (GLfloat)9/16;
@ -131,7 +139,6 @@ neural_getMesh(ModelRegistry *mr, Neural_Network *nn) {
model->transformations[0] = translation_matrix; model->transformations[0] = translation_matrix;
model->transformations[1] = aspectRatio_matrix; model->transformations[1] = aspectRatio_matrix;
model->transformation_count = 2; model->transformation_count = 2;
model_colorWhite(model);
modelRegistry_register(mr, model); modelRegistry_register(mr, model);