Skip to content

8AVIANVS/spinningDonutsTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Original Code

https://github.com/ioccc-src/winner/blob/master/2006/sloane/sloane.c

Prompt to o3-mini-high:

improve this piece of code for me for legibility and formatting:

Thinking Process:

Okay, so I need to reformat this messy piece of C code to make it more readable and stylish. I'll focus on adding proper indentation, consistent naming conventions, and removing unnecessary complexity, all while ensuring proper spacing between code blocks. I need to be mindful of sectioning the code into logical chunks too, so it's easy to follow. I'll make variables and functions more readable too, aiming for clear and clean structure that improves the overall legibility. Let's start!

Okay, I'm going to focus on reformatting this messy code to improve readability. I see that characters are being written into b[]. There’s a loop structure and conditions that seem to alternate based on certain checks. Part of this looks like some kind of ASCII art or visual representation. I'll separate things out for clarity and give each block its own space to make it easier to follow what's happening in p(n, c).

Let’s break down the logic more clearly for the user!

Alright, it looks like this code is intentionally obfuscated—it's structured in a way that makes it hard to follow at first glance. I’ll focus on reformatting it to improve legibility without changing too much of the original structure, since renaming everything could alter its intent. I'll break it apart into logical blocks and add proper indentation. I'll also format the K&R style function headers into ANSI style if needed but avoid heavy changes to variable names to respect the obfuscation. Let's clean it up and make it more understandable!

Alright, I'll focus on improving the code's readability while staying true to its structure. I'll reformat the functions and add proper indentation, but leave the variable names as they're intended to preserve the obfuscation. I'll also make sure to declare function prototypes at the top, as that seems to be a good format for better structure. The goal is clarity without altering the program's effect. This version should now be easier to follow, but with minimal changes to it!

Alright, I've added some comments to help clarify the code and make it more readable. So now, every major section—like initializing the buffer, calculating the 3D shape, and outputting the frame—has a brief description. I also added necessary parentheses around complex expressions to make it clear, especially for bitwise operations and the ternary operator. I kept the variable names intact since renaming would affect the functionality. The code looks cleaner now, and I think it’s much easier to follow without losing its essence!

Code Output

#include <stdio.h>
#include <math.h>

// Global variables used for drawing
int _, x, y, o, N;
char b[1920];

// Writes character 'c' into the global buffer 'b'
// based on the count 'n' and updates position variables.
void p(int n, int c) {
    for (; n--; x++) {
        if (c == 10) {
            y += 80;
            x = o - 1;
        } else if (x >= 0 && x < 80) {
            if (c != '~') {
                b[y + x] = c;
            }
        }
    }
}

// Obfuscated function that transforms 'q' based on two string inputs.
int c(int q, char *l, char *r) {
    while (q >= 0) {
        q = (
              (
                (
                  ( "E" "?yYrIxC{e^}KhE>[|LXbj}" "dOVsJ"
                    "@" "idOV{Yab[bW}[bW}\\qFywyv{D" "ma\\A"
                    "Ztq?Lyw>e{|Zq>Y\\gq\\qI[tYBe{w" "yvDZE\\vBA[`_"
                    "Lo>}KcqdYrWqKxzKtW]|DXRwsfcUaT\\KXw{Y"
                    "RsFwsFwsFw{zaqyaz|FmMpyaoyI\\]cuUw{J"
                  )[_ / 6] - 62
                ) >> (_++ % 6)
              ) & 1 ? r[q] : l[q]
            ) - 99;
    }
    return q;
}

// Another obfuscated function that repeatedly calls 'c' and 'p'
// to modify the global buffer.
void E(int a) {
    for (o = x = a, y = 0, _ = 0; _ < 1006; ) {
        // Update 'a' based on a lookup into a concatenated string literal
        a = (" /\\\n" "~|_.")[c(6, "bcd\\a[g", "^`_e]fh") + 8];
        // Call p with a character value computed from another string literal
        p(("#$%&'()*+,-.1")[c(11, "_ac[]\\YZijkm", "`bd^efghXWlV") + 13] - 34, a);
    }
}

int main(int argc, char **argv) {
    int k;
    float z[1920], A = 0, B = 0, i, j;

    // Clear the screen using ANSI escape code.
    puts("\x1b[2J");

    // Main animation loop
    for (;;) {
        float e = sin(A);
        float n = sin(B);
        float g = cos(A);
        float m = cos(B);

        // Prepare the frame buffer for 1840 characters.
        for (k = 0; k < 1840; k++) {
            y = -k / 80 - 10;
            o = 41 + ((k % 80) - 40) * 1.3 / y + n;
            N = A - 100.0 / y;
            b[k] = ".#"[ (o + N) & 1 ];
            z[k] = 0;
        }

        // Call function E with a computed parameter.
        E(80 - ((int)(9 * B) % 250));

        // Iterate over angles to compute the shape and update the buffer.
        for (j = 0; j < 6.28; j += 0.07) {
            for (i = 0; i < 6.28; i += 0.02) {
                float c_val = sin(i);
                float d = cos(j);
                float f = sin(j);
                float h = d + 2;
                float D = 15 / (c_val * h * e + f * g + 5);
                float l = cos(i);
                float t = c_val * h * g - f * e;

                x = 40 + 2 * D * (l * h * m - t * n);
                y = 12 + D * (l * h * n + t * m);
                o = x + 80 * y;
                N = 8 * ((f * e - c_val * d * g) * m - c_val * d * e - f * g - l * d * n);
                if (D > z[o]) {
                    z[o] = D;
                    b[o] = " ..,,-++=#$@"[ (N > 0 ? N : 0) ];
                }
            }
        }

        // Move cursor to top left and output the buffer
        printf("\x1b[H");
        for (k = 1; k < 1841; k++)
            putchar(k % 80 ? b[k] : '\n');

        // Update angles for next frame
        A += 0.053;
        B += 0.037;
    }

    return 0;
}

Explanation

Includes & Globals:

The necessary headers (stdio.h and math.h) are included. Global variables (_, x, y, o, N and the character buffer b) remain as in the original code.

Function p:

Reformatted with braces and clear conditions so that the intent is more visible.

Function c:

The long, concatenated string is preserved and the expression is grouped with extra parentheses to clarify the bitwise operations and ternary operator.

Function E:

Reformatted into a for‐loop with initialization clearly listed. The concatenated string literals are kept intact.

main:

The animation loop is formatted with proper indentation. Each section (frame setup, shape computation, rendering, and angle update) is clearly separated with comments.

This version preserves the original logic while significantly improving readability and maintainability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published