Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions exercise/01/color.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "stdafx.h"
#include "color.h"
#include <windows.h> // RGB

color::color(double rn, double gn, double bn )
{
this->_rn = fix_value(rn);
this->_gn = fix_value(gn);
this->_bn = fix_value(bn);
}

color::~color()
{

}

double color::fix_value(double cn)
{
if (cn < 0)
return 0.;
if (cn > 1.)
return 1.;
return cn;
}

double color::get_red() const
{
return this->_rn;
}
double color::get_blue()const
{
return this->_bn;
}

double color::get_green()const
{
return this->_gn;
}

void color::set_red(double cn)
{
this->_rn = fix_value(cn);
}

void color::set_green(double cn)
{
this->_gn = fix_value(cn);
}

void color::set_blue(double cn)
{
this->_bn = fix_value(cn);
}

COLORREF color::get_color_ref()
{
COLORREF r = RGB(_rn * 255, _gn * 255, _bn * 255);
return r;

}

double color::get_luminance()
{
return 0.2126*_rn + 0.7152*_gn + 0.0722*_bn;
}

bool operator==(const color& lhs, const color& rhs)
{
return true;//kod koji usporeduje svaku boju
}
25 changes: 25 additions & 0 deletions exercise/01/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <windows.h> // RGB

class color
{
public:
color(double rn = 0, double gn = 0, double bn = 0);
~color();
double get_red() const;
double get_green() const;
double get_blue() const;
void set_red(double cn);
void set_green(double cn);
void set_blue(double cn);
COLORREF get_color_ref();
double get_luminance();

private:
double fix_value(double rn);
double _rn;
double _gn;
double _bn;
};

bool operator==(const color& lhs, const color& rhs);
3 changes: 2 additions & 1 deletion exercise/01/color_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework {
template<> static std::wstring ToString(const color& c) {
std::wostringstream ss;
ss << c.get_red() << L',' << c.get_green() << L',' << c.get_blue();
return ss.str();
ss << L',';
return ss.str();
}
}}}

Expand Down
Loading