progress on lab 5 part 2

This commit is contained in:
2022-05-03 11:53:11 -05:00
parent e381f5d7ca
commit 780c2bba3c
5 changed files with 192 additions and 15 deletions

BIN
Lab5/Lab5 Executable file

Binary file not shown.

View File

@@ -0,0 +1,78 @@
/**
* @file image.cpp
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief
* @version 1.0
* @date 2022-04-19
*
* @copyright Copyright (c) 2022
*
*/
#include "image.h"
// TODO
Image::Image(){
shapes.clear();
}
// TODO
Image::Image(const Image& from){
for(int i = 0; i < from.shapes.size(); i++){
shapes.push_back(from.shapes[i]->clone());
}
}
// TODO
Image::~Image(){
for(int i = 0; i < shapes.size(); i++){
delete shapes[i];
}
shapes.clear();
}
// TODO
Image &Image::operator=(const Image& rhs){
for(int i = 0; i < shapes.size(); i++){
delete shapes[i];
}
shapes.clear();
for(int i = 0; i < rhs.shapes.size(); i++){
shapes.push_back(rhs.shapes[i]->clone());
}
return *this;
}
// TODO
void Image::add(Shape* shape){
shapes.push_back(shape);
}
// TODO
void Image::draw(GraphicsContext* gc){
for(int i = 0; i < shapes.size(); i++){
shapes[i]->draw(gc);
}
}
// TODO
void Image::out(std::ostream& os){
for(int i = 0; i < shapes.size(); i++){
shapes[i]->out(os);
os << endl;
}
}
// TODO
void Image::in(std::istream& is){
}
// TODO
void Image::erase(){
for(int i = 0; i < shapes.size(); i++){
delete shapes[i];
}
shapes.clear();
}

View File

@@ -0,0 +1,35 @@
#ifndef image_h
#define image_h
/**
* @file image.h
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief
* @version 1.0
* @date 2022-04-19
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream>
#include "shape.h"
#include "x11context.h"
#include <vector>
using namespace std;
class Image{
public:
Image();
Image(const Image& from);
~Image();
Image& operator=(const Image& rhs);
void add(Shape* shape);
void draw(GraphicsContext* gc);
void out(std::ostream& os);
void in(std::istream& is);
void erase();
private:
vector<Shape*> shapes;
};
#endif

View File

@@ -14,25 +14,89 @@
#include "shape.h"
#include "line.h"
#include "triangle.h"
#include "image.h"
using namespace std;
GraphicsContext* gc = new X11Context(800,600,GraphicsContext::BLACK);
void part1Test(){
// Boat
Shape* LT1 = new Line(250,500,550,500,GraphicsContext::YELLOW);
Shape* LT2 = new Line(250,500,150,400,GraphicsContext::YELLOW);
Shape* LT3 = new Line(150,400,650,400,GraphicsContext::YELLOW);
Shape* LT4 = new Line(650,400,550,500,GraphicsContext::YELLOW);
Shape* LT5 = new Line(400,400,400,100,GraphicsContext::YELLOW);
// Sail
Shape* TT1 = new Triangle(400,100,300,150,400,200,GraphicsContext::YELLOW);
// Waves
Shape* LT8 = new Line(0,550,100,450,GraphicsContext::BLUE);
Shape* LT9 = new Line(100,450,100,550,GraphicsContext::BLUE);
Shape* LT10 = new Line(100,550,200,450,GraphicsContext::BLUE);
Shape* LT11 = new Line(200,450,200,550,GraphicsContext::BLUE);
Shape* LT12 = new Line(200,550,300,450,GraphicsContext::BLUE);
Shape* LT13 = new Line(300,450,300,550,GraphicsContext::BLUE);
Shape* LT14 = new Line(300,550,400,450,GraphicsContext::BLUE);
Shape* LT15 = new Line(400,450,400,550,GraphicsContext::BLUE);
Shape* LT16 = new Line(400,550,500,450,GraphicsContext::BLUE);
Shape* LT17 = new Line(500,450,500,550,GraphicsContext::BLUE);
Shape* LT18 = new Line(500,550,600,450,GraphicsContext::BLUE);
Shape* LT19 = new Line(600,450,600,550,GraphicsContext::BLUE);
Shape* LT20 = new Line(600,550,700,450,GraphicsContext::BLUE);
Shape* LT21 = new Line(700,450,700,550,GraphicsContext::BLUE);
Shape* LT22 = new Line(700,550,800,450,GraphicsContext::BLUE);
(*LT1).draw(gc);
(*LT2).draw(gc);
(*LT3).draw(gc);
(*LT4).draw(gc);
(*LT5).draw(gc);
(*TT1).draw(gc);
(*LT8).draw(gc);
(*LT9).draw(gc);
(*LT10).draw(gc);
(*LT11).draw(gc);
(*LT12).draw(gc);
(*LT13).draw(gc);
(*LT14).draw(gc);
(*LT15).draw(gc);
(*LT16).draw(gc);
(*LT17).draw(gc);
(*LT18).draw(gc);
(*LT19).draw(gc);
(*LT20).draw(gc);
(*LT21).draw(gc);
(*LT22).draw(gc);
}
void part2Test(){
Image image1;
for(int i = 0; i < 10; i++){
image1.add(new Line(rand()%800,rand()%600,rand()%800,rand()%600,rand()));
}
for(int i = 0; i < 10; i++){
image1.add(new Triangle(rand()%800,rand()%600,rand()%800,rand()%600,rand()%800,rand()%600,rand()));
}
image1.draw(gc);
}
int main(void)
{
GraphicsContext* gc = new X11Context(800,600,GraphicsContext::BLACK);
Shape* L1 = new Line(200, 150, 200, 300, GraphicsContext::GREEN);
Shape* T1 = new Triangle(250, 100, 50, 320, 125, 200, GraphicsContext::RED);
Shape* L2 = L1->clone();
Shape* T2 = T1->clone();
delete L1;
delete T1;
(*L2).draw(gc);
(*T2).draw(gc);
(*L2).out(cout);
(*T2).out(cout);
part1Test();
sleep(5);
gc->clear();
part2Test();
sleep(5);
gc->clear();
sleep(20);
delete gc;
return 0;
}
}

View File

@@ -4,7 +4,7 @@ CC = g++
CFLAGS = -c -MMD -g
LFLAGS = -lX11
# Change w/ every new project
SOURCES = main.cpp gcontext.cpp x11context.cpp row.cpp matrix.cpp shape.cpp line.cpp triangle.cpp
SOURCES = main.cpp gcontext.cpp x11context.cpp row.cpp matrix.cpp shape.cpp line.cpp triangle.cpp image.cpp
OBJECTS = $(SOURCES:.cpp=.o)
# Change w/ every new project
EXECUTABLE = Lab5