Galactic Flower Python Turtle Mini Project with Source Code

Introduction

The Logo programming language is frequently linked to turtle graphics. In the late 1960s, Seymour Papert added turtle graphics support to Logo to support his version of the turtle robot, which is a simple robot controlled from the user’s workstation and designed to carry out the drawing functions assigned to it using a small retractable pen set into or attached to the robot’s body.

The standard library of the Python programming language now contains a Turtle graphics module. Turtle in Python, like its Logo ancestor, allows programmers to manipulate one or more turtles in a two-dimensional space.

Overview of the syntax

A location, an orientation (or direction), and a pen are the three qualities of the turtle. Color, width, and on/off state are all properties of the pen (also called down and up).

“Move ahead 10 spaces” and “turn left 90 degrees” are orders that the turtle responds to based on its current location. The turtle’s pen can also be managed by enabling it, changing its color, and adjusting its breadth. By visualizing what they would do if they were the turtle, a pupil may comprehend (and forecast and reason about) the turtle’s motion. This is referred to as “body syntonic” reasoning by Seymour Papert.

Basic syntax:

import turtle // start of the program
     //body
    //of the main
   //code
turtle.done() //end of the program

Inorder to understand the codes to draw various shapes given below, Getting Started with Powerful yet Easy Python Graphics Module, Turtle.

Methods

A Python method is a label that can be applied to an object and is a piece of code that may be run on that object.

The most frequently, used turtle methods are:

MethodParameterDescription
Turtle()NoneCreates and returns a new turtle object
forward()amountMoves the turtle forward by the specified amount
backward()amountMoves the turtle backward by the specified amount
right()angleTurns the turtle clockwise
left()angleTurns the turtle counterclockwise
penup()NonePicks up the turtle’s Pen
pendown()NonePuts down the turtle’s Pen
up()NonePicks up the turtle’s Pen
down()NonePuts down the turtle’s Pen
color()Color nameChanges the color of the turtle’s pen
fillcolor()Color nameChanges the color of the turtle will use to fill a polygon
heading()NoneReturns the current heading
position()NoneReturns the current position
goto()x, yMove the turtle to position x,y
begin_fill()NoneRemember the starting point for a filled polygon
end_fill()NoneClose the polygon and fill with the current fill color
dot()NoneLeave the dot at the current position
stamp()NoneLeaves an impression of a turtle shape at the current location
shape()shapenameShould be ‘arrow’, ‘classic’, ‘turtle’ or ‘circle’

Galactic Flower Mini Project

The principles governs everything in every subject. They’re the basis on which all incredible exploits are built. To execute acts that appear magical to us simple humans, great scientists and artists equally rely on their most basic skills. Same is the case for python turtle module.

In order to draw any shapes using python turtle, for this instance what we call a galactic flower, the fundamentals are mandatory. If you really think about it our galactic flower is basically circles( of various shapes and color) drawn in a non overlapping way.

Explanation

  • Import turtle module.
import turtle
  • Make a turtle screen and give it a background color of your choice, in this instance we take a black background color.
window = turtle.Screen()
window.bgcolor('black')
window.title("Galactic Flower made for Follow Tutorials")
  • Make a turtle object and give it preferred speed and color, in this instance we take color as white and speed as 2.
galatic = turtle.Turtle()
galatic.speed(2)
galatic.color('white')
  • Assigning 180 as an integer to rotate.
rotate=int(180)
  • Define Circles function
def Circles(t,size):
    for i in range(10):
        t.circle(size)
        size=size-4
  • Define drawCricles function
def drawCircles(t,size,repeat):
  for i in range (repeat):
    Circles(t,size)
    t.right(360/repeat)
  • Now if you look at the remaining source code you can easily understand and decipher it’s purpose and meaning. Happy Learning!

Source Code

Below is the source code for galactic flower made using python turtle module.

import turtle
window = turtle.Screen()
window.bgcolor('black')
window.title("Galactic Flower made for Follow Tutorials")
galatic = turtle.Turtle()
galatic.speed(2)
galatic.color('white')
rotate=int(180)
def Circles(t,size):
    for i in range(10):
        t.circle(size)
        size=size-4
def drawCircles(t,size,repeat):
  for i in range (repeat):
    Circles(t,size)
    t.right(360/repeat)
drawCircles(galatic,200,10)
t1 = turtle.Turtle()
t1.speed(0)
t1.color('yellow')
rotate=int(90)
def Circles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-10
def drawCircles(t,size,repeat):
    for i in range (repeat):
        Circles(t,size)
        t.right(360/repeat)
drawCircles(t1,160,10)
t2= turtle.Turtle()
t2.speed(0)
t2.color('blue')
rotate=int(80)
def Circles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-5
def drawCircles(t,size,repeat):
    for i in range (repeat):
        Circles(t,size)
        t.right(360/repeat)
drawCircles(t2,120,10)
t3 = turtle.Turtle()
t3.speed(0)
t3.color('red')
rotate=int(90)
def Circles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-19
def drawCircles(t,size,repeat):
    for i in range (repeat):
        Circles(t,size)
        t.right(360/repeat)
drawCircles(t3,80,10)
t4= turtle.Turtle()
t4.speed(0)
t4.color('green')

rotate=int(90)
def Circles(t,size):
    for i in range(4):
        t.circle(size)
        size=size-20
def drawCircles(t,size,repeat):
    for i in range (repeat):
        Circles(t,size)
        t.right(360/repeat)
drawCircles(t4,40,10)

turtle.done()

Output

The following is the output for the given code above:

You may also Like

SHARE Galactic Flower Python Turtle Mini Project with Source Code

You may also like...

Leave a Reply

Your email address will not be published.

Share