baabtra.com little coder chapter - 4

21
L i t t l e C o d e r P r o g r a m by

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 15-Jul-2015

305 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Baabtra.com little coder   chapter - 4

Little Coder Program

by

Page 2: Baabtra.com little coder   chapter - 4

Drawing with TurtlesChapter 4

Page 3: Baabtra.com little coder   chapter - 4

Turtle in python

• A module in Python is a way of providing useful code to be used by another

program. We’ll learn more about modules later on.

• Python has a special module called turtle that we can use to learn how

computers draw pictures on a screen.

• In the world of Python, a turtle is a small, black arrow that moves slowly

around the screen

Turtle in real world Turtle in Python

Page 4: Baabtra.com little coder   chapter - 4

Lets start drawing by turtle module

Page 5: Baabtra.com little coder   chapter - 4

>>> import turtleWe are asking python to import a

module named ‘turtle’ so that we

can use the functions and variables

written inside it

Page 6: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()we need to create a

Canvas - a blank space to draw on,

like an artist’s canvas. To do so,

we call the function Pen from the

turtle module, which automatically

creates a canvas.

Page 7: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(500)

The forward instruction tells the

turtle to move forwardby 50 pixels,.

Page 8: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(500)

>>>t.left(90)

The left() will turn the turtle 90

degree

Page 9: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

Page 10: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

Page 11: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

Page 12: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

Page 13: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

Page 14: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

Yaay !! You have successfully drawn a square !!

Page 15: Baabtra.com little coder   chapter - 4

>>> import turtle

>>> t = turtle.Pen()

>>> t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.left(90)

>>>t.forward(50)

>>>t.reset()

Reset function will erase your drawing and

set the turtle to the initial position

Page 16: Baabtra.com little coder   chapter - 4

>>>t.reset()

>>>t.right(120)

>>>t.forward(50)

You can use the right function similar

to left

Page 17: Baabtra.com little coder   chapter - 4

>>>t.reset()

>>>t.right(120)

>>>t.forward(50)

>>>t.backward(100)

Backward function act just in the

opposite direction of forward

Page 18: Baabtra.com little coder   chapter - 4

>>>t.reset()

>>>t.right(120)

>>>t.forward(50)

>>>t.backward(100)

>>>t.left(60)

>>>t.up()

>>> t.forward(50)

>>> t.down()

>>> t.forward(100)

We can use up to lift the pen off the

page (in other words, tell the turtle to

stop drawing), and down to start

drawing.

Page 19: Baabtra.com little coder   chapter - 4

Exercise !

Page 20: Baabtra.com little coder   chapter - 4

Exercise !

Page 21: Baabtra.com little coder   chapter - 4

End of Chapter 4