Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Warm - up: Use the shapeFunStart.cpp code in canvas. If you need to review setting up a OpenCV assignment, use the module 1 powerpoint &
Warmup:
Use the shapeFunStart.cpp code in canvas. If you need to review setting up a OpenCV assignment, use the module powerpoint & ShowPicture assignment andor copy your showpicture assignment and edit the code
Simple Turtle like drawing
Start with calling init
changePosition will move the turtle to any location on the screen
is the upper left corner
is bottom right corner
changeDirection will point the turtle in any direction
right, down, left, up
moveForward will move the turtle forward the given number of pixels leaving a line behind.
Code for square given. Add code to draw a triangle turn pentagon turn and star turn
Daily Assignment:
#if or comment out the warmup code
Remove the #if FULLDAILYASSIGNMENT and corresponding #endif statements
Add the Pentagon and Star classes that derive from the shape virtual base class so they work with the given main
Submit your cpp file and a screenshot showing your shapes being drawn. ShapeFun.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include
#include "opencvcorehpp
#include "opencvimgprochpp
#include "opencvhighguihpp
#include
#include
using namespace cv;
using namespace std;
#define MPI
#define degToRadangleInDegreesangleInDegrees MPI
char wndname "TurtleWindow";
Mat image Mat::zeros CVUC;
Scalar WHITE;
const int DELAY ;
Point curPosition;
int direction ;
Must be called in main before any other drawing function
void init
imshowwndname image;
waitKeyDELAY;
Move the pen to the given coordinates without leaving a mark
Note refers to the upper left corner
refers to the bottom right corner
void changePositionint x int y
curPosition.x x;
curPosition.y y;
point in the direction given in degrees
point right
point down
point left
point up
void changeDirectionint direction
direction direction;
Moves the pen forward the given number of pixels
Note leaves a mark creating a line from the previous point
to the new point
void moveForwardint nPixels
int x staticcastroundnPixels cosdegToRaddirection;
int y staticcastroundnPixels sindegToRaddirection;
Point newPoint Pointx curPosition.x y curPosition.y;
lineimagecurPosition, newPoint, WHITE;
curPosition newPoint;
cout "moved to newPoint.x newPoint.y dir:" direction endl;
imshowwndname image;
waitKeyDELAY;
void main
init;
changePosition;
int direction ;
for int i ; i ; i
changeDirectiondirection;
moveForward;
direction ;
waitKey;
#if FULLDAILYASSIGNMENT remove this line for the full daily assignment
class Shape
public:
virtual void Draw;
Shapeint x int y int size
x x;
y y;
size size;
protected:
int x;
int y;
int size;
;
class Square : public Shape
public:
Squareint x int y int size : Shapex y size
virtual void Draw
changePositionxy;
int myDirection ;
changeDirectionmyDirection;
for int i ; i ; i
moveForwardsize;
myDirection ;
changeDirectionmyDirection;
;
Add a Pentagon and a Star classes that inherit from the public shape base class
void drawShapesShape shapeArr
for int i ; i ; i
shapeArriDraw;
int main
init;
Shape myShapes
new Square
new Pentagon
new Star
;
drawShapesmyShapes;
waitKey;
#endif remove this line for the full daily assignment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started