Skip to content

Commit 82d486b

Browse files
Merge pull request avinashkranjan#776 from ricsin23/Codes-on-Turtle-Graphics
Codes on turtle graphics
2 parents 4769957 + 06a3c90 commit 82d486b

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import turtle as t
2+
import time as ti
3+
4+
def rectangle(hor,ver,col):
5+
t.pendown() # to create a canvas for drawing
6+
t.pensize(1) # size of pen
7+
t.color(col)
8+
t.begin_fill()
9+
for counter in range(1,3):
10+
t.forward(hor)
11+
t.right(90) #move 90 degree right
12+
t.forward(ver)
13+
t.right(90)
14+
t.end_fill()
15+
t.penup()
16+
17+
t.penup()
18+
t.speed('slow')
19+
t.bgcolor('Dodger blue') # give background color
20+
21+
t.goto(-100,-150) # move the turtle to given coordinates
22+
rectangle(50,20,'blue') # create a rectangle of given size
23+
t.goto(-30,-150)
24+
rectangle(50,20,'blue')
25+
26+
t.goto(-25,-50)
27+
rectangle(15,100,'grey')
28+
t.goto(-55,-50)
29+
rectangle(-15,100,'grey')
30+
31+
t.goto(-90,100)
32+
rectangle(100,150,'skyblue')
33+
34+
t.goto(-150,70)
35+
rectangle(60,15,'grey')
36+
t.goto(-150,110)
37+
rectangle(15,40,'grey')
38+
t.goto(10,70)
39+
rectangle(60,15,'grey')
40+
t.goto(55,110)
41+
rectangle(15,40,'grey')
42+
43+
t.goto(-50,120)
44+
rectangle(15,20,'grey')
45+
t.goto(-85,170)
46+
rectangle(80,50,'red')
47+
t.goto(-60,160)
48+
rectangle(30,10,'white')
49+
t.goto(-55,155)
50+
rectangle(5,5,'black')
51+
t.goto(-40,155)
52+
rectangle(5,5,'black')
53+
t.goto(-65,138)
54+
rectangle(40,5,'black')
55+
56+
ti.sleep(10)
57+
58+
t.hideturtle()
36.9 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import turtle as t
2+
import time as ti
3+
from itertools import cycle
4+
5+
colors = cycle(['red','orange','yellow','blue','green','purple']) # create circles and squares of different colors
6+
7+
def draw_circle(size,angle,shift,shape):
8+
t.pencolor(next(colors))
9+
next_shape = ''
10+
if shape == 'circle':
11+
t.circle(size)
12+
next_shape = 'square' # draw next shape as square after circle
13+
elif shape == 'square':
14+
for i in range(4):
15+
t.forward(size * 2)
16+
t.left(90)
17+
next_shape = 'circle'
18+
t.right(angle)
19+
t.forward(shift)
20+
draw_circle(size + 5,angle+1,shift+1,next_shape)
21+
22+
t.bgcolor('black')
23+
t.speed('fast') # to create the figure fastly
24+
t.pensize(4)
25+
26+
draw_circle(5,0,1,'circle')
27+
28+
ti.sleep(3)
29+
t.hideturtle()

Codes on Turtle Graphics/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Codes on Turtle Graphics
2+
3+
_turtle_ is a pre installed library in Python that enables us to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that we use to draw
4+
is called turtle.
5+
6+
## Requirements
7+
### 1. Python Environment:
8+
Use applications like Python IDLE or Jupyter Notebook.
9+
### 2. Python Version:
10+
Ensure you have version 3 of Python.
11+
12+
With the turtle library of Python, we can draw several shapes and figures. Here's two samples we can create with turtles's library.
13+
14+
## 1. Animated Robot
15+
This is a simple figure we can create to understand basics of turtle graphics.
16+
<img src="Robot.png" width="350" height="250" />
17+
18+
## 2. Kaleido Spiral
19+
In this, we will draw circles and squares in continuation. Everytime we will change the radius of circle and side dimension of square to make it look like a expanding squares and circles.
20+
<img src="Kaleido-spiral.png" width="350" height="250" />

Codes on Turtle Graphics/Robot.png

4.85 KB
Loading

0 commit comments

Comments
 (0)