User:ProjectEuler/Sandbox

From Esolang
Jump to navigation Jump to search
// Convert ASCII-Piet back into an HTML-encoded image.
//Last letter can not be a capital letter

#include <stdio.h>

int width=0,w=0;
int c=0,c1=0;
int h1=0,h2=0;

int main(){
scanf("%d",&width); // no extra newline after number

printf("%ctable style=\"border-collapse:collapse;\">",60);

for(w=0,c=9;c>=0;){
 c=getchar();
 if(c<0){
  for(;w<width;++w){
   printf("%ctd style=\"width:1ex;height:1ex;background:#000000;\"/>",60);
  }
  printf("%c/tr>",60);
  w=0;
  break; // end of file
 }
 if(w==0){printf("%ctr>",60);}

 if(c==10){

  for(;w<width;++w){
   printf("%ctd style=\"width:1ex;height:1ex;background:#000000;\"/>",60);
  }
  printf("%c/tr>",60);
  w=0;
  
 } else {

  if(63<c && c<96){

   //Start color
   c1=c%32;
   if(c1==0){
    printf("%ctd style=\"width:1ex;height:1ex;background:#000000;\"/>",60);
   }else if(c1==31){
    printf("%ctd style=\"width:1ex;height:1ex;background:#ffffff;\"/>",60);
   }else{
    if(0<c1 && 9>c1){h1=192;h2=0;}
    if(8<c1 && 17>c1){h1=255;h2=0;}
    if(16<c1 && 25>c1){h1=255;h2=192;}
    printf("%ctd style=\"width:1ex;height:1ex;background:#%02x%02x%02x;\"/>",60,
        ( (c1/4)?h1:h2 ),
        ( (c1/2%2)?h1:h2 ),
        ( (c1%2)?h1:h2 )
    );
   }
   //End color

  ++w;
  for(;w<width;++w){
   printf("%ctd style=\"width:1ex;height:1ex;background:#000000;\"/>",60);
  }
  printf("%c/tr>",60);
  w=0;

  } else {


   //Start color
   c1=c%32;
   if(c1==0){
    printf("%ctd style=\"width:1ex;height:1ex;background:#000000;\"/>",60);
   }else if(c1==31){
    printf("%ctd style=\"width:1ex;height:1ex;background:#ffffff;\"/>",60);
   }else{
    if(0<c1 && 9>c1){h1=192;h2=0;}
    if(8<c1 && 17>c1){h1=255;h2=0;}
    if(16<c1 && 25>c1){h1=255;h2=192;}
    printf("%ctd style=\"width:1ex;height:1ex;background:#%02x%02x%02x;\"/>",60,
        ( (c1/4)?h1:h2 ),
        ( (c1/2%2)?h1:h2 ),
        ( (c1%2)?h1:h2 )
    );
   }
   //End color

   ++w;
  }

 }
}

printf("%c/table>",60);
return 0;
}


LifeViewer version:

x = 5, y = 2, rule = HistoricalMuziksRainbowRA
2T2LE$2T.2E!


tliiahd?dn??samte?rjliiah
t?????a?advd?iqq ?r?????k
t?dah?e?akr?? qqt?r?uic?q
          r?aaaqu?a?fei? l
                      i?vl
                         l