Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include "turtle.hh"
  2.  
  3. #include <cmath>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. Point Point::polar(double angle, double distance) {
  10. double radians = angle * M_PI /180.0;
  11.  
  12. double x = distance*cos(radians);
  13. double y = distance*sin(radians);
  14. return Point(x, y);
  15. }
  16.  
  17. Point Point::cartesian(double x, double y) {
  18. return Point(x, y);
  19. }
  20.  
  21. Point operator+(const Point& p1, const Point& p2) {
  22. Point r(p1);
  23. r+=p2;
  24. return r;
  25. }
  26.  
  27. Point operator-(const Point& p1, const Point& p2) {
  28. Point r(p1);
  29. r-=p2;
  30. return r;
  31. }
  32.  
  33. ostream& operator<<(ostream& out, const Point& p) {
  34. out << p.get_x() << " " << p.get_y();
  35. return out;
  36. }
  37.  
  38. std::ostream& operator<<(std::ostream& out, const Color& c) {
  39. out << c.red() << ' ' << c.green() << ' ' << c.blue() << ' ' << "setrgbcolor" << endl;
  40. return out;
  41. }
  42.  
  43. void PSTurtle::setup() {
  44.  
  45. out_ << "%!PS-Adobe-3.0 EPSF-3.0" << endl;
  46. out_ << "%%Creator: turtle" << endl;
  47. out_ << "%%DocumentData: Clean7Bit" << endl;
  48. out_ << "%%BoundingBox: 0 0 "
  49. << get_width() << " "
  50. << get_height() << endl;
  51. out_ << "%%Pages: 1" << endl;
  52. out_ << "%%Page: 1 1" << endl;
  53.  
  54. out_ << "newpath" << endl;
  55. out_ << get_pos() << " moveto" << endl;
  56.  
  57. }
  58.  
  59. PSTurtle::~PSTurtle() {
  60.  
  61. out_ << "stroke" << endl;
  62. out_ << "%%EOF" << endl;
  63. }
  64.  
  65. Turtle& PSTurtle::pencolor(const Color& c) {
  66. out_ << c;
  67. Turtle::pencolor(c);
  68. return *this;
  69. }
  70.  
  71. Turtle& PSTurtle::moveto(const Point& next_pos) {
  72. out_ << next_pos << " ";
  73. if(is_pendown()) {
  74. out_ << "lineto";
  75. } else {
  76. out_ << "moveto";
  77. }
  78. out_ << endl;
  79. Turtle::moveto(next_pos);
  80. return *this;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement