Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class rgb: public Heks{
- public:
- rgb(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
- wypelnij();
- }
- virtual void wypelnij(){
- float alfa, be;
- for(int i=_x1;i<_x2;i++){
- for(int j=_y1;j<_y2;j++){
- if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be))
- putpixel(i,j,COLOR(255,(int)(alfa*255),(int)(be*255)));
- if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be))
- putpixel(i,j,COLOR((int)(alfa*255),(int)(be*255),255));
- if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be))
- putpixel(i,j,COLOR((int)(be*255),255,(int)(alfa*255)));
- }
- }
- }
- };
- class cmy: public Heks{
- public:
- cmy(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
- wypelnij();
- }
- virtual void wypelnij(){
- float alfa, be;
- for(int i=_x1;i<_x2;i++){
- for(int j=_y1;j<_y2;j++){
- if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be))
- putpixel(i,j,COLOR(0,255-(int)(alfa*255),255-(int)(be*255)));
- if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be))
- putpixel(i,j,COLOR(255-(int)(alfa*255),255-(int)(be*255),0));
- if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be))
- putpixel(i,j,COLOR(255-(int)(be*255),0,255-(int)(alfa*255)));
- }
- }
- }
- };
- class hsl: public Heks{
- public:
- hsl(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
- wypelnij();
- }
- void hsl2rgb(float H, float S, float L, float &red, float &green, float &blue){
- float temp1, temp2, temp3_r, temp3_g, temp3_b;
- if(L<0.5) temp2=L*(1+S);
- if(L>=0.5) temp2=L+S-L*S;
- temp1=2.0*L-temp2;
- temp3_r=H+1.0/3.0;
- temp3_g=H;
- temp3_b=H-1.0/3.0;
- if(temp3_r<0) temp3_r+=1;
- if(temp3_g<0) temp3_g+=1;
- if(temp3_b<0) temp3_b+=1;
- if(temp3_r>1) temp3_r-=1;
- if(temp3_g>1) temp3_g-=1;
- if(temp3_b>1) temp3_b-=1;
- if(6.0*temp3_r<1) red=temp1+(temp2-temp1)*6.0*temp3_r;
- else if(2.0*temp3_r<1) red=temp2;
- else if(3.0*temp3_r<2) red=temp1+(temp2-temp1)*((2.0/3.0)-temp3_r)*6.0;
- else red=temp1;
- if(6.0*temp3_g<1) green=temp1+(temp2-temp1)*6.0*temp3_g;
- else if(2.0*temp3_g<1) green=temp2;
- else if(3.0*temp3_g<2) green=temp1+(temp2-temp1)*((2.0/3.0)-temp3_g)*6.0;
- else green=temp1;
- if(6.0*temp3_b<1) blue=temp1+(temp2-temp1)*6.0*temp3_b;
- else if(2.0*temp3_b<1) blue=temp2;
- else if(3.0*temp3_b<2) blue=temp1+(temp2-temp1)*((2.0/3.0)-temp3_b)*6.0;
- else blue=temp1;
- red=red*255;
- green=green*255;
- blue=blue*255;
- }
- virtual void wypelnij(){
- float alfa, be;
- for(int i=_x1;i<_x2;i++){
- for(int j=_y1;j<_y2;j++){
- float r, g, b;
- if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be)){
- hsl2rgb(1, alfa, be, r, g, b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be)){
- hsl2rgb(alfa, be, 1, r, g, b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be)){
- hsl2rgb(be, 1, alfa, r, g, b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- }
- }
- }
- };
- class hsb: public Heks{
- public:
- hsb(int x_1, int y_1, int x_2, int y_2): Heks(x_1,y_1,x_2,y_2){
- wypelnij();
- }
- void hsb2rgb(float h, float s, float v, float &red, float &green, float &blue){
- float i,f,p,q,t;
- h=((int)h)%360;
- if(v==0){
- red=green=blue=0;
- return;
- }
- s/=100;
- v/=100;
- h/=60;
- i=floor(h);
- f=h-i;
- p=v*(1-s);
- q=v*(1-(s*f));
- t=v*(1-(s*(1-f)));
- if(i==0){red=v; green=t; blue=p;}
- else if(i==1){red=q; green=v; blue=p;}
- else if(i==2){red=p; green=v; blue=t;}
- else if(i==3){red=p; green=q; blue=v;}
- else if(i==4){red=t; green=p; blue=v;}
- else if(i==5){red=v; green=p; blue=q;}
- else if(i==6){red=v; green=p; blue=q;}
- red=floor(red*255);
- green=floor(green*255);
- blue=floor(blue*255);
- }
- virtual void wypelnij(){
- float alfa, be;
- for(int i=_x1;i<_x2;i++){
- for(int j=_y1;j<_y2;j++){
- float r, g, b;
- float h, s, b_;
- if(rhombus(w2_x,w2_y,w1_x,w1_y,i,j,alfa, be)){
- h=1*360;
- s=alfa*100;
- b_=be*100;
- hsb2rgb(h,s,b_,r,g,b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- if(rhombus(w4_x,w4_y,w3_x,w3_y,i,j,alfa,be)){
- h=alfa*360;
- s=be*100;
- b_=1*100;
- hsb2rgb(h,s,b_,r,g,b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- if(rhombus(w6_x,w6_y,w5_x,w5_y,i,j,alfa,be)){
- h=be*360;
- s=1*100;
- b_=alfa*100;
- hsb2rgb(h,s,b_,r,g,b);
- putpixel(i,j,COLOR((int)r,(int)g,(int)b));
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement