Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # for_pixel_generative_art.py
- Mandelbrot Set: This algorithm generates a Mandelbrot set by iterating over a complex plane and using a color map to determine the color of each point based on the number of iterations it takes to escape the set.
- import math
- def mandelbrot():
- for x in range(-width, width):
- for y in range(-height, height):
- z = complex(x * 4 / width, y * 4 / height)
- c = z
- for i in range(255):
- if abs(z) > 2:
- break
- z = z * z + c
- cv.create_line(x, y, x, y, fill=color_map[i])
- cv.update()
- Conway's Game of Life: This algorithm simulates the evolution of a cellular automaton according to the rules of Conway's Game of Life.
- def game_of_life():
- grid = [[random.choice([0, 1]) for _ in range(width)] for _ in range(height)]
- while True:
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- neighbors = sum([grid[i + ii][j + jj] for ii in [-1, 0, 1] for jj in [-1, 0, 1] if ii != 0 or jj != 0])
- if grid[i][j] == 1:
- if neighbors < 2 or neighbors > 3:
- grid[i][j] = 0
- else:
- if neighbors == 3:
- grid[i][j] = 1
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- if grid[i][j] == 1:
- cv.create_line(i, j, i + 1, j + 1, fill='black')
- else:
- cv.create_line(i, j, i + 1, j + 1, fill='white')
- cv.update()
- Fractal Tree: This algorithm generates a fractal tree by recursively drawing lines with decreasing length and alternating colors.
- def fractal_tree(cv, x1, y1, angle, depth):
- if depth:
- x2 = x1 + int(math.cos(angle) * depth * 10)
- y2 = y1 + int(math.sin(angle) * depth * 10)
- cv.create_line(x1, y1, x2, y2, fill=random.choice(colors))
- fractal_tree(cv, x2, y2, angle - 20, depth - 1)
- fractal_tree(cv, x2, y2, angle + 20, depth - 1)
- def draw_fractal_tree():
- fractal_tree(cv, width / 2, height, -90, 9)
- cv.update()
- Cellular Automaton: This algorithm simulates a cellular automaton by using a rule set to determine the color of the line based on the colors of neighboring cells.
- import random
- def cellular_automaton():
- grid = [[random.choice(colors) for _ in range(width)] for _ in range(height)]
- while True:
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- neighbors = sum([grid[i + ii][j + jj] for ii in [-1, 0, 1] for jj in [-1, 0, 1] if ii != 0 or jj != 0])
- if grid[i][j] == 1:
- if neighbors < 2 or neighbors > 3:
- grid[i][j] = 0
- else:
- if neighbors == 3:
- grid[i][j] = 1
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- if grid[i][j] == 1:
- cv.create_line(i, j, i + 1, j + 1, fill='black')
- else:
- cv.create_line(i, j, i + 1, j + 1, fill='white')
- cv.update()
- Particle System: This algorithm simulates a particle system by randomly generating particles with initial velocities and updating their positions over time according to basic physics principles.
- def particle_system():
- particles = [Particle(random.uniform(-5, 5), random.uniform(-5, 5)) for _ in range(100)]
- while True:
- for particle in particles:
- particle.update()
- cv.create_line(particle.x, particle.y, particle.x + particle.vx, particle.y + particle.vy, fill=random.choice(colors))
- cv.update()
- Sine Wave: This algorithm generates a sine wave by using a sine function to determine the y coordinate of the line.
- import math
- def sine_wave():
- x = 0
- while True:
- y = math.sin(x / 10) * 50 + 50
- cv.create_line(x, y, x, y, fill=random.choice(colors))
- cv.update()
- x += 1
- Rainbow Gradient: This algorithm generates a rainbow gradient by using the hue value of a color to determine the color of the line.
- import colorsys
- def rainbow_gradient():
- x = 0
- while True:
- hue = x / width
- color = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
- color = '#%02x%02x%02x' % (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
- cv.create_line(x, 0, x, height, fill=color)
- cv.update()
- x += 1
- Circular Pattern: This algorithm generates a circular pattern by using polar coordinates to determine the x and y coordinates of the line.
- import math
- def circular_pattern():
- t = 0
- while True:
- r = t / 10
- x = r * math.cos(t) + width / 2
- y = r * math.sin(t) + height / 2
- cv.create_line(x, y, x, y, fill=random.choice(colors))
- cv.update()
- t += 0.1
- Plasma Effect: This algorithm generates a plasma effect by using sine and cosine functions to determine the color of each point on the canvas.
- import colorsys
- def plasma():
- t = 0
- while True:
- for x in range(width):
- for y in range(height):
- hue = (math.sin(x / 10 + t) + math.cos(y / 10 + t)) / 2
- color = colorsys.hsv_to_rgb(hue, 1.0, 1.0)
- color = '#%02x%02x%02x' % (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
- cv.create_line(x, y, x, y, fill=color)
- cv.update()
- t += 0.1
- Spirograph: This algorithm generates a spirograph by drawing circles with different radii and using the parametric equations for a circle to determine the x and y coordinates of the line.
- def spirograph():
- r1 = random.randint(50, 150)
- r2 = random.randint(50, 150)
- p = random.randint(50, 150)
- t = 0
- while t < 360:
- x = (r1 - r2) * math.cos(t) + p * math.cos((r1 - r2) * t / r2)
- y = (r1 - r2) * math.sin(t) - p * math.sin((r1 - r2) * t / r2)
- cv.create_line(x, y, x + 1, y + 1, fill=random.choice(colors))
- t += 0.1
- cv.update()
- L-System: This algorithm generates a fractal pattern using an L-system (Lindenmayer system) by iteratively replacing symbols in a string according to a set of rules.
- def l_system():
- start = "F"
- rules = {"F": "F[+F]F[-F]F"}
- for i in range(5):
- next_str = ""
- for char in start:
- if char in rules:
- next_str += rules[char]
- else:
- next_str += char
- start = next_str
- for char in start:
- if char == "F":
- cv.create_line(x, y, x + 5, y + 5, fill=random.choice(colors))
- x += 5
- y += 5
- elif char == "+":
- x += 5
- elif char == "-":
- y += 5
- cv.update()
- Perlin Noise: This algorithm generates a random, organic-looking pattern using Perlin noise, which is based on interpolating between random gradient vectors.
- def perlin_noise():
- x_offset = random.random()
- y_offset = random.random()
- for x in range(width):
- for y in range(height):
- nx = x / width - 0.5
- ny = y / height - 0.5
- noise = perlin(nx + x_offset, ny + y_offset)
- cv.create_line(x, y, x + 1, y + 1, fill=(noise * 255, noise * 255, noise * 255))
- cv.update()
- Bouncing Ball: This algorithm simulates a bouncing ball by updating the x and y coordinates of the ball based on its velocity and checking for collisions with the edges of the canvas.
- def bouncing_ball():
- x = random.randint(0, width)
- y = random.randint(0, height)
- vx = random.uniform(-5, 5)
- vy = random.uniform(-5, 5)
- while True:
- x += vx
- y += vy
- if x < 0 or x > width:
- vx = -vx
- if y < 0 or y > height:
- vy = -vy
- cv
- .create_line(x, y, x + 1, y + 1, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Mandelbulb: This algorithm generates a 3D fractal known as a Mandelbulb by iterating over a 3D space and using a color map to determine the color of each point based on the number of iterations it takes to escape the set.
- def mandelbulb():
- for x in range(-width, width):
- for y in range(-height, height):
- for z in range(-depth, depth):
- c = complex(x * 4 / width, y * 4 / height, z * 4 / depth)
- z = c
- for i in range(255):
- if abs(z) > 2:
- break
- z = z * z + c
- cv.create_line(x, y, x, y, fill=color_map[i])
- cv.update()
- Particle System: This algorithm simulates a particle system by updating the position and velocity of each particle based on forces such as gravity and air resistance.
- def particle_system():
- particles = []
- for i in range(50):
- particles.append({
- "x": random.uniform(0, width),
- "y": random.uniform(0, height),
- "vx": random.uniform(-5, 5),
- "vy": random.uniform(-5, 5),
- "mass": random.uniform(0.1, 1)
- })
- while True:
- for particle in particles:
- particle["x"] += particle["vx"]
- particle["y"] += particle["vy"]
- particle["vy"] += 0.1 * particle["mass"]
- if particle["x"] < 0 or particle["x"] > width:
- particle["vx"] = -particle["vx"]
- if particle["y"] < 0 or particle["y"] > height:
- particle["vy"] = -particle["vy"]
- cv.create_line(particle["x"], particle["y"], particle["x"] + 1, particle["y"] + 1, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Firework: This algorithm simulates a firework by creating a burst of particles at the starting point and updating their position and velocity based on forces such as gravity and air resistance.
- def firework():
- particles = []
- for i in range(50):
- particles.append({
- "x": random.uniform(0, width),
- "y": random.uniform(0, height),
- "vx": random.uniform(-5, 5),
- "vy": random.uniform(-5, 5),
- "mass": random.uniform(0.1, 1)
- })
- while True:
- for particle in particles:
- particle["x"] += particle["vx"]
- particle["y"] += particle["vy"]
- particle["vy"] += 0.1 * particle["mass"]
- if particle["x"] < 0 or particle["x"] > width:
- particle["vx"] = -particle["vx"]
- if particle["y"] < 0 or particle["y"] > height:
- particle["vy"] = -particle["vy"]
- cv.create_line(particle["x"], particle["y"], particle["x"] + 1, particle["y"] + 1, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Galaxy: This algorithm simulates a galaxy by updating the position and velocity of each star based on the gravitational force of the other stars.
- def galaxy():
- stars = []
- for i in range(50):
- stars.append({
- "x": random.uniform(0, width),
- "y": random.uniform(0, height),
- "vx": random.uniform(-0.5, 0.5),
- "vy": random.uniform(-0.5, 0.5),
- "mass": random.uniform(0.1, 1)
- })
- while True:
- for i, star in enumerate(stars):
- for j, other in enumerate(stars):
- if i == j:
- continue
- dx = other["x"] - star["x"]
- dy = other["y"] - star["y"]
- distance = math.sqrt(dx2 + dy2)
- if distance < 10:
- distance = 10
- force = other["mass"] / (distance**2)
- star["vx"] += dx / distance * force
- star["vy"] += dy / distance * force
- star["x"] += star["vx"]
- star["y"] += star["vy"]
- cv.create_line(star["x"], star["y"], star["x"] + 1, star["y"] + 1, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Shapes: This algorithm generates random shapes by randomly selecting points on the canvas and connecting them with lines.
- def shapes():
- points = []
- for i in range(10):
- points.append((random.randint(0, width), random.randint(0, height)))
- for i, point in enumerate(points):
- for j, other in enumerate(points):
- if i == j:
- continue
- cv.create_line(point[0], point[1], other[0], other[1], fill=random.choice(colors))
- cv.update()
- Kaleidoscope: This algorithm generates a kaleidoscope effect by drawing a pattern and rotating it around the center of the canvas.
- def kaleidoscope():
- angle = 0
- while True:
- for x in range(-width, width):
- for y in range(-height, height):
- nx = x * math.cos(angle) - y * math.sin(angle)
- ny = x * math.sin(angle) + y * math.cos(angle)
- cv.create_line(nx, ny, nx + 1, ny + 1, fill=random.choice(colors))
- angle += 0.01
- cv.update()
- time.sleep(0.01)
- Ray Tracing: This algorithm generates a 3D image by tracing the path of light rays through a 3D scene and determining the color of each pixel based on the objects and lights in the scene.
- def ray_tracing():
- for x in range(width):
- for y in range(height):
- ray_origin = (0, 0, 0)
- ray_direction = (x / width - 0.5, y / height - 0.5, 1)
- intersect, color = trace_ray(ray_origin, ray_direction, objects, lights)
- if intersect:
- cv.create_line(x, y, x + 1, y + 1, fill=color)
- cv.update()
- Perlin Worm: This algorithm generates a curving, organic-looking pattern using Perlin noise, which is based on interpolating between random gradient vectors.
- def perlin_worm():
- x = 0
- y = 0
- t = 0
- while True:
- nx = x / width - 0.5
- ny = y / height - 0.5
- noise = perlin(nx, ny)
- x += math.cos(noise * math.pi * 2)
- y += math.sin(noise * math.pi * 2)
- t += 0.01
- cv.create_line(x, y, x + 1, y + 1, fill=(noise * 255, noise * 255, noise * 255))
- cv.update()
- time.sleep(0.01)
- Flocking: This algorithm simulates the flocking behavior of birds by updating the position and velocity of each bird based on the positions and velocities of its neighbors.
- def flocking():
- birds = []
- for i in range(50):
- birds.append({
- "x": random.uniform(0, width),
- "y": random.uniform(0, height),
- "vx": random.uniform(-5, 5),
- "vy": random.uniform(-5, 5)
- })
- while True:
- for i, bird in enumerate(birds):
- vx = bird["vx"]
- vy = bird["vy"]
- for j, other in enumerate(birds):
- if i == j:
- continue
- dx = other["x"] - bird["x"]
- dy = other["y"] - bird["y"]
- distance = math.sqrt(dx2 + dy2)
- if distance < 10:
- vx += dx / distance
- vy += dy / distance
- bird["vx"] = vx
- bird["vy"] = vy
- bird["x"] += bird["vx"]
- bird["y"] += bird["vy"]
- cv.create_line(bird["x"], bird["y"], bird["x"] + 1, bird["y"] + 1, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Audio Visualization: This algorithm generates a visual representation of an audio signal by using the amplitude of the signal at each point in time to determine the color and height of the line.
- def audio_visualization(audio_data):
- for i, sample in enumerate(audio_data):
- cv.create_line(i, height / 2, i, height / 2 + sample * height / 2, fill=random.choice(colors))
- cv.update()
- Rainbow Lines: This algorithm generates a rainbow effect by gradually changing the color of the lines as they are drawn.
- def rainbow_lines():
- hue = 0
- while True:
- for x in range(width):
- color = colorsys.hsv_to_rgb(hue, 1, 1)
- cv.create_line(x, 0, x, height, fill=color)
- hue += 0.01
- cv.update()
- time.sleep(0.01)
- Plasma: This algorithm generates a plasma effect by using a set of sine waves with different frequencies and amplitudes to determine the color of each pixel.
- def plasma():
- t = 0
- while True:
- for x in range(width):
- for y in range(height):
- color = (
- math.sin(x / 10 + t) + math.sin(y / 10 + t),
- math.sin(x / 20 + t) + math.sin(y / 20 + t),
- math.sin(x / 30 + t) + math.sin(y / 30 + t)
- )
- cv.create_line(x, y, x + 1, y + 1, fill=color)
- t += 0.01
- cv.update()
- time.sleep(0.01)
- Sierpinski Triangle: This algorithm generates a Sierpinski triangle by recursively drawing smaller triangles with alternating colors.
- def sierpinski_triangle(cv, x1, y1, x2, y2, x3, y3, depth):
- if depth:
- cv.create_line(x1, y1, x2, y2, fill=random.choice(colors))
- cv.create_line(x2, y2, x3, y3, fill=random.choice(colors))
- cv.create_line(x3, y3, x1, y1, fill=random.choice(colors))
- sierpinski_triangle(cv, x1, y1, (x1 + x2) / 2, (y1 + y2) / 2, (x1 + x3) / 2, (y1 + y3) / 2, depth - 1)
- sierpinski_triangle(cv, (x1 + x2) / 2, (y1 + y2) / 2, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, depth - 1)
- sierpinski_triangle(cv, (x1 + x3) / 2, (y1 + y3) / 2, (x2 + x3) / 2, (y2 + y3) / 2, x3, y3, depth - 1)
- def draw_sierpinski_triangle():
- sierpinski_triangle(cv, 0, 0, width, 0, width / 2, height, 5)
- cv.update()
- Perlin Noise: This algorithm generates a random, flowing pattern by interpolating between a set of randomly generated control points.
- def perlin_noise():
- control_points = [[random.randint(0, width), random.randint(0, height)] for _ in range(5)]
- for x in range(width):
- for y in range(height):
- color = 0
- for i, (cx, cy) in enumerate(control_points):
- dist = math.sqrt((x - cx) ** 2 + (y - cy) ** 2)
- color += 255 / (i + dist)
- cv.create_line(x, y, x, y, fill=color)
- cv.update()
- Spirograph: This algorithm generates a spirograph by drawing a line that traces the path of a point rotating around a fixed point.
- def spirograph(cv, x, y, r, R, O):
- theta = 0
- while True:
- x1 = (R - r) * math.cos(theta) + O * math.cos((R - r) / r * theta) + x
- y1 = (R - r) * math.sin(theta) - O * math.sin((R - r) / r * theta) + y
- cv.create_line(x, y, x1, y1, fill=random.choice(colors))
- x, y = x1, y1
- theta += 0.1
- cv.update()
- Koch Snowflake: This algorithm generates a Koch snowflake by recursively drawing lines and forming an equilateral triangle.
- def koch_snowflake(cv, x1, y1, x2, y2, depth):
- if depth:
- x3 = (x1 + x2) / 2 + (y2 - y1) / math.sqrt(3)
- y3 = (y1 + y2) / 2 - (x2 - x1) / math.sqrt(3)
- x4 = (x1 + x3) / 2 + (y3 - y1) / 2
- y4 = (y1 + y3) / 2 - (x3 - x1) / 2
- koch_snowflake(cv, x1, y1, x4, y4, depth - 1)
- koch_snowflake(cv, x4, y4, x3, y3, depth - 1)
- koch_snowflake(cv, x3, y3, x2, y2, depth - 1)
- def draw_koch_snowflake():
- cv.create_line(0, height / 2, width / 2, 0, fill='white')
- cv.create_line(width / 2, 0, width, height / 2, fill='white')
- cv.create_line(width, height / 2, width / 2, height, fill='white')
- cv.create_line(width / 2, height, 0, height / 2, fill='white')
- koch_snowflake(cv, 0, height / 2, width / 2, 0, 5)
- koch_snowflake(cv, width / 2, 0, width, height / 2, 5)
- koch_snowflake(cv, width, height / 2, width / 2, height, 5)
- koch_snowflake(cv, width / 2, height, 0, height / 2, 5)
- cv.update()
- Sierpinski Triangle: This algorithm generates a Sierpinski triangle by recursively dividing a triangle into smaller triangles and coloring them according to a predetermined pattern.
- def sierpinski_triangle(cv, x1, y1, x2, y2, x3, y3, depth):
- if depth:
- x4 = (x1 + x2) / 2
- y4 = (y1 + y2) / 2
- x5 = (x2 + x3) / 2
- y5 = (y2 + y3) / 2
- x6 = (x1 + x3) / 2
- y6 = (y1 + y3) / 2
- sierpinski_triangle(cv, x1, y1, x4, y4, x6, y6, depth - 1)
- sierpinski_triangle(cv, x4, y4, x2, y2, x5, y5, depth - 1)
- sierpinski_triangle(cv, x6, y6, x5, y5, x3, y3, depth - 1)
- else:
- cv.create_line(x1, y1, x2, y2, fill='white')
- cv.create_line(x2, y2, x
- Dragon Curve: This algorithm generates a dragon curve by alternating between turning left and right and drawing a line.
- def dragon_curve(cv, x1, y1, x2, y2, depth):
- if depth:
- x3 = x1 + (x2 - x1) / math.sqrt(2)
- y3 = y1 + (y2 - y1) / math.sqrt(2)
- x4 = x1 + (x2 - x1) / 2 - (y2 - y1) / 2
- y4 = y1 + (y2 - y1) / 2 + (x2 - x1) / 2
- dragon_curve(cv, x3, y3, x4, y4, depth - 1)
- dragon_curve(cv, x4, y4, x2, y2, depth - 1)
- else:
- cv.create_line(x1, y1, x2, y2, fill='white')
- def draw_dragon_curve():
- dragon_curve(cv, 0, height / 2, width, height / 2, 10)
- cv.update()
- Julia Set: This algorithm generates a Julia set by iterating over a complex plane and using a color map to determine the color of each point based on the number of iterations it takes to escape the set.
- def julia():
- c = complex(-0.4, 0.6)
- for x in range(-width, width):
- for y in range(-height, height):
- z = complex(x * 4 / width, y * 4 / height)
- for i in range(255):
- if abs(z) > 2:
- break
- z = z * z + c
- cv.create_line(x, y, x, y, fill=color_map[i])
- cv.update()
- Barnsley Fern: This algorithm generates a Barnsley fern by applying a set of rules to a starting point to determine the next point.
- def barnsley_fern():
- x = 0
- y = 0
- for i in range(10000):
- r = random.random()
- if r < 0.01:
- x = 0
- y = 0.16 * y
- elif r < 0.86:
- x = 0.85 * x + 0.04 * y
- y = -0.04 * x + 0.85 * y + 1.6
- elif r < 0.93:
- x = 0.2 * x - 0.26 * y
- y = 0.23 * x + 0.22 * y + 1.6
- else:
- x = -0.15 * x + 0.28 * y
- y = 0.26 * x + 0.24 * y + 0.44
- cv.create_line(x * 10 + width / 2, -y * 10 + height / 2, x * 10 + width / 2, -y * 10 + height / 2, fill='green')
- cv.update()
- Spirograph: This algorithm generates a spirograph by drawing a line that rotates around a fixed point.
- def spirograph(cv, x1, y1, r1, r2, p):
- theta = 0
- while True:
- x2 = (r1 + r2) * math.cos(theta) - p * math.cos((r1 + r2) * theta / r2) + x1
- y2 = (r1 + r2) * math.sin(theta) - p * math.sin((r1 + r2) * theta / r2) + y1
- cv.create_line(x1, y1, x2, y2, fill='red')
- theta += 0.01
- x1 = x2
- y1 = y2
- cv.update()
- def draw_spirograph():
- spirograph(cv, width / 2, height / 2, 100, 50, 50)
- Random Walk: This algorithm generates a random walk by moving a point in a random direction and drawing a line to the new position.
- def random_walk():
- x = width / 2
- y = height / 2
- while True:
- x += random.choice([-1, 0, 1])
- y += random.choice([-1, 0, 1])
- cv.create_line(x, y, x + 1, y + 1, fill='blue')
- cv.update()
- L-System: This algorithm generates a pattern using an L-system by applying a set of rules to a starting string and iteratively replacing characters according to the rules.
- def l_system():
- axiom = 'F'
- rules = {'F': 'F+F-F-F+F'}
- iterations = 5
- for i in range(iterations):
- next_string = ''
- for char in axiom:
- if char in rules:
- next_string += rules[char]
- else:
- next_string += char
- axiom = next_string
- for char in axiom:
- if char == 'F':
- cv.create_line(x, y, x + 1, y, fill='white')
- x += 1
- elif char == '+':
- x, y = y, -x
- elif char == '-':
- x, y = -y, x
- cv.update()
- Percolation: This algorithm simulates percolation by randomly coloring cells and checking if they are connected to a previously colored cell. If they are, they are colored the same color as the connected cell.
- def percolation():
- grid = [[random.choice(colors) for _ in range(width)] for _ in range(height)]
- while True:
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- if grid[i][j] == grid[i-1][j]:
- grid[i][j] = grid[i-1][j]
- elif grid[i][j] == grid[i][j-1]:
- grid[i][j] = grid[i][j-1]
- for i in range(1, width - 1):
- for j in range(1, height - 1):
- cv.create_line(i, j, i + 1, j + 1, fill=grid[i][j])
- cv.update()
- Fireworks Display: This algorithm generates a fireworks display by creating a "rocket" that explodes into a circle of sparks when it reaches the top of the screen.
- import random
- def fireworks():
- x = random.randint(0, width)
- y = height
- vx = random.uniform(-2, 2)
- vy = random.uniform(-10, -5)
- while y > 0:
- cv.create_line(x, y, x, y, fill='red')
- x += vx
- y += vy
- vy += 0.5
- cv.update()
- time.sleep(0.01)
- for i in range(360):
- cv.create_line(x, y, x + math.cos(i) * 20, y + math.sin(i) * 20, fill=random.choice(colors))
- cv.update()
- time.sleep(0.01)
- Spirograph: This algorithm generates a spirograph by drawing a series of circles with decreasing radii and alternating colors.
- import math
- def spirograph():
- for i in range(360):
- cv.create_line(width / 2, height / 2, width / 2 + math.cos(i) * radius, height / 2 + math.sin(i) * radius, fill=random.choice(colors))
- radius -= 1
- cv.update()
- time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement