Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <string>
  4. #include <conio.h>
  5.  
  6. #define UP 1
  7. #define LEFT 2
  8. #define DOWN 3
  9. #define RIGHT 4
  10.  
  11. using namespace std;
  12.  
  13. int lineLn = 1;
  14. int transX = 130;
  15. int transY = 700;
  16.  
  17. void rotates(int &direction,int rotation){
  18. if(rotation == RIGHT){
  19. if(direction==UP){
  20. direction = RIGHT;
  21. return ;
  22. }
  23. direction --;
  24. }
  25. else if(rotation == LEFT){
  26. if(direction==RIGHT) {
  27. direction = UP;
  28. return;
  29. }
  30. direction++;
  31. }
  32. }
  33.  
  34. struct Point {
  35. int x,y;
  36. Point(int ix,int iy)
  37. {
  38. x = ix;
  39. y = iy;
  40. }
  41. };
  42.  
  43. void apply(Point &p,int direction){
  44. if(direction==UP)
  45. p.y--;
  46. if(direction==DOWN)
  47. p.y++;
  48. if(direction==LEFT)
  49. p.x--;
  50. if(direction==RIGHT)
  51. p.x++;
  52. }
  53.  
  54. void lines(Point a,Point b){
  55. line(a.x*lineLn+transX,a.y*lineLn+transY,b.x*lineLn+transX,b.y*lineLn+transY);
  56. }
  57.  
  58. Point currentPos(0,0);
  59. int rotation = RIGHT;
  60. void runProgram(std::string program)
  61. {
  62. for(int i=0;i<program.size();i++)
  63. {
  64. if(program[i]=='F'){
  65. Point p = currentPos;
  66. apply(currentPos,rotation);
  67. lines(p,currentPos);
  68. }if(program[i]=='R')
  69. rotates(rotation,RIGHT);
  70. if(program[i]=='L')
  71. rotates(rotation,LEFT);
  72. }
  73. }
  74.  
  75. std::string nextProgram(std::string program)
  76. {
  77. return program+"L"+program+"R";
  78. }
  79.  
  80.  
  81. int main()
  82. {
  83. initwindow(900,950,"Robotel",100,0);
  84. std::string init = "F";
  85. for(int i=0;i<18;i++)
  86. init = nextProgram(init);
  87. cout<<init.size();
  88. runProgram(init);
  89. _getch();
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement