Advertisement
Guest User

Lab

a guest
Dec 5th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. // Dalton Dove - CSE20311 - lab11
  2. // 12/02/2019
  3. // This program displays shapes at the mouse cursor depending on input
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7. using namespace std;
  8. #include "gfx.h"
  9.  
  10. void drawSquare(int);
  11. void drawCircle(int);
  12. void drawTriangle(int);
  13. void drawPolygon(int, int);
  14.  
  15. int main()
  16. {
  17. int wd = 500;
  18. int ht = 400;
  19. int SIZE = 50;
  20. bool loop = true;
  21. int val = 0;
  22. int sides;
  23.  
  24.  
  25. gfx_open(wd, ht, "Symbol");
  26.  
  27. while(loop == true){
  28. val = (int)gfx_wait();
  29.  
  30. if(val == 1){
  31. drawSquare(SIZE);
  32. }
  33. else if(val == 99){
  34. drawCircle(SIZE);
  35. }
  36. else if(val == 116){
  37. drawTriangle(SIZE);
  38. }
  39. else if(val > 50 && val < 58){
  40. sides = val - 48;
  41. drawPolygon(SIZE, sides);
  42. }
  43. else if(val == 27){
  44. gfx_clear();
  45. }
  46. else if(val == 113){
  47. loop = false;
  48. }
  49. }
  50. return 0;
  51. }
  52.  
  53. void drawSquare(int SIZE)
  54. {
  55. int xm = gfx_xpos();
  56. int ym = gfx_ypos();
  57. gfx_color(0, 0, 255);
  58. // Right Side Square
  59. gfx_line(xm+SIZE/2, ym+SIZE/2, xm+SIZE/2, ym-SIZE/2);
  60. // Left Side Square
  61. gfx_line(xm-SIZE/2, ym+SIZE/2, xm-SIZE/2, ym-SIZE/2);
  62. // Top Side Square
  63. gfx_line(xm+SIZE/2, ym+SIZE/2, xm-SIZE/2, ym+SIZE/2);
  64. // Bottom Side Square
  65. gfx_line(xm+SIZE/2, ym-SIZE/2, xm-SIZE/2, ym-SIZE/2);
  66. }
  67.  
  68. void drawCircle(int SIZE)
  69. {
  70. int xm = gfx_xpos();
  71. int ym = gfx_ypos();
  72. gfx_color(255, 255, 255);
  73. gfx_circle(xm, ym, SIZE/2);
  74. }
  75.  
  76. void drawTriangle(int SIZE)
  77. {
  78. int xm = gfx_xpos();
  79. int ym = gfx_ypos();
  80. gfx_color(0, 255, 0);
  81. // Top Side Triangle
  82. gfx_line(xm+SIZE/2, ym-SIZE/2, xm-SIZE/2, ym-SIZE/2);
  83. // Right Side Triangle
  84. gfx_line(xm+SIZE/2, ym-SIZE/2, xm, ym+SIZE/2);
  85. // Left Side Triangle
  86. gfx_line(xm-SIZE/2, ym-SIZE/2, xm, ym+SIZE/2);
  87.  
  88. }
  89.  
  90. void drawPolygon(int SIZE, int sides)
  91. {
  92. double pi = 3.1415926535897;
  93. int xm = gfx_xpos();
  94. int ym = gfx_ypos();
  95. gfx_color(128, 0, 128);
  96. int radius = SIZE/2;
  97.  
  98. for(int i = 0; i < sides; i++){
  99. gfx_line(radius * cos((2 * pi * i)/sides) + xm, radius * sin((2 * pi * i)/sides) + ym, radius * cos((2 * pi * (i+1))/sides) + xm, radius * sin((2 * pi * (i+1))/sides) + ym);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement