Feeping Creaturism #1

Post Reply
User avatar
alexandria
Posts: 14
Joined: 04 May 2019, 23:42

Feeping Creaturism #1

Post by alexandria » 10 May 2019, 01:36

I just had an idea for something that might be amusing. Basically the idea is, one person starts off with a program that does maybe, one thing. Another person takes the program and adds something to it/improves upon it, then the next person in the thread does the same, and so on.

So, basically the rough 'guide' or 'rules' of the game are:
  • You start your program by modifying the last posted code in the thread (If there's a selection, feel free to choose though).
  • You can add code.
  • You can modify existing code
  • You should try not to remove code (If you really need to, comment it out).
  • Try and build on whatever features the program has already, or not, make it do something ridiculous, idk.
I did a toss-up between C and maybe something like codepen.io and p5.js, or whatever, and C won because whatever.

But anyway, here's to starting it off:

Code: Select all

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <unistd.h>
#include <string.h>

#define SAMPLES 8000 /* per second */
#define TAU M_PI*2
#define NOTE 440

int main(int argc, char **argv)
{
        uint8_t t = 0;
        uint8_t i = 0;
        uint8_t volume = 128;

        /* 440Hz is an A sound, I cannot remember what 640Hz is */
        int notes[24] = { 440, 640, 440, 640, 440, 640, 440, 640,
                          440, 640, 440, 640, 440, 640, 440, 640,
                          440, 640, 440, 640, 440, 640, 440, 640 };

        for (; ; t++) { 
                /* Every 4 samples (which I guess is our unit of time),
                   we increment i, which increments the note */
                i = (t % SAMPLES*4) == 0 ? i+1 : i;
                i = i % 24; 

                /* formula is: ( sine( time * TAU  / SAMPLES * NOTE ) + 1 ) * VOLUME */

                uint8_t n = (sin(t * TAU / SAMPLES*notes[i])+1)*volume;

                write(STDOUT_FILENO, &n, 1);
        }

        return 0;
}
trans gal
assembler monster will eat your code

Image
Image

Post Reply