Advertisement
TeslaCoilGirl

C++ SVG

Dec 12th, 2020
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include "svgCreate.c"
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int tetriminoPattern[20][10] =
  7.                                 {
  8.                                     {7,0,0,0,0,0,0,0,0,0}, //20
  9.                                     {7,7,0,0,0,0,0,0,0,0}, //19
  10.                                     {7,0,0,0,0,0,0,0,0,0}, //18
  11.                                     {0,0,1,1,0,0,0,0,0,0}, //17
  12.                                     {0,0,0,1,1,0,0,0,0,0}, //16
  13.                                     {6,6,0,7,5,5,5,5,2,2}, //15
  14.                                     {6,0,0,7,7,5,5,5,5,2}, //14
  15.                                     {6,1,0,7,4,4,7,6,6,2}, //13
  16.                                     {1,1,0,4,4,7,7,6,2,2}, //12
  17.                                     {1,0,0,4,1,1,7,6,5,2}, //11
  18.                                     {3,3,0,4,4,1,1,2,5,2}, //10
  19.                                     {3,3,0,6,4,2,2,2,5,6}, //09
  20.                                     {4,0,0,6,6,6,3,3,5,6}, //08
  21.                                     {4,4,0,7,1,1,3,3,6,6}, //07
  22.                                     {2,4,0,7,7,1,1,7,7,7}, //06
  23.                                     {2,0,0,7,1,5,3,3,7,5}, //05
  24.                                     {2,2,0,1,1,5,3,3,5,5}, //04
  25.                                     {6,6,0,1,1,5,3,3,5,5}, //03
  26.                                     {6,0,0,1,1,5,3,3,5,5}, //02
  27.                                     {6,7,0,1,4,4,4,4,5,2}  //01
  28.                                 };
  29.  
  30.  
  31. class TetraBlock {
  32.  
  33. public:
  34.     int blockColor;
  35.  
  36.     TetraBlock(){
  37.         blockColor = 0;
  38.     }
  39.  
  40.     TetraBlock(int _blockColor){
  41.         blockColor = _blockColor;
  42.     }
  43.  
  44.     void writeSVG(FILE* fp, std::string fileName, int x, int y){
  45.  
  46.         switch(blockColor){
  47.  
  48.             case 0:
  49.                 createBlock(fp, x, y, 0, 0, 0);
  50.                 break;
  51.             case 1:
  52.                 createBlock(fp, x, y, 255, 0, 0);
  53.                 break;
  54.             case 2:
  55.                 createBlock(fp, x, y, 255, 127, 0);
  56.                 break;
  57.             case 3:
  58.                 createBlock(fp, x, y, 255,255,0);
  59.                 break;
  60.             case 4:
  61.                 createBlock(fp, x, y, 0, 255, 0);
  62.                 break;
  63.             case 5:
  64.                 createBlock(fp, x, y, 0, 255, 255);
  65.                 break;
  66.             case 6:
  67.                 createBlock(fp, x, y, 0, 0, 255);
  68.                 break;
  69.             case 7:
  70.                 createBlock(fp, x, y, 255, 0, 255);
  71.                 break;
  72.             }
  73.  
  74.         }
  75.     };
  76.  
  77.  
  78.  
  79. int main()
  80. {
  81.     FILE* fp = fopen("htmlfile.html","w+");
  82.  
  83.     fputs( "<!DOCTYPE html>\n<html>\n<body>\n<svg height = \"1000\" width = \"2000\">\n", fp);
  84.     TetraBlock block[10][20];
  85.  
  86.     for (int i = 0; i < 10; i++){
  87.         for (int j = 0; j < 20; j++){
  88.             block[i][j] = TetraBlock(tetriminoPattern[j][i]);
  89.             block[i][j].writeSVG(fp,"htmlfile.html",i*50,j*50);
  90.         }
  91.  
  92.     }
  93.     fputs("</svg></body>\n</html>\n",fp);
  94.     fclose(fp);
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement