Tweetable Art Code

Andy Balaam
artificialworlds.net/blog

Contents

Challenge

Create some Tweetable Mathematical Art.

https://codegolf.stackexchange.com/questions/35569/tweetable-mathematical-art

Example: red

Example: red

unsigned short RD( int i, int j ) {
    return 1023;
}

unsigned short GR( int i, int j ) {
    return 0;
}

unsigned short BL( int i, int j ) {
    return 0;
}

Example: gradient

Example: gradient

unsigned short RD( int i, int j ) {
    return i;
}

unsigned short GR( int i, int j ) {
    return i;
}

unsigned short BL( int i, int j ) {
    return j;
}

Answer

Answer

Credit:

teh internets is made of catz

https://codegolf.stackexchange.com/users/11744/teh-internets-is-made-of-catz

Answer

int t[64],k=0,l,e,d=2e7;srand(time(0));while(k<64){t[k]=rand()%DIM;if((e=_sq(i-t[k])+_sq(j-t[42&k++]))<d)d=e,l=k;}return t[l];
static int t[64];int k=0,l,e,d=2e7;while(k<64){if(!t[k])t[k]=rand()%DIM;if((e=_sq(i-t[k])+_sq(j-t[42&k++]))<d)d=e,l=k;}return t[l];
static int t[64];int k=0,l,e,d=2e7;while(k<64){if(!t[k])t[k]=rand()%DIM;if((e=_sq(i-t[k])+_sq(j-t[42&k++]))<d)d=e,l=k;}return t[l];

(127 chars, 132 chars, 132 chars)

Answer

3 superimposed "Voronoi" diagrams

Answer

Answer

unsigned short RD( int i, int j ) {

    int t[64], // coords of 64 sites
    k=0,   // loop counter
    l,     // index of closest site
    e,     // temporary
    d=2e7; // distance to closest

Answer

hacks
while(k<64){ // For each point
    hacks that set up t[k]s
    if(      // if shorter distance
        ( e = _sq( i - t[k] ) + 
              _sq( j - hack )
        ) < d
    )
        d=e, // store distance
        l=k; // and remember index
}

Answer

    // l is the index of the
    // closest site.  Return
    // the colour of that site.
    return t[l]
}

Answer

unsigned short GR( int i, int j ) {
unsigned short BL( int i, int j ) {

    // Both same as red
    // (except for hacks)

Hacks

int t[64],k=0,l,e,d=2e7;
// At the start of every call to RD
// reset the random seed.
// This gets us the same sites
// every time without storing them.
srand(time(0));
while(k<64)

// Just hope we don't cross
// a second boundary!

Hacks

while(k<64){
    // Then the x coord is made
    // by a call to rand()
    t[k]=rand()%DIM;
    if((e=_sq(...

Hacks

if(
    ( e = _sq( i - t[k] ) + 
          _sq( j - t[42&k++])
    ) < d
)
// The y coord is the x coord of
// the site with index m, where
// m = 00101010 & k

// Note m <= k, so
// t[m] is initialised.

Hacks

        ) < d
    )
        d=e, // comma avoids needing
        l=k; // {} around these. 
    }

Hacks


        d=e,
        l=k;
    }
    // The colour we return is
    // the x coord of the site
    return t[l];
}

Other Answers

Credit: githubphagocyte

Other Answers

Credit: user11153 (183 bytes over)

Other Answers

Credit: FireFly

Other Answers

Credit: cjfaure

Other Answers

Credit: squeamish ossifrage

Other Answers

Credit: FireFly

More info

Patreon! patreon.com/andybalaam
Videos youtube.com/user/ajbalaam
Twitter @andybalaam
Blog artificialworlds.net/blog
Projects artificialworlds.net