Last active
January 7, 2026 10:17
-
-
Save coderodde/5aabedb029338cddac449c02f047cd87 to your computer and use it in GitHub Desktop.
Artur's mode I
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
| # ETC (Critter & Guitari) mode - Python 2.7 | |
| import os | |
| import glob | |
| import math | |
| import pygame | |
| i = 0 | |
| images = [] | |
| def setup(screen, etc): | |
| global images | |
| images = [] | |
| img_dir = os.path.join(etc.mode_root, 'Images', '*.png') | |
| for filepath in sorted(glob.glob(img_dir)): | |
| filename = os.path.basename(filepath) | |
| print 'loading image file: ' + filename | |
| img = pygame.image.load(filepath).convert_alpha() | |
| images.append(img) | |
| def draw(screen, etc): | |
| global images, i | |
| if not images: | |
| return | |
| # Center of the screen | |
| cx = screen.get_width() // 2 | |
| cy = screen.get_height() // 2 | |
| # knob2 = radius (plus a little audio modulation) | |
| R = etc.knob2 * 400.0 - 200.0 | |
| # Protect against audio_in being shorter than 100 | |
| if hasattr(etc, 'audio_in') and etc.audio_in: | |
| R += (etc.audio_in[i % len(etc.audio_in)] / 100.0) | |
| # orbit angle (0..2pi) | |
| angle = (i / 100.0) * (2.0 * math.pi) | |
| # position around the center | |
| x = cx + R * math.cos(angle) | |
| y = cy + R * math.sin(angle) | |
| # knob3 = circle size / ring width | |
| max_circle = 200 | |
| if etc.knob3 <= 0.5: | |
| circle_size = int(etc.knob3 * max_circle) | |
| line_width = 0 | |
| else: | |
| circle_size = abs(max_circle - int(etc.knob3 * max_circle)) | |
| line_width = int((etc.knob3 - 0.5) * 60) # ~0..30 | |
| if line_width < 1: | |
| line_width = 1 | |
| color = etc.color_picker() | |
| pygame.draw.circle(screen, color, (int(x), int(y)), circle_size, line_width) | |
| # knob1 = image size | |
| base = images[0] | |
| w = max(1, int(base.get_width() * etc.knob1)) | |
| h = max(1, int(base.get_height() * etc.knob1)) | |
| img = pygame.transform.scale(base, (w, h)) | |
| # draw image centered on (x, y) | |
| screen.blit(img, (int(x - w // 2), int(y - h // 2))) | |
| i = (i + 1) % 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment