RGB color chart [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 13 Exercise 7
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 13 Exercise 7

#define _USE_MATH_DEFINES
#include "Simple_window.h"
#include "Graph.h"
#include <cmath>

using namespace Graph_lib;

/*
template<class T> class Vector_ref {
public:
	void push_back(T&); //add a named object
	void push_back(T*); //add a unnamed object

	T& operator[](int i); //subscripting: read and write access
	const T& operator[](int i) const;

	int size() const;
};
*/

int main()
try
{
	int xcount = 13;
	int ycount = 9;
	int cellSize = 20;

	Point tl(100, 100);
	Simple_window win(tl, 720, 400, "Simple Window");
	
	Vector_ref<Graph_lib::Rectangle> vr;
	
	for (int i = 0; i < 6; ++i) {
		for (int j = 0; j < 6; ++j) {
			for (int k = 0; k < 6; ++k) {
				vr.push_back(new Graph_lib::Rectangle(Point(i * 6 * cellSize + j*cellSize, k*cellSize), cellSize, cellSize));
				vr[vr.size() - 1].set_fill_color(fl_rgb_color(51 * i, 51 * j, 51 * k));
				vr[vr.size() - 1].set_color(Color(Color::black, Color::invisible));
				win.attach(vr[vr.size() - 1]);
			}
		}
	}

	win.wait_for_button();
}
catch (exception& e) {
	cout << e.what() << endl;
	return 1;
}
catch (...) {
	cout << "Exiting" << endl;
	return 2;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.