Created
September 11, 2018 05:59
-
-
Save jason790228/e317619903380ed67e22b82c357145aa to your computer and use it in GitHub Desktop.
403
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Board.h" | |
#include "Postscript.h" | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
Postscript::init(); | |
Board jason = Postscript::generate_sticker(Postscript::eFontSize::c5, "JASON"); | |
Board ben = Postscript::generate_sticker(Postscript::eFontSize::c5, "BEN"); | |
Board amy = Postscript::generate_sticker(Postscript::eFontSize::c5, "AMY"); | |
Board jay = Postscript::generate_sticker(Postscript::eFontSize::c5, "JAY"); | |
Board steven = Postscript::generate_sticker(Postscript::eFontSize::c5, "STEVEN"); | |
Board yipo = Postscript::generate_sticker(Postscript::eFontSize::c5, "YIPO"); | |
Board eva = Postscript::generate_sticker(Postscript::eFontSize::c5, "EVA"); | |
Board eric = Postscript::generate_sticker(Postscript::eFontSize::c5, "ERIC"); | |
Board gray = Postscript::generate_sticker(Postscript::eFontSize::c5, "GRAY"); | |
Board derek = Postscript::generate_sticker(Postscript::eFontSize::c5, "DEREK"); | |
Board rice = Postscript::generate_sticker(Postscript::eFontSize::c5, "RICE"); | |
Board ccl = Postscript::generate_sticker(Postscript::eFontSize::c5, "CCL"); | |
Board board(72, 120, '.'); | |
Postscript::stick_l(board, jason, 1); | |
Postscript::stick_r(board, jason, 1); | |
Postscript::stick_c(board, jason, 1); | |
Postscript::stick_l(board, ben, 7); | |
Postscript::stick_r(board, ben, 7); | |
Postscript::stick_c(board, ben, 7); | |
Postscript::stick_l(board, amy, 13); | |
Postscript::stick_r(board, amy, 13); | |
Postscript::stick_c(board, amy, 13); | |
Postscript::stick_l(board, jay, 19); | |
Postscript::stick_r(board, jay, 19); | |
Postscript::stick_c(board, jay, 19); | |
Postscript::stick_l(board, steven, 25); | |
Postscript::stick_r(board, steven, 25); | |
Postscript::stick_c(board, steven, 25); | |
Postscript::stick_l(board, yipo, 31); | |
Postscript::stick_r(board, yipo, 31); | |
Postscript::stick_c(board, yipo, 31); | |
Postscript::stick_l(board, eva, 37); | |
Postscript::stick_r(board, eva, 37); | |
Postscript::stick_c(board, eva, 37); | |
Postscript::stick_l(board, eric, 43); | |
Postscript::stick_r(board, eric, 43); | |
Postscript::stick_c(board, eric, 43); | |
Postscript::stick_l(board, gray, 49); | |
Postscript::stick_r(board, gray, 49); | |
Postscript::stick_c(board, gray, 49); | |
Postscript::stick_l(board, derek, 55); | |
Postscript::stick_r(board, derek, 55); | |
Postscript::stick_c(board, derek, 55); | |
Postscript::stick_l(board, rice, 61); | |
Postscript::stick_r(board, rice, 61); | |
Postscript::stick_c(board, rice, 61); | |
Postscript::stick_l(board, ccl, 67); | |
Postscript::stick_r(board, ccl, 67); | |
Postscript::stick_c(board, ccl, 67); | |
board.dispaly(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
#include "Matrix.h" | |
class Board | |
{ | |
public: | |
enum eDirection | |
{ | |
LEFT, | |
}; | |
public: | |
Board(size_t height = 0, size_t width = 0, char value = ' ') : m_board(height, width, value) {}; | |
public: | |
const Matrix& data() const { return m_board; } | |
void stick_picture(size_t top, size_t left, const Matrix &matrix) | |
{ | |
if (matrix.col() == 0 || matrix.row() == 0) return; | |
if (is_over_side(top, left, matrix.col(), matrix.row())) return; | |
size_t t2d = top + matrix.row(); | |
size_t l2r = left + matrix.col(); | |
for (size_t i = top; i < t2d; i++) | |
{ | |
for (size_t j = left; j < l2r; j++) | |
{ | |
m_board.set_element(i, j, matrix.at(i - top, j - left)); | |
} | |
} | |
} | |
void dispaly() | |
{ | |
for (size_t i = 0; i < m_board.row(); i++) | |
{ | |
for (size_t j = 0; j < m_board.col(); j++) | |
{ | |
std::cout << m_board.at(i, j); | |
} | |
std::cout << std::endl; | |
} | |
} | |
void append(const Matrix &m, eDirection d = LEFT) | |
{ | |
if (d == LEFT) | |
{ | |
size_t right = m_board.col(); | |
if (m_board.row() >= m.row()) enlarge(0, m.col()); | |
else enlarge(m.row(), m.col()); | |
stick_picture(0, right, m); | |
} | |
} | |
size_t width() const { return m_board.col(); } | |
size_t hieght() const { return m_board.row(); } | |
private: | |
bool is_over_side(size_t top, size_t left, size_t width, size_t hieght) | |
{ | |
if (left + width > m_board.col()) return true; | |
if (top + hieght > m_board.row()) return true; | |
return false; | |
}; | |
void resize(size_t height, size_t width) { m_board.resize(height, width); } | |
void enlarge(size_t height, size_t width) | |
{ | |
m_board.resize(m_board.row() + height, m_board.col() + width); | |
} | |
private: | |
Matrix m_board; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
#include <vector> | |
class Matrix | |
{ | |
public: | |
Matrix() | |
{ | |
} | |
Matrix(size_t row, size_t col, char data = ' ') : m_data(row, std::vector<char>(col, data)) | |
{ | |
} | |
Matrix(size_t row, size_t col, const std::string &data) : m_data(row, std::vector<char>(col, '.')) | |
{ | |
int count(0); | |
for (auto& row : m_data) | |
{ | |
for (auto& item : row) | |
{ | |
item = data[count]; | |
count++; | |
} | |
} | |
} | |
public: | |
size_t row() const { return m_data.size(); } | |
size_t col() const { if (row() == 0) return 0; return m_data[0].size(); } | |
const char& at(size_t r, size_t c) const { return m_data.at(r).at(c); } | |
void set_element(size_t r, size_t c, char value) { m_data[r][c] = value; } | |
void resize(size_t r, size_t c) | |
{ | |
m_data.resize(r); | |
for (auto &d : m_data) d.resize(c); | |
}; | |
private: | |
std::vector<std::vector<char>> m_data; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <map> | |
#include "Matrix.h" | |
#include "Board.h" | |
namespace Postscript | |
{ | |
enum eFontSize | |
{ | |
c1, | |
c5 | |
}; | |
static std::map<char, Matrix> C1; | |
static std::map<char, Matrix> C5; | |
void init() | |
{ | |
C1['A'] = Matrix(1, 1, "A"); | |
C1['B'] = Matrix(1, 1, "B"); | |
C1['C'] = Matrix(1, 1, "C"); | |
C1['D'] = Matrix(1, 1, "D"); | |
C1['E'] = Matrix(1, 1, "E"); | |
C1['F'] = Matrix(1, 1, "F"); | |
C1['G'] = Matrix(1, 1, "G"); | |
C1['H'] = Matrix(1, 1, "H"); | |
C1['I'] = Matrix(1, 1, "I"); | |
C1['J'] = Matrix(1, 1, "J"); | |
C1['K'] = Matrix(1, 1, "K"); | |
C1['L'] = Matrix(1, 1, "L"); | |
C1['M'] = Matrix(1, 1, "M"); | |
C1['N'] = Matrix(1, 1, "N"); | |
C1['O'] = Matrix(1, 1, "O"); | |
C1['P'] = Matrix(1, 1, "P"); | |
C1['Q'] = Matrix(1, 1, "Q"); | |
C1['R'] = Matrix(1, 1, "R"); | |
C1['S'] = Matrix(1, 1, "S"); | |
C1['T'] = Matrix(1, 1, "T"); | |
C1['U'] = Matrix(1, 1, "U"); | |
C1['V'] = Matrix(1, 1, "V"); | |
C1['W'] = Matrix(1, 1, "W"); | |
C1['X'] = Matrix(1, 1, "X"); | |
C1['Y'] = Matrix(1, 1, "Y"); | |
C1['Z'] = Matrix(1, 1, "Z"); | |
C5['A'] = Matrix(5, 6, ".***..*...*.*****.*...*.*...*."); | |
C5['B'] = Matrix(5, 6, "****..*...*.****..*...*.****.."); | |
C5['C'] = Matrix(5, 6, ".****.*...*.*.....*......****."); | |
C5['D'] = Matrix(5, 6, "****..*...*.*...*.*...*.****.."); | |
C5['E'] = Matrix(5, 6, "*****.*.....***...*.....*****."); | |
C5['F'] = Matrix(5, 6, "*****.*.....***...*.....*....."); | |
C5['G'] = Matrix(5, 6, ".****.*.....*..**.*...*..***.."); | |
C5['H'] = Matrix(5, 6, "*...*.*...*.*****.*...*.*...*."); | |
C5['I'] = Matrix(5, 6, "*****...*.....*.....*...*****."); | |
C5['J'] = Matrix(5, 6, "..***....*.....*..*..*...**..."); | |
C5['K'] = Matrix(5, 6, "*...*.*..*..***...*..*..*...*."); | |
C5['L'] = Matrix(5, 6, "*.....*.....*.....*.....*****."); | |
C5['M'] = Matrix(5, 6, "*...*.**.**.*.*.*.*...*.*...*."); | |
C5['N'] = Matrix(5, 6, "*...*.**..*.*.*.*.*..**.*...*."); | |
C5['O'] = Matrix(5, 6, ".***..*...*.*...*.*...*..***.."); | |
C5['P'] = Matrix(5, 6, "****..*...*.****..*.....*....."); | |
C5['Q'] = Matrix(5, 6, ".***..*...*.*...*.*..**..****."); | |
C5['R'] = Matrix(5, 6, "****..*...*.****..*..*..*...*."); | |
C5['S'] = Matrix(5, 6, ".****.*......***......*.****.."); | |
C5['T'] = Matrix(5, 6, "*****.*.*.*...*.....*....***.."); | |
C5['U'] = Matrix(5, 6, "*...*.*...*.*...*.*...*..***.."); | |
C5['V'] = Matrix(5, 6, "*...*.*...*..*.*...*.*....*..."); | |
C5['W'] = Matrix(5, 6, "*...*.*...*.*.*.*.**.**.*...*."); | |
C5['X'] = Matrix(5, 6, "*...*..*.*....*....*.*..*...*."); | |
C5['Y'] = Matrix(5, 6, "*...*..*.*....*.....*.....*..."); | |
C5['Z'] = Matrix(5, 6, "*****....*....*....*....*****."); | |
} | |
Board generate_sticker(eFontSize fs, std::string s) | |
{ | |
Board sticker; | |
if (fs == c1) | |
{ | |
for (size_t i = 0; i < s.length(); i++) | |
{ | |
sticker.append(C1[s[i]]); | |
} | |
} | |
else if (fs == c5) | |
{ | |
for (size_t i = 0; i < s.length(); i++) | |
{ | |
sticker.append(C5[s[i]]); | |
} | |
} | |
return sticker; | |
} | |
void stick_p(Board& b, const Board& sticker, size_t top, size_t left) | |
{ | |
b.stick_picture(top - 1, left - 1, sticker.data()); | |
} | |
void stick_l(Board& b, const Board& sticker, size_t top) | |
{ | |
size_t left = 1; | |
b.stick_picture(top - 1, left - 1, sticker.data()); | |
} | |
void stick_r(Board& b, const Board& sticker, size_t top) | |
{ | |
size_t left = b.width() - sticker.width(); | |
b.stick_picture(top - 1, left, sticker.data()); | |
} | |
void stick_c(Board& b, const Board& sticker, size_t top) | |
{ | |
size_t left = b.width()/2 - sticker.width()/2; | |
b.stick_picture(top - 1, left - 1, sticker.data()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment