Sketch project in python with source code

Sketch project in python with source code

Introduction

A sketch project is a drawing project using python turtle library. This app can useful for creating different objects and shapes on screen.

Turtle is an inbuilt module in python that is mostly useful for creating graphics. In this project, we are creating a sketching app using turtle graphics with simple logic. The project allows you to use keys from your keyboard to draw on the screen. Such as A, S, W and D keys.

We use the python turtle library for this project. We use functions for moving the cursor and creating. We use screen.listen() to apply functionality on the screen. Download the project and get experienced by yourself. See the code and output below how the project looks like.

from turtle import Turtle, Screen
tin = Turtle()
screen = Screen()

def move_forward():
    tin.forward(10)

def move_backward():
    tin.backward(10)

def turn_left():
    new_heading = tin.heading() + 10
    tin.setheading(new_heading)

def turn_right():
    new_heading = tin.heading() - 10
    tin.setheading(new_heading)

def clear():
    tin.clear()
    tin.penup()
    tin.home()
    tin.pendown()

screen.listen()
screen.onkey(move_forward, "w")
screen.onkey(move_backward, "s")
screen.onkey(turn_left, "a")
screen.onkey(turn_right, "d")

screen.exitonclick()
screen = Screen()

output:

sketch project

How to use this sketch project?

  • Copy the source code and paste in your editor or IDE. (pycharm, anaconda)
  • Execute the project.
  • Sketch your shapes and objects.
  • Enjoy and share