Have you read the PPP and especially that chapter?
No.
Perhaps you could either provide the block of code in question or a link to it, if it is available online.
Thinking logically, you could have a function to draw a coloured square at the required screen coordinates. Then you just need to iterate through a matrix calling the function with the x and y coordinates for where the square is to be drawn, the size of a square side, and colour.
This is the block I should write for that problem;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <Graph.h>
#include <Simple_window.h>
int main()
{
Point t(100,100);
Simple_window win(t, 600,400, "My window");
Graph_lib::Rectangle r1(Point(20,20),20,20);
r1.set_fill_color(Color::red);
win.attach(r1);
win.wait_for_button();
}
//*************************
The code written in line 9 through 11 is for only one square. And for doing the exercise I should repeat that snip code for 64 times! and that was the reason that I thought about a loop.
Thank you "cire",
I haven't learned about #include <deque> or deque<Rect> rectangles ; until now in this book, so I can't use of them. But anyway, I appreciate your answer.
I have a hard time believing you weren't introduced to containers of some sort by the time you hit that point in the book, although I can well believe you weren't introduced to the the deque.
You may treat it almost the same as a vector, although it avoids a problem in this code that a vector would not. (Mainly that a push_back may cause reallocation and therefore relocation of elements so that the address fed to win.attach() is no longer valid.)
I have a hard time believing you weren't introduced to containers of some sort by the time you hit that point in the book
Yeah, I weren't introduced to that facility until now in this book!
When I recalled the vectors I immediately thought about some code like below:
1 2 3 4 5 6 7 8 9 10 11 12 13
int main()
{
Point t(100,100);
Simple_window win(t, 600,400, "My window");
vector<Graph_lib::Rectangle> VR(64);
VR[0].(Point(20,20),20,20);
VR[0].set_fill_color(Color::red);
win.attach(VR[0]);
// some more codes.
win.wait_for_button();
}