Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Dalton Dove - CSE20311 - lab11
- // 12/02/2019
- // This program displays shapes at the mouse cursor depending on input
- #include <iostream>
- #include <cmath>
- using namespace std;
- #include "gfx.h"
- void drawSquare(int);
- void drawCircle(int);
- void drawTriangle(int);
- void drawPolygon(int, int);
- int main()
- {
- int wd = 500;
- int ht = 400;
- int SIZE = 50;
- bool loop = true;
- int val = 0;
- int sides;
- gfx_open(wd, ht, "Symbol");
- while(loop == true){
- val = (int)gfx_wait();
- if(val == 1){
- drawSquare(SIZE);
- }
- else if(val == 99){
- drawCircle(SIZE);
- }
- else if(val == 116){
- drawTriangle(SIZE);
- }
- else if(val > 50 && val < 58){
- sides = val - 48;
- drawPolygon(SIZE, sides);
- }
- else if(val == 27){
- gfx_clear();
- }
- else if(val == 113){
- loop = false;
- }
- }
- return 0;
- }
- void drawSquare(int SIZE)
- {
- int xm = gfx_xpos();
- int ym = gfx_ypos();
- gfx_color(0, 0, 255);
- // Right Side Square
- gfx_line(xm+SIZE/2, ym+SIZE/2, xm+SIZE/2, ym-SIZE/2);
- // Left Side Square
- gfx_line(xm-SIZE/2, ym+SIZE/2, xm-SIZE/2, ym-SIZE/2);
- // Top Side Square
- gfx_line(xm+SIZE/2, ym+SIZE/2, xm-SIZE/2, ym+SIZE/2);
- // Bottom Side Square
- gfx_line(xm+SIZE/2, ym-SIZE/2, xm-SIZE/2, ym-SIZE/2);
- }
- void drawCircle(int SIZE)
- {
- int xm = gfx_xpos();
- int ym = gfx_ypos();
- gfx_color(255, 255, 255);
- gfx_circle(xm, ym, SIZE/2);
- }
- void drawTriangle(int SIZE)
- {
- int xm = gfx_xpos();
- int ym = gfx_ypos();
- gfx_color(0, 255, 0);
- // Top Side Triangle
- gfx_line(xm+SIZE/2, ym-SIZE/2, xm-SIZE/2, ym-SIZE/2);
- // Right Side Triangle
- gfx_line(xm+SIZE/2, ym-SIZE/2, xm, ym+SIZE/2);
- // Left Side Triangle
- gfx_line(xm-SIZE/2, ym-SIZE/2, xm, ym+SIZE/2);
- }
- void drawPolygon(int SIZE, int sides)
- {
- double pi = 3.1415926535897;
- int xm = gfx_xpos();
- int ym = gfx_ypos();
- gfx_color(128, 0, 128);
- int radius = SIZE/2;
- for(int i = 0; i < sides; i++){
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement