Last active
July 20, 2023 10:56
-
-
Save coderodde/2d759177cc27094c9f4d4b769f645d5a to your computer and use it in GitHub Desktop.
Mod 2B.
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
# Author: Rodion Efremov | |
# Version: VIII | |
# Date: Jul 20, 2023 13:55. | |
# Info: Fixing stuff. | |
import os | |
import pygame | |
import time | |
import random | |
import pygame.freetype | |
import math | |
etc_frequency = 60.0 | |
etc_frame_duration = 1.0 / etc_frequency | |
class SinusoidalLFO: | |
def __init__(self, maximum_angle_amplitude, frequency): | |
self.maximum_angle_amplitude = maximum_angle_amplitude | |
self.frequency = frequency | |
self.angle = 0.0 | |
self.time = 0.0 | |
def get_angle(self): | |
return self.angle | |
def update(self): | |
wave_length = 1.0 / self.frequency | |
if self.time > wave_length: | |
self.time -= wave_length | |
self.angle = self.maximum_angle_amplitude * math.sin(2.0 * math.pi * self.frequency * self.time) | |
self.time += etc_frame_duration | |
size = 1000 | |
gs = 0 | |
charnum = 1 | |
x = 640 | |
y = 360 | |
yo = 255 | |
speed = 1 | |
lfo = SinusoidalLFO(90.0, 1.0) | |
red = (190, 0, 0) | |
brown = (0, 40, 40) | |
blue = (100, 100, 255) | |
def is_between(char_number, min, max): | |
return min <= char_number <= max | |
def get_color_of_char(char_number): | |
if is_between(char_number, 33, 64): | |
return red | |
if is_between(char_number, 65, 90): | |
return brown | |
if is_between(char_number, 91, 122): | |
return blue | |
return None | |
def setup(screen, etc): | |
pygame.freetype.init() | |
def draw(screen, etc): | |
global size, gs, charnum, x, y, charList, unistr, coloryo, yo, speed | |
char_index = None | |
if etc.audio_trig or etc.midi_note_new : | |
gs = 1 | |
size = 800 * (etc.knob2 + .1) | |
char_index = random.randint(65, 120) | |
unistr = unichr(char_index) | |
x = random.randrange(0,screen.get_width()) | |
y = random.randrange(0,screen.get_height()) | |
color = etc.color_picker() | |
speed=int(etc.knob1*100+1) | |
yo = speed | |
if gs == 1 and size > 0 : | |
font = pygame.freetype.Font(etc.mode_root + "/font.ttf", size) | |
color = etc.color_picker() | |
test_color = get_color_of_char(char_index) | |
if test_color: | |
color = test_color | |
coloryo = (int(color[0]*speed/yo),int(color[1]*speed/yo),color[2]*speed/yo) | |
if coloryo == (1,1,1) : coloryo = (0,0,0) | |
(text, textpos) = font.render(unistr, coloryo) | |
textpos.centerx = x | |
textpos.centery = y | |
angle = lfo.get_angle() | |
my_surface = pygame.transform.rotate(text, (etc.knob3 - 0.5) * (-180.0) + angle) | |
screen.blit(my_surface, textpos) | |
size = size - 5 * 50*(etc.knob3 + .02) | |
yo = yo + 1 | |
if yo > 255 : yo = 255 | |
if size < 1 : size = 1 | |
lfo.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment