lab 5 part 2 complete

This commit is contained in:
2022-05-10 01:45:01 -05:00
parent 780c2bba3c
commit 6a425d5300
10 changed files with 345 additions and 102 deletions

View File

@@ -10,6 +10,8 @@
*/
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "x11context.h"
#include "shape.h"
#include "line.h"
@@ -19,68 +21,77 @@ using namespace std;
GraphicsContext* gc = new X11Context(800,600,GraphicsContext::BLACK);
vector<Shape*> boatScene;
void part1Test(){
cout << "Part 1 Test" << endl;
// 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);
boatScene.push_back(new Line(250,500,550,500,GraphicsContext::YELLOW));
boatScene.push_back(new Line(250,500,150,400,GraphicsContext::YELLOW));
boatScene.push_back(new Line(150,400,650,400,GraphicsContext::YELLOW));
boatScene.push_back(new Line(650,400,550,500,GraphicsContext::YELLOW));
boatScene.push_back(new Line(400,400,400,100,GraphicsContext::YELLOW));
// Sail
Shape* TT1 = new Triangle(400,100,300,150,400,200,GraphicsContext::YELLOW);
boatScene.push_back(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);
boatScene.push_back(new Line(0,550,100,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(100,450,100,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(100,550,200,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(200,450,200,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(200,550,300,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(300,450,300,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(300,550,400,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(400,450,400,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(400,550,500,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(500,450,500,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(500,550,600,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(600,450,600,550,GraphicsContext::BLUE));
boatScene.push_back(new Line(600,550,700,450,GraphicsContext::BLUE));
boatScene.push_back(new Line(700,450,700,550,GraphicsContext::BLUE));
boatScene.push_back(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);
for(int i = 0; i < boatScene.size(); i++){
boatScene[i]->draw(gc);
}
}
// Run part 1 test first
void part2Test(){
cout << "Part 2 Test" << endl;
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()));
}
Line L1(300,400,400,600,0x00FF00);
image1.add(&L1);
image1.draw(gc);
image1.erase();
sleep(3);
gc->clear();
Image boat;
for(int i = 0; i < boatScene.size(); i++){
boat.add(boatScene[i]);
}
Image boat2(boat);
boat2.draw(gc);
sleep(5);
gc->clear();
sleep(1);
ofstream boatImage;
boatImage.open("boat.txt");
boat.out(boatImage);
boatImage.close();
Image image2;
ifstream imageFile2("boat.txt", ifstream::in);
image2.in(imageFile2);
image2.draw(gc);
boat2.erase();
image2.erase();
boat.erase();
for(int i = 0; i < boatScene.size(); i++){
delete boatScene[i];
}
}
int main(void)
@@ -92,8 +103,7 @@ int main(void)
part2Test();
sleep(5);
gc->clear();
sleep(20);
delete gc;