0% found this document useful (0 votes)
21 views8 pages

Exp 9

The document outlines a series of graphics design projects using Python's Turtle module, including creating scalable geometric patterns, rotating shape animations, recursive spiral designs, color filter effects, and multi-layered artistic designs. Each project includes a clear aim, step-by-step algorithms, and source code to implement the designs. The document confirms successful execution of all programs.

Uploaded by

beninprayerson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views8 pages

Exp 9

The document outlines a series of graphics design projects using Python's Turtle module, including creating scalable geometric patterns, rotating shape animations, recursive spiral designs, color filter effects, and multi-layered artistic designs. Each project includes a clear aim, step-by-step algorithms, and source code to implement the designs. The document confirms successful execution of all programs.

Uploaded by

beninprayerson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Exp No:9 GRAPHICS DESIGN USING TURTLE AND IMAGE

PROCESSING
Date 19.03.2025

1. Create a Scalable Geometric Pattern – Develop a program that draws a geometric pattern
that increases in size dynamically while maintaining proportionality.

AIM: To create graphical designs, shapes, and artistic patterns using Python's Turtle

ALGORITHMS:
Step1: Import Required Modules
●​ Import the turtle module for graphics.
●​ Import math if needed for calculations.
Step2: Initialize the Screen and Turtle
●​ Create a turtle.Screen() window and set its size and title.
●​ Initialize a turtle.Turtle() object and set its speed.
Step3: Define Function to Draw the Pattern
●​ Clear the screen to remove previous drawings.
●​ Move the turtle to the starting position.
●​ Set the number of sides (e.g., hexagon with 6 sides).
●​ Loop through each side:
o​ Move forward by a scaled length.
o​ Turn by an appropriate angle.
●​ Optionally, draw concentric hexagons by looping multiple times.
Step4: Define Functions to Scale the Pattern
●​ Increase Size:
o​ Increase the scaling factor.
o​ Redraw the pattern with the updated size.
●​ Decrease Size:
o​ Ensure the size does not go below a minimum limit.
o​ Decrease the scaling factor.
o​ Redraw the pattern.
Step5: Set Up Keyboard Controls
●​ Listen for key presses using screen.onkey().
●​ Assign the "Up" arrow key to increase size.
●​ Assign the "Down" arrow key to decrease size.
Step6: Run the Program
●​ Call turtle.tracer(0, 0) for smooth rendering.
●​ Draw the initial pattern.
●​ Enable key listenin

SOURCE CODE:
import turtle
import math
screen = turtle.Screen()
screen.title("Scalable Geometric Pattern")
screen.setup(width=600, height=600)
pen = turtle.Turtle()
pen.speed(0)
def draw_pattern(scale=1):
pen.clear()
pen.penup()
pen.goto(-50 * scale, 0)
pen.pendown()
num_sides = 6
radius = 50 * scale
angle = 360 / num_sides
for _ in range(num_sides):
pen.forward(radius)
pen.right(angle)
for i in range(1, 4):
pen.penup()
pen.goto(-50 * scale * i, 0)
pen.pendown()
for _ in range(num_sides):
pen.forward(radius * i)
pen.right(angle)
def increase_size():
global scale_factor
scale_factor += 0.2
draw_pattern(scale_factor)
def decrease_size():
global scale_factor
if scale_factor > 0.4:
scale_factor -= 0.2
draw_pattern(scale_factor)
turtle.tracer(0, 0)
scale_factor = 1
draw_pattern(scale_factor)
turtle.tracer(1, 1)
screen.listen()
screen.onkey(increase_size, "Up")
screen.onkey(decrease_size, "Down")
screen.mainloop()

OUTPUT:
RESULT: The program has been executed successfully.
2. Design a Rotating Shape Animation – Write a program to draw a polygon and rotate it
incrementally around a central point to form a circular pattern.

AIM: To create graphical designs, shapes, and artistic patterns using Python's Turtle
ALGORITHMS :
Step1: Import Required Modules
●​ Import the turtle module for graphics.
●​ Import math if needed for calculations.
Step2: Initialize the Screen and Turtle
●​ Create a turtle.Screen() window and set its size and title.
●​ Initialize a turtle.Turtle() object and set its speed.
●​ Hide the turtle for a smoother animation.
Step3: Define Function to Draw a Polygon
●​ Move the turtle to the starting position.
●​ Set the number of sides for the polygon (e.g., hexagon with 6 sides).
●​ Calculate the exterior angle (360 / sides).
●​ Rotate the shape by an angle_offset to achieve the animation effect.
●​ Draw the polygon by looping through its sides.
●​ Reset the rotation angle after drawing.
Step4: Define Animation Function
●​ Clear the previous frame to avoid overlapping shapes.
●​ Call the draw_polygon() function with an incrementing rotation angle.
●​ Increase the rotation angle gradually for smooth motion.
●​ Use screen.ontimer(animate, delay) to repeatedly call the function for continuous animation.
Step5: Start the Animation
●​ Set the initial rotation angle to 0.
●​ Call the animate() function to begin the rotation.
●​ Use screen.mainloop() to keep the window open and responsive.

SOURCE CODE:
import turtle
import math
screen = turtle.Screen()
screen.title("Rotating Shape Animation")
screen.setup(width=600, height=600)
pen = turtle.Turtle()
pen.speed(0)
pen.hideturtle()

def draw_polygon(sides, size, angle_offset):


pen.penup()
pen.goto(0, 0)
pen.pendown()
angle = 360 / sides
pen.right(angle_offset)
for _ in range(sides):
pen.forward(size)
pen.right(angle)
pen.left(angle_offset)
def animate():
global rotation_angle
pen.clear()
draw_polygon(6, 100, rotation_angle)
rotation_angle += 10
screen.ontimer(animate, 100)
rotation_angle = 0
animate()
screen.mainloop()

OUTPUT:

RESULT: The program has been executed successfully.

3. Implement a Recursive Spiral Design – Create a recursive function to generate a spiral


pattern using a series of connected lines or circles that increase in size.

AIM: To create graphical designs, shapes, and artistic patterns using Python's Turtle.

ALGORITHMS:
Step1: Import Required Module
●​ Import the turtle module for graphical drawing.
Step2: Initialize the Turtle Screen
●​ Create a turtle.Screen() window.
●​ Set the window title to "Recursive Spiral Design".
Step3: Initialize the Turtle
●​ Create a turtle.Turtle() object.
●​ Set the drawing speed to the fastest mode (speed(0)).
●​ Set the turtle’s color (e.g., blue).
Step4: Define a Recursive Function (draw_spiral)
●​ Base Case: If the recursion depth reaches zero, stop drawing and return.
●​ Recursive Step:
o​ Move the turtle forward by the given size.
o​ Turn the turtle by a fixed angle.
o​ Call draw_spiral again with an increased size and reduced depth.
Step5: Call the Recursive Function
●​ Start with an initial size, angle, and recursion depth.
●​ Example: draw_spiral(10, 30, 100), where:
o​ 10 is the starting size of each step.
o​ 30 is the turning angle.
o​ 100 is the number of recursive steps.
Step6: Keep the Window Open
●​ Use screen.mainloop() to ensure the window remains open after execution.

SOURCE CODE:
import turtle
screen = turtle.Screen()
screen.title("Recursive Spiral Design")

pen = turtle.Turtle()
pen.speed(0)
pen.color("blue")
def draw_spiral(size, angle, depth):
if depth == 0:
return
pen.forward(size)
pen.right(angle)
draw_spiral(size + 2, angle, depth - 1)
draw_spiral(10, 30, 100)
screen.mainloop()
OUTPUT:

RESULT: The program has been executed successfully.

4. Simulate a Color Filter Effect – Develop a program that draws multiple overlapping shapes
with varying colors and opacities to create a blended visual effect.

AIM: To create graphical designs, shapes, and artistic patterns using Python's Turtle.

ALGORITHMS:

Step1: Import Required Modules


●​ Import turtle for graphical drawing.
●​ Import random for generating random positions, colors, and sizes.
Step2: Initialize the Turtle Screen
●​ Create a turtle.Screen() window.
●​ Set the window title as "Color Filter Effect".
●​ Set the background color (e.g., black).
Step3: Initialize the Turtle
●​ Create a turtle.Turtle() object.
●​ Set the turtle’s speed to the fastest mode (speed(0)).
●​ Hide the turtle for better visual effects.
●​ Define a list of colors to use for drawing.
Step4: Define a Function to Draw a Shape
●​ Move the turtle to a random (x, y) position.
●​ Select a random number of sides for the polygon (e.g., triangle, square, pentagon).
●​ Pick a random color.
●​ Use begin_fill() to fill the shape with the selected color.
●​ Loop through the sides to draw the polygon with equal angles.
●​ Use end_fill() to complete the shape.
Step5: Draw Multiple Overlapping Shapes
●​ Loop a fixed number of times (e.g., 20 times) to draw multiple shapes.
●​ Randomly determine the size, shape, and position for each iteration.
●​ Call the draw_shape() function with random parameters.
Step6: Keep the Window Open
●​ Use screen.mainloop() to keep the graphics window open.

SOURCE CODE:
import turtle
import random
screen = turtle.Screen()
screen.title("Color Filter Effect")
screen.bgcolor("black")
pen = turtle.Turtle()
pen.speed(0)
pen.hideturtle()
colors = ["red", "blue", "green", "yellow", "purple", "orange", "cyan", "magenta"]

def draw_shape(size, sides, x, y, color):


pen.penup()
pen.goto(x, y)
pen.pendown()
pen.color(color)
pen.begin_fill()
angle = 360 / sides
for _ in range(sides):
pen.forward(size)
pen.right(angle)
pen.end_fill()
for _ in range(20):
size = random.randint(30, 100)
sides = random.choice([3, 4, 5, 6, 8])
x = random.randint(-200, 200)
y = random.randint(-200, 200)
color = random.choice(colors)
draw_shape(size, sides, x, y, color)
screen.mainloop()

OUTPUT:
RESULT: The program has been executed successfully.

5. Create a Multi-Layered Artistic Design – Design a complex pattern using a combination


of scaling, rotation, and recursion to generate a visually appealing symmetric structure.

AIM: To create graphical designs, shapes, and artistic patterns using Python's Turtle.

ALGORITHMS:
Step1: Import Required Modules
●​ Import turtle for graphics.
●​ Import math if needed for calculations.
Step2: Initialize the Turtle Screen
●​ Create a turtle.Screen() window.
●​ Set the background color (e.g., black).
●​ Set the window title as "Multi-Layered Artistic Design".
Step3: Initialize the Turtle
●​ Create a turtle.Turtle() object.
●​ Set the drawing speed to the fastest (speed(0)).
●​ Hide the turtle for better visual effects.
●​ Set the turtle’s color (e.g., white).
Step4: Define a Recursive Function (draw_pattern)
●​ Base Case: If the recursion depth reaches zero, stop drawing and return.
●​ Recursive Step:
o​ Loop through a symmetric shape (e.g., hexagon with 6 sides).
o​ Move forward by the given size.
o​ Recursively call draw_pattern() with a reduced size and decreased recursion depth.
o​ Move back to the starting position.
o​ Rotate the turtle for the next segment (e.g., by 60 degrees for hexagonal symmetry).
Step5: Define Function to Create the Overall Design (create_design)
●​ Move the turtle to an appropriate starting position.
●​ Call draw_pattern() with an initial size and recursion depth (e.g., draw_pattern(100, 4)).
Step6: Call the create_design Function to Start Drawing
●​ Generate the multi-layered pattern dynamically.
Step7: Keep the Window Open
●​ Use screen.mainloop() to ensure the drawing window remains open.

SOURCE CODE:

import turtle
import math
screen = turtle.Screen()
screen.title("Multi-Layered Artistic Design")
screen.bgcolor("black")
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.hideturtle()

def draw_pattern(size, depth):


if depth == 0:
return
for _ in range(6):
pen.forward(size)
draw_pattern(size / 2, depth - 1)
pen.backward(size)
pen.right(60)

def create_design():
pen.penup()
pen.goto(0, -200)
pen.pendown()
draw_pattern(100, 4)
create_design()
screen.mainloop()

OUTPUT:

RESULT: The program has been executed successfully.

You might also like