Created
April 25, 2024 05:37
-
-
Save Fortyseven/f725432cbacaf7b1a58cc990d4652902 to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
Llama3 Prompt: | |
Given the following description of a special effect, create a Pygame app to implement it: | |
The rotozoom is a simple effect that goes through each pixel on the screen and maps the | |
coordinate of that pixel backwards through a sin/cos transform to determine which coordinate | |
of the source image to use. By applying a scale to that transform you also achieve the | |
zooming part of the rotozoom effect. Finally, the source coordinate is wrapped using modulo | |
to give a tiling effect. | |
""" | |
import pygame | |
import math | |
# Initialize Pygame | |
pygame.init() | |
# Set the screen dimensions | |
SCREEN_WIDTH = 320 | |
SCREEN_HEIGHT = 240 | |
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) | |
# Load the source image | |
source_image = pygame.image.load('source_image.png') | |
# Set the rotation speed and zoom factor | |
rotation_speed = 0.1 | |
zoom_factor = 1.01 | |
# Set the angle and scale | |
angle = 0 | |
scale = 1 | |
# Game loop | |
running = True | |
while running: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
running = False | |
# Fill the screen with black | |
screen.fill((0, 0, 0)) | |
# Calculate the new angle and scale | |
angle += rotation_speed | |
scale *= zoom_factor | |
# Loop through each pixel on the screen | |
for x in range(SCREEN_WIDTH): | |
for y in range(SCREEN_HEIGHT): | |
# Calculate the source coordinate | |
src_x = (x - SCREEN_WIDTH / 2) * math.cos(angle) - (y - SCREEN_HEIGHT / 2) * math.sin(angle) | |
src_y = (x - SCREEN_WIDTH / 2) * math.sin(angle) + (y - SCREEN_HEIGHT / 2) * math.cos(angle) | |
# Apply the scale | |
src_x *= scale | |
src_y *= scale | |
# Wrap the source coordinate using modulo | |
src_x = int(src_x) % source_image.get_width() | |
src_y = int(src_y) % source_image.get_height() | |
# Get the color of the source pixel | |
color = source_image.get_at((src_x, src_y)) | |
# Draw the pixel on the screen | |
screen.set_at((x, y), color) | |
# Update the display | |
pygame.display.flip() | |
# Quit Pygame | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment