STColor4ub interpolatedColor(STPoint2 point, STImage *image) { point.x = fmax(0, fmin(point.x, image->GetWidth()-1)); point.y = fmax(0, fmin(point.y, image->GetHeight()-1)); if (point.x == floor(point.x) && point.y == floor(point.y)) return image->GetPixel(point.x, point.y); STPoint2 point1 = STPoint2(floor(point.x), floor(point.y)); STPoint2 point2 = STPoint2(floor(point.x), ceil(point.y)); STPoint2 point3 = STPoint2(ceil(point.x), ceil(point.y)); STPoint2 point4 = STPoint2(ceil(point.x), floor(point.y)); float weight1 = calculateColorWeight(point, point3); float weight2 = calculateColorWeight(point, point4); float weight3 = calculateColorWeight(point, point1); float weight4 = calculateColorWeight(point, point2); STColor4f color1 = STColor4f(image->GetPixel(point1.x, point1.y)) * weight1; STColor4f color2 = STColor4f(image->GetPixel(point2.x, point2.y)) * weight2; STColor4f color3 = STColor4f(image->GetPixel(point3.x, point3.y)) * weight3; STColor4f color4 = STColor4f(image->GetPixel(point4.x, point4.y)) * weight4; STColor4f colorTotal = color1 + color2 + color3 + color4; // colorTotal.a = 1; return STColor4ub(colorTotal); }
// position: (x,y), relative midi note: mapped_midi_num, speed s, max_connection_time: t Note::Note(float x, float y, float z, int mapped_midi_num, float s, int t) { color = STColor4f((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,1.0); centerPosition = STPoint3(x,y,z); printf("centerPosition.x = %f, centerPosition.y = %f\n", centerPosition.x, centerPosition.y); radius = .2; width_max = (10 * radius) / .2; excitement = 0.0; speed = s; max_connection_time = t; mapped_midi = mapped_midi_num; Spelling my_spell = SpellNote(mapped_midi_num); note_space = my_spell.staff_offset; accidental = my_spell.accidental; max_connections = 50; connection_list.resize(max_connections); rel_space = note_space; // for notes with ledger lines if (note_space > 5) { rel_space = 4 + (note_space%2); } if (note_space < -5) { rel_space = -4 + (note_space%2); } }
/** * Compute a linear blend of the pixel colors in two provided images according * to a parameter t. */ STImage *BlendImages(STImage *image1, STImage *image2, float t) { int width = image1->GetWidth(); int height = image1->GetHeight(); STImage *result = new STImage(width, height, STColor4ub(255,255,255,255)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { STColor4f pixel1 = STColor4f(image1->GetPixel(x, y)); STColor4f pixel2 = STColor4f(image2->GetPixel(x, y)); STColor4f newPixel = pixel1*(1-t) + pixel2*t; result->SetPixel(x, y, STColor4ub(newPixel)); } } return result; }
// // Display the label to the current OpenGL context. // void UILabel::Display() { /** CS 148 TODO: * * You must implement the display logic for your label widget. * Look at the STFont class for ideas of how to do this. * * You should render your label based on the rectangle * of the widget, but you do not need to "cut off" any * text that extends outside this rectangle. */ glPushMatrix(); glTranslatef(GetRectangle().pMin.x, GetRectangle().pMin.y - mFont->GetDescender(), 0); mFont->DrawString(mText, STColor4f(0, 1)); glPopMatrix(); }
/* Component-wise log. Applies to color components only. */ STColor4f STColor4f::Log() const { STColor3f rgb(*this); return STColor4f(rgb.Log(), a); }
/* Component-wise exponential. Applies to color components only. */ STColor4f STColor4f::Exp() const { STColor3f rgb(*this); return STColor4f(rgb.Exp(), a); }