Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cpp
- #include "Image.h"
- #include "image.cpp"
- #include <cstring>
- #include "SandPile.h"
- #include "SandPile.cpp"
- struct Arguments{
- int length;
- int width;
- char *input_filepath;
- char *output_filepath;
- uint32_t iterations = 0;
- uint32_t frequency;
- };
- void Output(int length, int width, SandPile ModelOutput){
- Image image(width, length);
- std::cout << ModelOutput.sanding.size() << std::endl;
- for(int i = 0; i < length; i++){
- for (int j = 0; j < width; j++){
- if (ModelOutput.sanding[i][j] == 0){
- image.SetColor(Color(255, 255, 255), i, j);
- }
- if (ModelOutput.sanding[i][j] == 1){
- image.SetColor(Color(0, 255, 0), i, j);
- }
- if (ModelOutput.sanding[i][j] == 2){
- image.SetColor(Color(255, 0, 255), i, j);
- }
- if (ModelOutput.sanding[i][j] == 3){
- image.SetColor(Color(255, 255, 0), i, j);
- }
- if (ModelOutput.sanding[i][j] > 3){
- image.SetColor(Color(0, 0, 0), i, j);
- }
- }
- }
- image.Export("image.bmp");
- std::cout<<"file created\n";
- }
- void TSVParse(char* path, SandPile& SandCoords){
- std::ifstream infile(path);
- int buf;
- int iter = 0;
- int x;
- int y;
- int val;
- while(infile >> buf) {
- if (iter % 3 == 0) {
- x = buf;
- }
- else if (iter % 3 == 1) {
- y = buf;
- }
- else {
- val = buf;
- SandCoords.sanding[x][y] = val;
- }
- iter++;
- }
- }
- int main(int argc, char* argv[]) {
- Arguments args;
- for (int k = 1; k < argc; k++) {
- std::string opts = argv[k];
- if (strcmp(argv[k], "-l") == 0 || strcmp(argv[k], "--length") == 0) {
- args.length = std::stoi(argv[k + 1]);
- }
- if (strcmp(argv[k], "-w") == 0 || strcmp(argv[k], "--width") == 0) {
- args.width = std::stoi(argv[k + 1]);
- }
- if (strcmp(argv[k], "-i") == 0 || strcmp(argv[k], "--input") == 0) {
- args.input_filepath = argv[k + 1];
- }
- if (strcmp(argv[k], "-o") == 0 || strcmp(argv[k], "--output") == 0) {
- args.output_filepath = argv[k + 1];
- }
- if (strcmp(argv[k], "-m") == 0 || strcmp(argv[k], "--max-iter") == 0) {
- args.iterations = std::stoi(argv[k + 1]);
- }
- if (strcmp(argv[k], "-f") == 0 || strcmp(argv[k], "--freq") == 0) {
- args.frequency = std::stoi(argv[k + 1]);
- }
- }
- SandPile Making_Scenes(args.length, args. width);
- TSVParse(args.input_filepath, Making_Scenes);
- for(int i = 0; i < args.iterations; i++){
- Making_Scenes.Piling();
- Output(args.length, args.width, Making_Scenes);
- };
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- SandPile.h
- #include <iostream>
- #include <vector>
- #include <string>
- #include <fstream>
- #ifndef LABWORK3__SANDPILE_H_
- #define LABWORK3__SANDPILE_H_
- class SandPile {
- int length_sanding;
- int width_sanding;
- public:
- std::vector<std::vector<int>> sanding;
- SandPile();
- SandPile(int length_sanding, int width_sanding);
- ~SandPile();
- friend void TSVParse(char* path, SandPile& SandCoords);
- void Piling();
- void PrintPile();
- };
- #endif //LABWORK3__SANDPILE_H_
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Sandpile.cpp
- #include "SandPile.h"
- SandPile::SandPile() {
- }
- SandPile::SandPile(int length_sanding, int width_sanding) {
- std::vector<std::vector<int>> sanding;
- this->length_sanding= length_sanding;
- this-> width_sanding = width_sanding;
- sanding.resize(length_sanding);
- for(int i = 0; i < length_sanding; ++i) {
- sanding[i].resize(width_sanding);
- }
- for (int i = 0; i < sanding.size(); i++){
- for(int j = 0; j < sanding[i].size(); j++){
- int a(0);
- sanding[i][j] = a;
- }
- }
- }
- SandPile::~SandPile() {}
- void SandPile::Piling() {
- for (int i = 0; i < sanding.size(); i++) {
- for (int j = 0; j < sanding[i].size(); j++) {
- if (sanding[i][j] > 3) {
- if (i + 1 < sanding.size()) {
- sanding[i + 1][j] += 1;
- }
- if (j + 1 < sanding[i].size()) {
- sanding[i][j + 1] += 1;
- }
- if (i + 1 > 0) {
- sanding[i - 1][j] += 1;
- }
- if (i - 1 > 0) {
- sanding[i + 1][j] += 1;
- }
- sanding[i][j] -= 4;
- }
- }
- }
- }
- void SandPile::PrintPile() {
- for(int i = 0; i < sanding.size(); i++){
- std::cout << "\n";
- for (int j = 0; j < sanding[i].size(); j++){
- std::cout << sanding[i][j] << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement