Using Gui in C++ Draw a rectangle as a Rectangle and as a Polygon . Make the lin
ID: 3818708 • Letter: U
Question
Using Gui in C++
Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polygon yellow and the lines of the Rectangle green.
Draw a 200-by-50 Rectangle and place the text “Hi there!” inside it.
Draw your initials 100 pixels high. Use a thick Line. Draw each initial in a different colour.
Draw a chess board: 8-by-8 alternating yellow and blue squares. [Hint: Use a loop or two! ]
Draw a white 5-mm frame around a rectangle that is three-quarters the height of your screen and two-thirds the width.
Draw a two-dimensional house seen from the front, the way a child would: with a door, two windows, and a roof with a chimney. Feel free to add details; maybe have “smoke” come out of the chimney...
Explanation / Answer
Qn.3.
/**
* Draw your initials 100 pixels high. Use a thick line. Draw each initial
* in a different color.
*/
#include <stdexcept>
#include <FL/Fl_Window.H>
#include "Simple_window.h"
#include "Graph.h"
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
try
{
Point tl(100,100); // top left corner of window
Simple_window win(tl,600,400,"ch12ex03"); // make a simple window
// draw initial 'J'
Line init_J1(Point(100,50),Point(250,50));
init_J1.set_color(Color::red);
init_J1.set_style(Line_style(Line_style::solid,10));
win.attach(init_J1); // connect poly to the window
Line init_J2(Point(175,50),Point(175,175));
init_J2.set_color(Color::red);
init_J2.set_style(Line_style(Line_style::solid,10));
win.attach(init_J2); // connect poly to the window
Open_polyline init_J3;
init_J3.add(Point(175,175));
init_J3.add(Point(155,200));
init_J3.add(Point(120,200));
init_J3.add(Point(100,175));
init_J3.set_color(Color::red);
init_J3.set_style(Line_style(Line_style::solid,10));
win.attach(init_J3); // connect poly to the window
// draw initial 'A'
Open_polyline init_J4;
init_J4.add(Point(300,200));
init_J4.add(Point(350,50));
init_J4.add(Point(400,200));
init_J4.add(Point(382,150));
init_J4.add(Point(320,150));
init_J4.set_color(Color::blue);
init_J4.set_style(Line_style(Line_style::solid,10));
win.attach(init_J4); // connect poly to the window
win.wait_for_button(); // display
}
catch(exception& e) {
cerr <<"exception: " << e.what() << endl;
return 1;
}
catch(...) {
cerr << "Some exception ";
return 2;
}
} // main()
Qn5. Draw a white 5-mm frame around a rectangle that is three-quarters the height of your screen and two-thirds the width.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.