Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
zmx0142857
GitHub Repository: zmx0142857/mini-games
Path: blob/master/c/sphere/sphere.c
363 views
1
#include <stdio.h>
2
#include <math.h>
3
4
#define inv_of_sqrt3 0.5773502692
5
6
int main()
7
{
8
double x, y, z;
9
unsigned index;
10
for (y = 1; y >= -1; y -= 0.05)
11
{
12
for (x = -1; x <=1; x += 0.025)
13
{
14
z = sqrt(1.0 - x*x - y*y);
15
16
// the value of x+y+z is between -sqrt3 and +sqrt3
17
// 0.5 is for rounding (si4 she4 wu3 ru4)
18
index = ((x + y + z) * inv_of_sqrt3 + 1.0) * 5.0 + 0.5;
19
putchar(x*x + y*y > 1.0 ? 'M' : "@@%#*+=;:. "[index]);
20
}
21
putchar('\n');
22
}
23
return 0;
24
}
25
26