ART WITH PYTHON

by HAT1412 in Craft > Digital Graphics

2062 Views, 5 Favorites, 0 Comments

ART WITH PYTHON

pattern.png

The turtle library is really useful if you want you to create beautiful patterns in python and it is very simple.

Now for those who know the basic's you can get to the next step where I'll explain the basics of Turtle and show you how to make some amazing patterns

WRITING CODE

square.png
code.png
red_square.png
final.png

Now where should I code ?

You can code in any python editor whether Jupyter or VS Code or even the python IDE

First type or copy/paste the following code and run it.

from turtle import *

s = Screen()

t = Turtle()

for i in range(4):

t.forward(30)

t.right(90)

t.forward(30)

mainloop()

from turtle import * : imports all functions from the turtle module

s = Screen() : Creates a screen on which the turtle will draw

t = Turtle() : Creates an object “t” which will draw for you

for i in range(4): Runs the following code 4 times

t.forward(30) : Makes the turtle move 30 cm Forward

t.right(90) : Makes the turtle take a 90 degree right turn

t.forward(30) : Makes the turtle move 30 cm Forward

mainloop():stops your window from crashing

IF YOU GET A TERMINATOR ERROR JUST RERUN THE CODE AND IT SHOULD WORK

you can change the color of the lines by using

t.color(“red”)


You can tweak a few things in the code to make amazing designs

So here is one example in which I use the random library to randomly choose a color for the turtle and use t.cicle() to draw a perfect circle

from turtle import *

import random

s = Screen()

t = Turtle()

t.speed(0)

color = ["red","blue","green","black"]

for i in range(199):

t.color(random.choice(color))

t.forward(2)

t.right(90)

t.circle(i)

mainloop()




LET ME KNOW WHAT U ALL MADE BY UPLOADING THE PHOTO OF YOUR CODE OR YOUR CREATION IN THE COMMENTS