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
# Take in input from the user. | |
while True: | |
num = None | |
# Check if the input is a valid integer. | |
try: | |
# Take in input from the user. | |
num = input("Input a number: ") | |
int(num) # Try to turn input into an integer | |
except ValueError: | |
print("Please input a correct integer.") |
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
def heart(n): | |
s = "" | |
for i in range(n): | |
s0 = " " * (n - i - 1) | |
s1 = "*" * (i * 2 + 1) | |
s2 = " " * (2 * (n - i) - 1) | |
s3 = "*" * (i * 2 + 1) | |
s4 = " " * (n - i - 1) | |
s += s0 + s1 + s2 + s3 + s4 + "\n" | |
for i in range(1, n * 2): |
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
import time | |
fps = 60 | |
animation_start = time.perf_counter() | |
skip_frames = 0 | |
for framecount, frame in enumerate(animation): | |
if skip_frames > 0: | |
skip_frames -= 1 | |
continue | |
frame_start = time.perf_counter() |
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
def hsv_to_rgb(h, s, v) -> tuple[float, float, float]: | |
# 0 <= h <= 1 | |
# 0 <= s <= 1 | |
# 0 <= v <= 1 | |
c = v * s | |
x = c * (1 - abs(h*6 % 2 - 1)) | |
m = v - c | |
rgb = ( | |
(c, x, 0), |
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
from itertools import product | |
import math | |
import random | |
def smoothstep(t): | |
return t * t * (3. - 2. * t) | |
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
def rmod(v: float, minimum: float, maximum: float) -> float: | |
"""modulo with minimum and maximum range | |
Args: | |
v (float): value | |
minimum (float): minimum | |
maximum (float): maximum | |
Returns: | |
float: result |
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
def lerp(v0, v1, t): | |
return (1 - t) * v0 + t * v1 | |
def inv_lerp(a, b, v): | |
return (v - a) / (b - a) | |
def remap(min0, max0, min1, max1, value): | |
return lerp(min1, max1, inv_lerp(min0, nax1, value)) | |
def remap(v, a0, a1, b0, b1): |