Advertisement
Korotkodul

shape_primitives

Nov 20th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <stdexcept>
  4.  
  5. #include <Graph_lib/Graph.h>
  6. #include <Graph_lib/Simple_window.h>
  7.  
  8. using namespace Graph_lib;
  9.  
  10.  
  11.  
  12. int main ()
  13. try
  14. {
  15.   Point t1{100, 100};
  16.  
  17.   Simple_window win{t1, 600, 400, "Canvas"};
  18.   win.wait_for_button();
  19.  
  20.   Axis xa{Axis::x, Point{20, 300}, 280, 10, "x axis"};
  21.   win.attach(xa);
  22.   win.set_label("Canvas #2");
  23.   win.wait_for_button();
  24.  
  25.   Axis ya{Axis::y, Point{20, 300}, 280, 10, "y axis"};
  26.   ya.set_color(Color::cyan);
  27.   ya.label.set_color(Color::dark_red);
  28.   win.attach(ya);
  29.   win.set_label("Canvas #3");
  30.   win.wait_for_button();
  31.  
  32.   Function sine{sin, 0, 100, Point{20, 150}, 1000, 50, 50};
  33.   win.attach(sine);
  34.   win.set_label("Canvas #4");
  35.   win.wait_for_button();
  36.  
  37.   sine.set_color(Color::blue);
  38.  
  39.   Graph_lib::Polygon poly;
  40.   poly.add(Point{300, 200});
  41.   poly.add(Point{350, 100});
  42.   poly.add(Point{400, 200});
  43.  
  44.   poly.set_color(Color::red);
  45.   poly.set_style(Line_style::dash);
  46.   win.attach(poly);
  47.   win.set_label("Canvas #5");
  48.   win.wait_for_button();
  49.  
  50.   Graph_lib::Rectangle r{Point{200, 200}, 100, 50};
  51.   win.attach(r);
  52.   win.set_label("Canvas #6");
  53.   win.wait_for_button();
  54.  
  55.   Closed_polyline poly_rect;
  56.   poly_rect.add(Point{100, 50});
  57.   poly_rect.add(Point{200, 50});
  58.   poly_rect.add(Point{200, 100});
  59.   poly_rect.add(Point{100, 100});
  60.   win.attach(poly_rect);
  61.   win.set_label("Canvas #6.1");
  62.   win.wait_for_button();
  63.  
  64.   poly_rect.add(Point{50, 75});
  65.   win.set_label("Canvas #6.2");
  66.   win.wait_for_button();
  67.  
  68.   r.set_fill_color(Color::yellow);
  69.   poly.set_style(Line_style{Line_style::dash, 4});
  70.   poly_rect.set_style(Line_style{Line_style::dash, 2});
  71.   poly_rect.set_fill_color(Color::green);
  72.   win.set_label("Canvas #7");
  73.   win.wait_for_button();
  74.  
  75.   Text t{Point{150, 150}, "Hello, graphical world!"};
  76.   win.attach(t);
  77.   win.set_label("Canvas #8");
  78.   win.wait_for_button();
  79.  
  80.   t.set_font(Graph_lib::Font::times_bold);
  81.   t.set_font_size(20);
  82.   win.set_label("Canvas #9");
  83.   win.wait_for_button();
  84.  
  85.   Image ii{Point{100, 50}, "around_Dhaulagiri.jpg"};
  86.   win.attach(ii);
  87.   win.set_label("Canvas #10");
  88.   win.wait_for_button();
  89.  
  90.   ii.move(100, 200);
  91.   win.set_label("Canvas #11");
  92.   win.wait_for_button();
  93.  
  94.   Graph_lib::Circle c{Point{100, 200}, 50};
  95.   Graph_lib::Ellipse e{Point{100, 200}, 75, 25};
  96.   e.set_color(Color::dark_red);
  97.   Mark m{Point{100, 200}, 'x'};
  98.  
  99.   std::ostringstream oss;
  100.   oss << "screen size: " << x_max() << "*" << y_max()
  101.       << "; window size: " << win.x_max() << "*" << win.y_max();
  102.   Text sizes{Point{100, 20}, oss.str()};
  103.  
  104.   Image cal{Point{225, 225}, "rafting_Adygeya.jpg"};
  105.   cal.set_mask(Point{100, 300}, 200, 150);
  106.  
  107.   win.attach(c);
  108.   win.attach(m);
  109.   win.attach(e);
  110.  
  111.   win.attach(sizes);
  112.   win.attach(cal);
  113.   win.set_label("Canvas #12");
  114.   win.wait_for_button();
  115. }
  116. catch (std::exception& e)
  117. {
  118.   std::cerr << e.what() << std::endl;
  119.   return 1;
  120. }
  121. catch (...)
  122. {
  123.   std::cerr << "Oops, something went wrong..." << std::endl;
  124.   return 2;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement