Skip to content

Instantly share code, notes, and snippets.

@gynvael
Created March 16, 2023 14:47
Show Gist options
  • Save gynvael/23f7bcd97c5c6e26b89590c0108927a4 to your computer and use it in GitHub Desktop.
Save gynvael/23f7bcd97c5c6e26b89590c0108927a4 to your computer and use it in GitHub Desktop.
JS to Python GPT-3.5 conversion
# original:
# https://github.com/gynvael/zrozumiec-programowanie/blob/master/018-Czesc_IV-Rozdzial_12-Format_BMP_i_wstep_do_bitmap/show.cpp
# this was converted to JS by GPT4, and then to this PY by GPT3.5
import pygame
# Initialize Pygame
pygame.init()
# Set up the canvas
W, H = 256, 256
canvas = pygame.display.set_mode((W, H))
pygame.display.set_caption("Gradient")
# Create a red-to-black gradient image
gradient = pygame.Surface((W, H))
for y in range(H):
for x in range(W):
index = x # ---------------- there was an error here: (x+y*W)
gradient.set_at((x, y), (index, 0, 0))
# Draw the gradient image to the center of the canvas
posX = (canvas.get_width() - W) // 2
posY = (canvas.get_height() - H) // 2
canvas.blit(gradient, (posX, posY))
# Run the main loop
running = True
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running = False
# Update the display
pygame.display.flip()
# Clean up Pygame
pygame.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment