Advertisement
D3nX

PixelDraw 1.5a - External command

Jul 19th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.23 KB | None | 0 0
  1. /*
  2. UniBatch Team - 2017
  3. PIXELDRAW 1.5a - By D3nX & Kvc
  4. */
  5. #define _WIN32_WINNT 0x0500
  6. #include <windows.h>
  7. #include <iostream>
  8. #include <sstream>
  9. #include <math.h>
  10.  
  11. using namespace std;
  12.  
  13. //Global variable
  14. #define PI 3.14
  15. COLORREF color = RGB(0,0,0);
  16.  
  17. double getlength_x(int len, int dir)
  18. {
  19.     return cos(dir * PI / 180) * len;
  20. }
  21.  
  22. double getlength_y(int len, int dir)
  23. {
  24.     return sin(dir * PI / 180) * len;
  25. }
  26.  
  27. //Here a function for color
  28. const COLORREF setcolor(string input)
  29. {
  30.     //Set the color
  31.     if (input == "0")
  32.     {
  33.         color = RGB(0,0,0);
  34.     }
  35.         else if (input == "1")
  36.     {
  37.         color = RGB(0,0,128);
  38.     }
  39.         else if (input == "2")
  40.     {
  41.         color = RGB(0,128,0);
  42.     }
  43.         else if (input == "3")
  44.     {
  45.         color = RGB(0,128,128);
  46.     }
  47.         else if (input == "4")
  48.     {
  49.         color = RGB(128,0,0);
  50.     }
  51.         else if (input == "5")
  52.     {
  53.         color = RGB(128,0,128);
  54.     }
  55.     else if (input == "6")
  56.     {
  57.         color = RGB(128,128,0);
  58.     }
  59.     else if (input == "7")
  60.     {
  61.         color = RGB(192,192,192);
  62.     }
  63.     else if (input == "8")
  64.     {
  65.         color = RGB(128,128,128);
  66.     }
  67.     else if (input == "9")
  68.     {
  69.         color = RGB(0,0,255);
  70.     }
  71.     else if (input == "a" || input == "A")
  72.     {
  73.         color = RGB(0,255,0);
  74.     }
  75.     else if (input == "b" || input == "B")
  76.     {
  77.         color = RGB(0,255,255);
  78.     }
  79.     else if (input == "c" || input == "C")
  80.     {
  81.         color = RGB(255,0,0);
  82.     }
  83.     else if (input == "d" || input == "D")
  84.     {
  85.         color = RGB(255,0,255);
  86.     }
  87.         else if (input == "e" || input == "E")
  88.     {
  89.         color = RGB(255,255,0);
  90.     }
  91.     else if (input == "f" || input == "F")
  92.     {
  93.         color = RGB(255,255,255);
  94.     }
  95.  
  96.     //Return the color
  97.     return color;
  98. }
  99.  
  100. int main(int argn, const char *arg[])
  101. {
  102.     HWND console = GetConsoleWindow();
  103.     HDC device = GetDC(console);
  104.  
  105.     if (argn == 1) exit(0);
  106.  
  107.     if (argn == 0)
  108.         system("exit");
  109.  
  110.     string command[argn];
  111.  
  112.     for (int i = 0; i < argn; i++)
  113.     {
  114.         command[i] = arg[i];
  115.     };
  116.  
  117.     if (command[1] == "/p" && (command[4] == "/c" || "/rgb"))
  118.     {
  119.         //set the color
  120.         if (command[4] == "/rgb")
  121.         {
  122.             stringstream ss_r;
  123.             stringstream ss_g;
  124.             stringstream ss_b;
  125.             ss_r << command[5];
  126.             ss_g << command[6];
  127.             ss_b << command[7];
  128.  
  129.             int r;
  130.             int g;
  131.             int b;
  132.             ss_r >> r;
  133.             ss_g >> g;
  134.             ss_b >> b;
  135.  
  136.             color = RGB(r,g,b);
  137.         }
  138.         else if (command[4] == "/c")
  139.         {
  140.             color = setcolor(command[5]);
  141.         }
  142.  
  143.  
  144.         //Convert string to int
  145.         stringstream strValue_a;
  146.         stringstream strValue_b;
  147.         strValue_a << command[2];
  148.         strValue_b << command[3];
  149.  
  150.  
  151.         int x;
  152.         int y;
  153.         strValue_a >> x;
  154.         strValue_b >> y;
  155.  
  156.         //Draw the pixel
  157.         SetPixel(device, x, y, color);
  158.  
  159.         return 0;
  160.     }
  161.     //Line draw
  162.     else if (command[1] == "/dl" && command[4] == "/lh" && (command[6] == "/v" || "/h") && (command[7] == "/c" || "/rgb"))
  163.     {
  164.         //set the color
  165.         if (command[7] == "/rgb")
  166.         {
  167.             stringstream ss_r;
  168.             stringstream ss_g;
  169.             stringstream ss_b;
  170.             ss_r << command[8];
  171.             ss_g << command[9];
  172.             ss_b << command[10];
  173.  
  174.             int r;
  175.             int g;
  176.             int b;
  177.             ss_r >> r;
  178.             ss_g >> g;
  179.             ss_b >> b;
  180.  
  181.             color = RGB(r,g,b);
  182.         }
  183.         else if (command[7] == "/c")
  184.         {
  185.             color = setcolor(command[7]);
  186.         }
  187.  
  188.         //Convert string to int
  189.         stringstream strValue_a;
  190.         stringstream strValue_b;
  191.         stringstream strValue_c;
  192.         strValue_a << command[2];
  193.         strValue_b << command[3];
  194.         strValue_c << command[5];
  195.  
  196.  
  197.         int x;
  198.         int y;
  199.         int h;
  200.         strValue_a >> x;
  201.         strValue_b >> y;
  202.         strValue_c >> h;
  203.  
  204.         //Draw the line of pixel
  205.         if (command[6] == "/v") {
  206.             for (int i = y; i<(y+h); i++)
  207.             {
  208.                 SetPixel(device, x, i, color);
  209.             }
  210.         }
  211.         else if (command[6] == "/h")
  212.         {
  213.             for (int i = x; i<(x+h); i++)
  214.             {
  215.                 SetPixel(device, i, y, color);
  216.             }
  217.         }
  218.  
  219.     }
  220.     //Line point draw
  221.     else if (command[1] == "/dl" && command[2] == "/p" && (command[7] == "/c" || "/rgb"))
  222.     {
  223.         //set the color
  224.         if (command[7] == "/rgb")
  225.         {
  226.             stringstream ss_r;
  227.             stringstream ss_g;
  228.             stringstream ss_b;
  229.             ss_r << command[8];
  230.             ss_g << command[9];
  231.             ss_b << command[10];
  232.  
  233.             int r;
  234.             int g;
  235.             int b;
  236.             ss_r >> r;
  237.             ss_g >> g;
  238.             ss_b >> b;
  239.  
  240.             color = RGB(r,g,b);
  241.         }
  242.         else if (command[7] == "/c")
  243.         {
  244.             color = setcolor(command[8]);
  245.         }
  246.  
  247.         //Convert string to int
  248.         stringstream str_x1;
  249.         stringstream str_y1;
  250.         stringstream str_x2;
  251.         stringstream str_y2;
  252.         str_x1 << command[3];
  253.         str_y1 << command[4];
  254.         str_x2 << command[5];
  255.         str_y2 << command[6];
  256.  
  257.         //And put it in the int
  258.         int x1, x2, y1, y2;
  259.         str_x1 >> x1;
  260.         str_y1 >> y1;
  261.         str_x2 >> x2;
  262.         str_y2 >> y2;
  263.  
  264.         int stepy=1;
  265.         int stepx=1;
  266.  
  267.         int dx = x2 - x1;
  268.         int dy = y2 - y1;
  269.  
  270.         if (dy<0) {
  271.             dy=dy*-1;
  272.             stepy=-1;
  273.         }
  274.  
  275.         if (dx<0) {
  276.             dx=dx*-1;
  277.             stepx=-1;
  278.         }
  279.  
  280.         dy <<= 1;
  281.         dx <<= 1;
  282.  
  283.         int x=x1;
  284.         int y=y1;
  285.  
  286.         if (dx>dy) {
  287.             int fraction=dy-(dx>>1);
  288.  
  289.             // loop variable...
  290.             int i=x1;
  291.  
  292.             while (i!=x2) {
  293.                 SetPixel(device,x,y,color);
  294.                 if (fraction>=0) {
  295.                     y+=stepy;
  296.                     fraction-=dx;
  297.                 }
  298.                 fraction+=dy;
  299.                 x+=stepx;
  300.                 i+=stepx;
  301.             }
  302.  
  303.         } else {
  304.             int fraction=dx-(dy>>1);
  305.  
  306.             // loop variable...
  307.             int i=y1;
  308.  
  309.             while (i!=y2) {
  310.                 SetPixel(device,x,y, color);
  311.                 if (fraction>=0) {
  312.                     x+=stepx;
  313.                     fraction-=dy;
  314.                 }
  315.                 fraction+=dx;
  316.                 y+=stepy;
  317.                 i+=stepy;
  318.             }
  319.         }
  320.  
  321.  
  322.     }
  323.     //Circle draw
  324.     else if (command[1] == "/dc" && command[4] == "/cr" && (command[6] == "/c" || "/rgb"))
  325.     {
  326.         //set the color
  327.         if (command[6] == "/rgb")
  328.         {
  329.             stringstream ss_r;
  330.             stringstream ss_g;
  331.             stringstream ss_b;
  332.             ss_r << command[7];
  333.             ss_g << command[8];
  334.             ss_b << command[9];
  335.  
  336.             int r;
  337.             int g;
  338.             int b;
  339.             ss_r >> r;
  340.             ss_g >> g;
  341.             ss_b >> b;
  342.  
  343.             color = RGB(r,g,b);
  344.         }
  345.         else if (command[6] == "/c")
  346.         {
  347.             color = setcolor(command[7]);
  348.         }
  349.  
  350.  
  351.  
  352.         //Convert string to int
  353.         stringstream strValue_a;
  354.         stringstream strValue_b;
  355.         stringstream strValue_c;
  356.         strValue_a << command[2];
  357.         strValue_b << command[3];
  358.         strValue_c << command[5];
  359.  
  360.  
  361.         int x;
  362.         int y;
  363.         int radius;
  364.         strValue_a >> x;
  365.         strValue_b >> y;
  366.         strValue_c >> radius;
  367.  
  368.         for (unsigned int i = 0; i < 360; i++)
  369.         {
  370.             SetPixel(device, x + getlength_x(radius, i), y + getlength_y(radius, i), color);
  371.         }
  372.  
  373.     }
  374.     //Square draw
  375.     else if (command[1] == "/ds" && command[4] == "/sh" && (command[6] == "/rgb" || "/c"))
  376.     {
  377.         //set the color
  378.         if (command[6] == "/rgb")
  379.         {
  380.             stringstream ss_r;
  381.             stringstream ss_g;
  382.             stringstream ss_b;
  383.             ss_r << command[7];
  384.             ss_g << command[8];
  385.             ss_b << command[9];
  386.  
  387.             int r;
  388.             int g;
  389.             int b;
  390.             ss_r >> r;
  391.             ss_g >> g;
  392.             ss_b >> b;
  393.  
  394.             color = RGB(r,g,b);
  395.         }
  396.         else if (command[6] == "/c")
  397.         {
  398.             color = setcolor(command[7]);
  399.         }
  400.  
  401.  
  402.         //Convert string to int
  403.         stringstream strValue_a;
  404.         stringstream strValue_b;
  405.         stringstream strValue_c;
  406.         strValue_a << command[2];
  407.         strValue_b << command[3];
  408.         strValue_c << command[5];
  409.  
  410.  
  411.         int x;
  412.         int y;
  413.         int h;
  414.         strValue_a >> x;
  415.         strValue_b >> y;
  416.         strValue_c >> h;
  417.         h-=1;
  418.  
  419.         for (unsigned int i=0; i<(h+1); i++)
  420.         {
  421.             SetPixel(device, x, y+i, color);
  422.             SetPixel(device, x+i, y, color);
  423.             SetPixel(device, x+h, y+i, color);
  424.             SetPixel(device, x+i, y+h, color);
  425.         }
  426.  
  427.     }
  428.     //Rectangle draw
  429.     else if (command[1] == "/dr" && command[4] == "/rd" && (command[7] == "/c" || "/rgb"))
  430.     {
  431.         //set the color
  432.         if (command[7] == "/rgb")
  433.         {
  434.             stringstream ss_r;
  435.             stringstream ss_g;
  436.             stringstream ss_b;
  437.             ss_r << command[8];
  438.             ss_g << command[9];
  439.             ss_b << command[10];
  440.  
  441.             int r;
  442.             int g;
  443.             int b;
  444.             ss_r >> r;
  445.             ss_g >> g;
  446.             ss_b >> b;
  447.  
  448.             color = RGB(r,g,b);
  449.         }
  450.         else if (command[7] == "/c")
  451.         {
  452.             color = setcolor(command[8]);
  453.         }
  454.  
  455.         //Convert string to int
  456.         stringstream strValue_a;
  457.         stringstream strValue_b;
  458.         stringstream strValue_c;
  459.         stringstream strValue_d;
  460.         strValue_a << command[2];
  461.         strValue_b << command[3];
  462.         strValue_c << command[5];
  463.         strValue_d << command[6];
  464.  
  465.  
  466.         int x;
  467.         int y;
  468.         int h;
  469.         int w;
  470.         strValue_a >> x;
  471.         strValue_b >> y;
  472.         strValue_c >> h;
  473.         strValue_d >> w;
  474.         h-=1;
  475.         w-=1;
  476.  
  477.         for (unsigned int i = 0; i < (h+1); i++)
  478.         {
  479.             SetPixel(device, x+i, y, color);
  480.             SetPixel(device, x+i, y+w, color);
  481.         }
  482.  
  483.         for (unsigned int i = 0; i < (w+1); i++)
  484.         {
  485.             SetPixel(device, x, y+i, color);
  486.             SetPixel(device, x+h, y+i, color);
  487.         }
  488.  
  489.     }
  490.     //Refresh
  491.     if ((command[1] == "/refresh" || command[1] == "/REFRESH") && argn == 3)
  492.     {
  493.         string color = "color 06 & color 0f & color " + command[2];
  494.         const char* setColor =  color.c_str();
  495.         system(setColor);
  496.     }
  497.     //Triangle draw
  498.     else if (command[1] == "/dt" && command[2] == "/p" && (command[9] == "/c" || "/rgb"))
  499.     {
  500.         //set the color
  501.         if (command[9] == "/rgb")
  502.         {
  503.             stringstream ss_r;
  504.             stringstream ss_g;
  505.             stringstream ss_b;
  506.             ss_r << command[10];
  507.             ss_g << command[11];
  508.             ss_b << command[12];
  509.  
  510.             int r;
  511.             int g;
  512.             int b;
  513.             ss_r >> r;
  514.             ss_g >> g;
  515.             ss_b >> b;
  516.  
  517.             color = RGB(r,g,b);
  518.         }
  519.         else if (command[9] == "/c")
  520.         {
  521.             color = setcolor(command[10]);
  522.         }
  523.  
  524.         //Convert string to int
  525.         stringstream str_x1;
  526.         stringstream str_y1;
  527.         stringstream str_x2;
  528.         stringstream str_y2;
  529.         stringstream str_x3;
  530.         stringstream str_y3;
  531.         str_x1 << command[3];
  532.         str_y1 << command[4];
  533.         str_x2 << command[5];
  534.         str_y2 << command[6];
  535.         str_x3 << command[7];
  536.         str_y3 << command[8];
  537.  
  538.  
  539.         //And put it in the int
  540.         int x1, x2, x3, y1, y2, y3;
  541.         str_x1 >> x1;
  542.         str_y1 >> y1;
  543.         str_x2 >> x2;
  544.         str_y2 >> y2;
  545.         str_x3 >> x3;
  546.         str_y3 >> y3;
  547.  
  548.         /*cout << x1 << " " << x2 << " " << x3 << endl;
  549.         cout << y1 << " " << y2 << " " << y3 << endl;*/
  550.  
  551.         const int x1Bis = x1,
  552.                   y1Bis = y1;
  553.  
  554.         //Get a handle to device context
  555.         for (int e = 0; e < 3; e++) {
  556.  
  557.             if (e == 1)
  558.             {
  559.                 x1 = x2;
  560.                 y1 = y2;
  561.                 x2 = x3;
  562.                 y2 = y3;
  563.             }
  564.  
  565.             if (e == 2)
  566.             {
  567.                 x1 = x3;
  568.                 y1 = y3;
  569.                 x2 = x1Bis;
  570.                 y2 = y1Bis;
  571.             }
  572.  
  573.             int temp;
  574.  
  575.             int stepy=1;
  576.             int stepx=1;
  577.  
  578.             int dx = x2 - x1;
  579.             int dy = y2 - y1;
  580.  
  581.             if (dy<0) {
  582.                 dy=dy*-1;
  583.                 stepy=-1;
  584.             }
  585.  
  586.             if (dx<0) {
  587.                 dx=dx*-1;
  588.                 stepx=-1;
  589.             }
  590.  
  591.             dy <<= 1;
  592.             dx <<= 1;
  593.  
  594.             int x=x1;
  595.             int y=y1;
  596.  
  597.             if (dx>dy) {
  598.                 int fraction=dy-(dx>>1);
  599.  
  600.                 // loop variable...
  601.                 int i=x1;
  602.  
  603.                 while (i!=x2) {
  604.                     SetPixel(device,x,y,color);
  605.                     if (fraction>=0) {
  606.                         y+=stepy;
  607.                         fraction-=dx;
  608.                     }
  609.                     fraction+=dy;
  610.                     x+=stepx;
  611.                     i+=stepx;
  612.                 }
  613.  
  614.             } else {
  615.                 int fraction=dx-(dy>>1);
  616.  
  617.                 // loop variable...
  618.                 int i=y1;
  619.  
  620.                 while (i!=y2) {
  621.                     SetPixel(device,x,y, color);
  622.                     if (fraction>=0) {
  623.                         x+=stepx;
  624.                         fraction-=dy;
  625.                     }
  626.                     fraction+=dx;
  627.                     y+=stepy;
  628.                     i+=stepy;
  629.                 }
  630.             }
  631.         }
  632.  
  633.  
  634.     }
  635.  
  636.     return 0;
  637. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement