Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.93 KB | None | 0 0
  1.  
  2. class rgb: public Heks{
  3.     public:
  4.         rgb(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
  5.             wypelnij();
  6.         }
  7.     virtual void wypelnij(){
  8.         float alfa, be;
  9.         for(int i=_x1;i<_x2;i++){
  10.             for(int j=_y1;j<_y2;j++){
  11.                 if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be))
  12.                     putpixel(i,j,COLOR(255,(int)(alfa*255),(int)(be*255)));
  13.                 if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be))
  14.                     putpixel(i,j,COLOR((int)(alfa*255),(int)(be*255),255));
  15.                 if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be))
  16.                     putpixel(i,j,COLOR((int)(be*255),255,(int)(alfa*255)));
  17.             }
  18.         }
  19.     }
  20. };
  21.  
  22. class cmy: public Heks{
  23.     public:
  24.         cmy(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
  25.             wypelnij();
  26.         }
  27.     virtual void wypelnij(){
  28.         float alfa, be;
  29.         for(int i=_x1;i<_x2;i++){
  30.             for(int j=_y1;j<_y2;j++){
  31.                 if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be))
  32.                     putpixel(i,j,COLOR(0,255-(int)(alfa*255),255-(int)(be*255)));
  33.                 if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be))
  34.                     putpixel(i,j,COLOR(255-(int)(alfa*255),255-(int)(be*255),0));
  35.                 if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be))
  36.                     putpixel(i,j,COLOR(255-(int)(be*255),0,255-(int)(alfa*255)));
  37.             }
  38.         }
  39.     }
  40. };
  41.  
  42. class hsl: public Heks{
  43.     public:
  44.         hsl(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
  45.             wypelnij();
  46.         }
  47.     void hsl2rgb(float H, float S, float L, float &red, float &green, float &blue){
  48.         float temp1, temp2, temp3_r, temp3_g, temp3_b;
  49.  
  50.                     if(L<0.5) temp2=L*(1+S);
  51.                     if(L>=0.5) temp2=L+S-L*S;
  52.                     temp1=2.0*L-temp2;
  53.  
  54.                     temp3_r=H+1.0/3.0;
  55.                     temp3_g=H;
  56.                     temp3_b=H-1.0/3.0;
  57.  
  58.                     if(temp3_r<0) temp3_r+=1;
  59.                     if(temp3_g<0) temp3_g+=1;
  60.                     if(temp3_b<0) temp3_b+=1;
  61.  
  62.                     if(temp3_r>1) temp3_r-=1;
  63.                     if(temp3_g>1) temp3_g-=1;
  64.                     if(temp3_b>1) temp3_b-=1;
  65.  
  66.                     if(6.0*temp3_r<1) red=temp1+(temp2-temp1)*6.0*temp3_r;
  67.                     else if(2.0*temp3_r<1) red=temp2;
  68.                     else if(3.0*temp3_r<2) red=temp1+(temp2-temp1)*((2.0/3.0)-temp3_r)*6.0;
  69.                     else red=temp1;
  70.  
  71.                     if(6.0*temp3_g<1) green=temp1+(temp2-temp1)*6.0*temp3_g;
  72.                     else if(2.0*temp3_g<1) green=temp2;
  73.                     else if(3.0*temp3_g<2) green=temp1+(temp2-temp1)*((2.0/3.0)-temp3_g)*6.0;
  74.                     else green=temp1;
  75.  
  76.                     if(6.0*temp3_b<1) blue=temp1+(temp2-temp1)*6.0*temp3_b;
  77.                     else if(2.0*temp3_b<1) blue=temp2;
  78.                     else if(3.0*temp3_b<2) blue=temp1+(temp2-temp1)*((2.0/3.0)-temp3_b)*6.0;
  79.                     else blue=temp1;
  80.  
  81.                     red=red*255;
  82.                     green=green*255;
  83.                     blue=blue*255;
  84.     }
  85.     virtual void wypelnij(){
  86.         float alfa, be;
  87.         for(int i=_x1;i<_x2;i++){
  88.             for(int j=_y1;j<_y2;j++){
  89.                 float r, g, b;
  90.                 if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be)){
  91.                     hsl2rgb(1, alfa, be, r, g, b);
  92.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  93.                 }
  94.                 if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be)){
  95.                     hsl2rgb(alfa, be, 1, r, g, b);
  96.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  97.                 }
  98.                 if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be)){
  99.                     hsl2rgb(be, 1, alfa, r, g, b);
  100.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  101.      
  102.                 }
  103.             }
  104.         }
  105.     }
  106. };
  107.  
  108.  
  109. class hsb: public Heks{
  110.     public:
  111.         hsb(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
  112.             wypelnij();
  113.         }
  114.  
  115.     void hsb2rgb(float h, float s, float v, float &red, float &green, float &blue){
  116.         float i,f,p,q,t;
  117.         h=((int)h)%360;
  118.         if(v==0){
  119.             red=green=blue=0;
  120.             return;
  121.         }
  122.         s/=100;
  123.         v/=100;
  124.         h/=60;
  125.         i=floor(h);
  126.         f=h-i;
  127.         p=v*(1-s);
  128.         q=v*(1-(s*f));
  129.         t=v*(1-(s*(1-f)));
  130.         if(i==0){red=v; green=t; blue=p;}
  131.         else if(i==1){red=q; green=v; blue=p;}
  132.         else if(i==2){red=p; green=v; blue=t;}
  133.         else if(i==3){red=p; green=q; blue=v;}
  134.         else if(i==4){red=t; green=p; blue=v;}
  135.         else if(i==5){red=v; green=p; blue=q;}
  136.         else if(i==6){red=v; green=p; blue=q;}
  137.         red=floor(red*255);
  138.         green=floor(green*255);
  139.         blue=floor(blue*255);
  140.     }
  141.     virtual void wypelnij(){
  142.         float alfa, be;
  143.         for(int i=_x1;i<_x2;i++){
  144.             for(int j=_y1;j<_y2;j++){
  145.                 float r, g, b;
  146.                 float h, s, b_;
  147.                 if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be)){
  148.                     h=1*360;
  149.                     s=alfa*100;
  150.                     b_=be*100;
  151.                     hsb2rgb(h,s,b_,r,g,b);
  152.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  153.                 }
  154.                 if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be)){
  155.                     h=alfa*360;
  156.                     s=be*100;
  157.                     b_=1*100;
  158.                     hsb2rgb(h,s,b_,r,g,b);
  159.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  160.                 }
  161.                 if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be)){
  162.                     h=be*360;
  163.                     s=1*100;
  164.                     b_=alfa*100;
  165.                     hsb2rgb(h,s,b_,r,g,b);
  166.                     putpixel(i,j,COLOR((int)r,(int)g,(int)b));
  167.                 }
  168.             }
  169.         }
  170.     }
  171. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement