Skip to content

Instantly share code, notes, and snippets.

@Godzil
Created September 5, 2018 14:25
Show Gist options
  • Save Godzil/24f32d89df4023a55e0dc9b2ba2089ad to your computer and use it in GitHub Desktop.
Save Godzil/24f32d89df4023a55e0dc9b2ba2089ad to your computer and use it in GitHub Desktop.
Rotating Orange
# Translated from PICO-8 Lua code to Python/PyGame
# Original: https://twitter.com/2DArray/status/1037052263091658752
import sys
import pygame
import math
import random
pygame.init()
clk = pygame.time.Clock()
screen = pygame.display.set_mode((128, 128))
palette = [
(0, 0, 0),
(29, 43, 83),
(126, 37, 83),
(0, 135, 81),
(171, 82, 54),
(95, 87, 79),
(194, 195, 199),
(255, 241, 232),
(255, 0, 77),
(255, 163, 0),
(255, 236, 39),
(0, 228, 54),
(41, 173, 255),
(131, 118, 156),
(255, 119, 168),
(255, 204, 170),
]
t = 0
random.seed()
def picosin(r):
r = r * (math.pi*2)
return math.sin(-r)
def picocos(r):
r = r * (math.pi * 2)
return math.cos(r)
def circfill(x, y, radius, colour):
pygame.draw.circle(screen, palette[int(colour)], (int(x), int(y)), int(radius))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
screen.fill(palette[0])
q = t / 8
for i in range(0, 1500):
y = i / 750 - 1
r = math.sqrt(1 - y * y)
b = i * 0.618
a = b + q
x = picocos(a) * r
z = picosin(a) * r + 2
c = 9 + random.uniform(0, 1.3)
if y > 0:
y = 0
c = 9
if y == 0 and (r > .9 or r < .3 or (b % 0.1) < 0.03):
c = 7
y -= 0.7
if z < 2 or y == -.7:
circfill(44 + (x-y) * 40 / z,
44 - ((x+y)*40)/z,
3 / z,
c)
pygame.display.flip()
clk.tick(30)
t += 0.05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment