Created
June 12, 2024 20:13
-
-
Save secemp9/965977c7b7fb0e71622b5c76a326bb71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from pygame.locals import * | |
from OpenGL.GL import * | |
from OpenGL.GLU import * | |
import math | |
def draw_dotted_sphere(radius, lats, longs): | |
for i in range(lats): | |
lat0 = math.pi * (-0.5 + float(i) / lats) | |
z0 = radius * math.sin(lat0) | |
zr0 = radius * math.cos(lat0) | |
for j in range(longs): | |
lng = 2 * math.pi * float(j) / longs | |
x = math.cos(lng) | |
y = math.sin(lng) | |
glColor3f(0.5*(x+1), 0.5*(y+1), 0.5*(z0/radius+1)) # Color gradient based on position | |
glPointSize(3.0) # Size of the points | |
glBegin(GL_POINTS) | |
glVertex3f(x * zr0, y * zr0, z0) | |
glEnd() | |
def main(): | |
pygame.init() | |
display = (800, 600) | |
pygame.display.set_mode(display, DOUBLEBUF|OPENGL) | |
gluPerspective(45, (display[0] / display[1]), 0.1, 50.0) | |
glTranslatef(0.0, 0.0, -5) | |
glEnable(GL_POINT_SMOOTH) # Smooth out the points | |
glPointSize(3.0) # Size of the points | |
while True: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
pygame.quit() | |
quit() | |
glRotatef(1, 1, 1, 1) | |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) | |
draw_dotted_sphere(2, 50, 50) # You can adjust the 'lats' and 'longs' for more dots | |
pygame.display.flip() | |
pygame.time.wait(10) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment