Skip to content

Instantly share code, notes, and snippets.

@ForLoopCodes
Created November 7, 2025 14:27
Show Gist options
  • Select an option

  • Save ForLoopCodes/8709ddad85c926ad76fed46a5f31b3d4 to your computer and use it in GitHub Desktop.

Select an option

Save ForLoopCodes/8709ddad85c926ad76fed46a5f31b3d4 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
#define RADIUS 10
int main()
{
char grid[RADIUS * 2][RADIUS * 4];
for (int i = 0; i < RADIUS * 2; i++)
{
for (int j = 0; j < RADIUS * 4; j++)
{
grid[i][j] = ' ';
}
}
for (double phi = 0.0; phi <= PI; phi += 0.01)
{
for (double theta = 0.0; theta < 2.0 * PI; theta += 0.01)
{
double x_norm = sin(phi) * cos(theta);
double y_norm = sin(phi) * sin(theta);
double z_norm = cos(phi);
int sx = (int)(RADIUS * (x_norm + 1.0) * 2);
int sy = (int)(RADIUS * (y_norm + 1.0));
if (sx >= 0 && sx < RADIUS * 4 && sy >= 0 && sy < RADIUS * 2)
{
grid[sy][sx] = '*';
}
}
}
for (int i = 0; i < RADIUS * 2; i++)
{
printf("%.*s\n", RADIUS * 4, grid[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment