Python Art using Turtle Graphics Library and Random Module

Diamond Tusks
3 min readAug 2, 2022

--

I have recently decided to partake in the #100daysofcode challenge to push myself to code everyday.

I’m up to Day 32 of the challenge. I have several reasons for wanting to start this, but mainly its to build momentum with my learning.

Over the last year I’ve picked up coding and dropped it a few times.

I tried different languages, even invested some of this time in Haskell and Plutus. I created a Cardano test node, made, minted and sent Cardano NFTs using the command line.

However, 32days ago I decided to commit to Python. Soon I want to start with the Boto3 library as I am also learning AWS, and pick up solidity again to use with Python. Blockchain is where my real passion is, it’s what brought me back to tech and got me coding.

I am writing because I want to share some of what I’ve been learning. By writing and talking about it hopefully I’ll learn more. I hope it can also inspire, motivate or help others who are on the fence or procrastinating.

Today I want to share a couple of exercises I recently completed. Having an interest in NFT and block arts this was exciting and quite satisfying.

It uses the Turtle Graphics library to create the graphics and the random module to add random movements and random colours. I wanted to share this because it shows how powerful these tools are and can be.

Below is a random walk program. Every time the program runs the turtle walks in random directions. It can either go left, right, forward or backwards. It also paints its track a random colour every time it moves.

The colours are not selected from list of colours, the program literally chooses a random intensity for red, green and blue to create a colour. For those that didn’t know, you can pretty much create any colour by combining the primary colours(red, green and blue) in different intensities. This is called the RGB colour model.

Random Walk using Turtle Graphics library

Here is a spirograph with each circle also made with random colours. The user can enter a number which determines the angle/gap between the circles, the program automatically calculates how many circles are required to go around and complete the spirograph. This one has a function which will return a random colour.

Spirograph using Turtle Graphic library

This is so much fun. I have also just completed a take on the paintings by Damien Hirst.

Using one of his paintings, I used library a called Colorgram to create a palette of colours to randomly choose colours from. Then using Python and the Turtle library to create random dots from the palette. As you can see below, it looks just like a Damien Hirst.

I hope to share more of these soon!

--

--

Diamond Tusks
Diamond Tusks

Written by Diamond Tusks

0 Followers

Crypto Native © 2013 | Trader | Farmer | Collector | Decided to become a developer, documenting my journey here.

No responses yet