../c-circle

Obfuscated C cricle

The other day I remembered about the International Obfuscated C Code Contest. I thought it would be fun to try, and I tried to make a circle-shaped code to display a circle in C.

This is how I did it. First, I wrote a normal code to draw a circle in terminal. Then, after playing around with the radius of the circle, I drew a circle with roughly the area of the code I used to generate it. Finally, I rearranged my code to make it look like a sphere. This is what I ended up with:

#include <stdlib.h>
#include <stdio.h>
#define RADIUS 6

       int main()
    {float r = RADIUS
  ;for(float i = 0; i<
 r*2 ; i++) { for(float
j = 0 ; j < r*4 ; j++ ){
float d = ((i - r + 0.5)
*(i - r + 0.5) + 0.25 *(
j- 2*r + 0.5) * (j - 2*r
 +0.5 ) ) ; printf( d < 
  r * r ? "#" : " ");} 
    printf( "\n" );}
       return 0;}

This is a small demo of the code:

$ ./circle
       ##########       
    ################    
  ####################  
 ###################### 
########################
########################
########################
########################
 ###################### 
  ####################  
    ################    
       ##########       

This code is not worth posting on IOCCC, but the process of creating it was fun. It might be possible to generate arbitrary shaped code with a modified version of an ASCII cam, for example. I might look into this in the future...

/Obfuscated/ /C/