Skip to content

Instantly share code, notes, and snippets.

@smcl
Created October 3, 2012 18:47
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smcl/3828954 to your computer and use it in GitHub Desktop.
Save smcl/3828954 to your computer and use it in GitHub Desktop.
Donut.c in c# (sorry)
using System;namespace
donut.net{class Program{static
void Main(string[] args){double A=0
,B=0,i,j;var z=new double[7040];var b=
new char[1760];while(true){memset(b,' ',1760);
memset(z,0.0f, 7040);for(j=0;6.28>j;j+=0.07)for(
i=0;6.28>i;i+=0.02){double c = Math.Sin(i);double d
=Math.Cos(j);double e=Math.Sin(A);double f=Math.Sin(j);
double g=Math.Cos(A); double h=d+2;double D=1
/(c*h*e+f*g+5);double l=Math.Cos(i);double m=
Math.Cos(B);double n =Math.Sin(B);double t=
c*h*g-f*e;int x=(int )(40+30*D*(l*h*m-t*n));
int y=(int)(12+15*D* (l*h*n + t*m));int o=x
+80*y;int N=(int)(8* ((f*e-c*d*g)*m-c*d*e-f*
g-l*d*n));if (22>y&&y>0&&x>0&&80>x&&D>z[o]){z[o]=D;b[o]
=".,-~:;=!*#$@"[N>0?N:0];}}Console.Clear();nl(b);Console.
Write(b);A+=0.04;B+=0.02;}}static void memset<T>
(T[] buf,T val,int bufsz){if (buf==null)buf=
new T[bufsz];for(int i=0;i<bufsz;i++)buf
[i] = val;}static void nl(char[]b){
for(int i=80;1760>i;i+=80){b
[i]='\n';}}}}
@PapiSneakz
Copy link

it just wont load on my console

@almicsen
Copy link

I tried as well and it too didn't work. I suggest using https://replit.com/languages/csharp

@smcl
Copy link
Author

smcl commented Jul 30, 2021

It's a ~9 year old gist. I've had a couple of beers but I'll come back and try to fix it up with a clear head tomorrow

@PapiSneakz
Copy link

now u should try it cuz of the ballmer peak lol

@smcl
Copy link
Author

smcl commented Jul 31, 2021

I think in the intervening period computers and/or .NET got too fast :) Try sticking a Thread.Sleep(33) before Console.Clear() so the characters are on screen a little longer before it's cleared.

@valxyz
Copy link

valxyz commented Apr 14, 2023

using System;

namespace donut.net{

class Program{
    static void Main(string[] args){

        double A = 0, B = 0, i, j;
        var z = new double[7040];
        var b = new char[1760];

        while (true){
            
            memset(b, ' ', 1760);
            memset(z, 0.0f, 7040);

            for (j = 0; 6.28 > j; j += 0.07){

                for (i = 0; 6.28 > i; i += 0.02){

                    double c = Math.Sin(i);
                    double d = Math.Cos(j);
                    double e = Math.Sin(A);
                    double f = Math.Sin(j);
                    double g = Math.Cos(A);
                    double h = d + 2;
                    double D = 1 / (c * h * e + f * g + 5);
                    double l = Math.Cos(i);
                    double m = Math.Cos(B);
                    double n = Math.Sin(B);
                    double t = c * h * g - f * e;

                    int x = (int)(40 + 30 * D * (l * h * m - t * n));
                    int y = (int)(12 + 15 * D * (l * h * n + t * m));
                    int o = x + 80 * y;
                    int N = (int)(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n));

                    if (22 > y && y > 0 && x > 0 && 80 > x && D > z[o]){
                        z[o] = D;
                        b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];
                    }
                }
            }

            Console.Clear();
            nl(b);
            Console.Write(b);

            A += 0.04;
            B += 0.02;
        }
    }

    static void memset<T>(T[] buf, T val, int bufsz){

        if (buf == null){
            buf = new T[bufsz];
        }

        for (int i = 0; i < bufsz; i++){
            buf[i] = val;
        }
    }

    static void nl(char[] b){
        for (int i = 80; 1760 > i; i += 80){
            b[i] = '\n';
        }
    }
}

}

@KITMAVV
Copy link

KITMAVV commented Apr 15, 2024

Here's a patched version with more control and smoother picture.

using System;
using System.Threading;

namespace donut.net
{
class Program
{
static void Main(string[] args)
{
double A = 0, B = 0, i, j;
var z = new double[1760];
var b = new char[1760];
const int width = 80;
const int height = 22;

        while (true)
        {
            memset(b, ' ', 1760);
            memset(z, 0.0f, 1760);

            for (j = 0; 6.28 > j; j += 0.07)
            {
                for (i = 0; 6.28 > i; i += 0.02)
                {
                    double c = Math.Sin(i);
                    double d = Math.Cos(j);
                    double e = Math.Sin(A);
                    double f = Math.Sin(j);
                    double g = Math.Cos(A);
                    double h = d + 2;
                    double D = 1 / (c * h * e + f * g + 5);
                    double l = Math.Cos(i);
                    double m = Math.Cos(B);
                    double n = Math.Sin(B);
                    double t = c * h * g - f * e;

                    int x = (int)(40 + 30 * D * (l * h * m - t * n));
                    int y = (int)(11 + 15 * D * (l * h * n + t * m));
                    int o = x + width * y;
                    int N = (int)(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n));

                    if (height > y && y > 0 && width > x && x > 0 && D > z[o])
                    {
                        z[o] = D;
                        b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];
                    }
                }
            }

            Console.SetCursorPosition(0, 0);
            nl(b);
            Console.Write(b);

            A += 0.04;
            B += 0.02;

            
            Thread.Sleep(20);
        }
    }

    static void memset<T>(T[] buf, T val, int bufsz)
    {
        if (buf == null)
        {
            buf = new T[bufsz];
        }

        for (int i = 0; i < bufsz; i++)
        {
            buf[i] = val;
        }
    }

    static void nl(char[] b)
    {
        for (int i = 80; 1760 > i; i += 80)
        {
            b[i] = '\n';
        }
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment