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:
parent
3b6b133001
commit
bb532ea5ef
3 changed files with 37 additions and 8 deletions
|
@ -22,6 +22,7 @@ int modelRegistry_register(ModelRegistry *, Model *);
|
|||
void modelRegistry_free(ModelRegistry *);
|
||||
GLfloat * model_applyTransformations(Model *);
|
||||
void model_colorFromPosition(Model *);
|
||||
void model_colorXYZ(Model *, int R, int G, int B);
|
||||
void model_colorRed(Model *);
|
||||
void model_colorGreen(Model *);
|
||||
void model_colorBlue(Model *);
|
||||
|
|
21
src/model.c
21
src/model.c
|
@ -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
|
||||
model_colorRed(Model *self) {
|
||||
for (int i = 0; i < self->bufsize; i++) {
|
||||
self->colors[i*3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
model_colorGreen(Model *self) {
|
||||
for (int i = 0; i < self->bufsize; i++) {
|
||||
|
|
23
src/neural.c
23
src/neural.c
|
@ -69,23 +69,26 @@ float *
|
|||
neural_process(Neural_Network *self, float *input) {
|
||||
float *retval = NULL;
|
||||
Neural_Layer *nl = self->layers[0];
|
||||
|
||||
retval = malloc(self->layers[self->layer_count-1]->layer_size * sizeof(float));
|
||||
Tensor *neural_vector, *synapse_matrix, *temp_buffer;
|
||||
|
||||
for (int i = 0; i < self->layers[0]->layer_size; i++) {
|
||||
nl->neurons[i].value = input[i];
|
||||
}
|
||||
neural_vector = tensor_new(1, nl->layer_size);
|
||||
for (int i = 0; i < self->layer_count; 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++) {
|
||||
neural_vector->data[j] = nl->neurons[j].value;
|
||||
for (int k = 0; k < nl->layer_size_next; k++) {
|
||||
|
||||
// MATH GOES BRRRRRRRR
|
||||
dot_prod += nl->neurons[j].value
|
||||
* nl->neurons[j].synapses[j];
|
||||
synapse_matrix->data[j*nl->layer_size_next+k] = nl->neurons[j].synapses[k];
|
||||
}
|
||||
}
|
||||
|
||||
temp_buffer = tensor_multip(synapse_matrix, neural_vector);
|
||||
tensor_free(neural_vector);
|
||||
tensor_free(synapse_matrix);
|
||||
neural_vector = temp_buffer;
|
||||
}
|
||||
|
||||
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++) {
|
||||
Neural_Layer *nl = nn->layers[j];
|
||||
for (int i = 0; i < nl->layer_size; i++) {
|
||||
unsigned int brightness;
|
||||
for (int k = 0; k < nl->layer_size_next; k++) {
|
||||
model = model_line((-.90)
|
||||
+ ((GLfloat)2 * i * .90/(nl->layer_size-1)),
|
||||
|
@ -115,10 +119,14 @@ neural_getMesh(ModelRegistry *mr, Neural_Network *nn) {
|
|||
|
||||
.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);
|
||||
}
|
||||
|
||||
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 *aspectRatio_matrix = tensor_new(4, 4);
|
||||
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[1] = aspectRatio_matrix;
|
||||
model->transformation_count = 2;
|
||||
model_colorWhite(model);
|
||||
|
||||
modelRegistry_register(mr, model);
|
||||
|
||||
|
|
Loading…
Reference in a new issue