Skip to main content

Pi is beautiful


Continuing from my last blog post : I watched this video called "Pi is beautiful" and it inspired me to create my own pi art. With the help of my friend Bard I was able to get python code (or should I write pithon code) to get the job done. I sort of see a 9 as highlighted in the image above with gray pen tool. I used pydroid on my mobile and I had to correct a few errors in the code with Bard.

This was my prompt:

Take the first 1000 pi digits and create x,y coordinates with the adjacent digits and create a colorful visualisation with the coordinates. Increment the size and color everytime we land on a coordinate.

This was the code:

import matplotlib.pyplot as plt
import math

from PIL import Image
import io

# Get the first 1000 digits of pi
pi_digits = "141592..."

# Create coordinates and track frequencies
coordinates = []
frequency_map = {}  # Use a dictionary to track frequencies efficiently
for i in range(0, len(pi_digits) - 1, 2):
    pair = (int(pi_digits[i]), int(pi_digits[i + 1]))
    coordinates.append(pair)
    frequency_map[pair] = frequency_map.get(pair, 0) + 1000  # Increment frequency

# Create the scatter plot with size and colors based on frequencies
plt.figure(figsize=(10, 6))
plt.scatter(*zip(*coordinates), s=[frequency_map[pair] for pair in coordinates],
            c=[frequency_map[pair] for pair in coordinates], cmap='viridis')

# Add labels and title
plt.xlabel("X-coordinates from Pi Digits")
plt.ylabel("Y-coordinates from Pi Digits")
plt.title("Scatter Plot of Pi Digits with Size and Color by Frequency")

# Show the plot
plt.show()

Comments

Popular posts from this blog

Cup of coffee

This is a chapter from my latest book called Breezes of Tobago . The cool morning breeze blew the hat off the tourist passing the coffee shop. We sat at the table waiting for our order of coffee and bagels. I had stayed up late writing and was now needing caffeine to stay awake. On entering the veranda of the coffee shop, the sign reads "happiness is a cup of coffee" and "sip your troubles away". This had me thinking about what is happiness? And was the theme of my chat with Chatty as we enjoyed our breakfast in Tobago. I told my friend Chatty that if we could put happiness in a bottle and sell it we would be rich. My friend Chatty then told me that money cannot buy happiness but it was a good idea to make a living. If according to the sign, happiness is a cup of coffee then maybe happiness is coffee in a bottle then. We could call it Caffibean, a taste of the Caribbean in Tobago, a blend of the happiest coffee beans from Tobago. Tobago is not known for its coffee p...

Sandy beaches

This is a chapter from my latest book called Breezes of Tobago . This story begins on a cool Friday evening in May. Fridays are the best days. Already a great start. It had rained earlier in the day and the clouds were moving away and the sun peeking through. I walked from the apartment where I was staying to Pigeon Point beach. Along the way I stopped for coconut water freshly extracted from the nut and straight into my mouth leaving traces on my cotton jersey. They say that coconut water is the drink of God—fresh from the nut, sweet with a hint of salt, a liquid reminder that paradise can exist in small and simple things. They did not say that but my friend Chatty did. It is my friend Chatty's first trip to Tobago. I asked him what he thinks of Tobago so far? He grinned, wiping a drop of coconut water from the corner of his mouth. "Man… it is like stepping into a painting. The air, the colors, the way everything smells after the rain—it is unreal. I did not know paradise cam...

Under the lights

This is a chapter from my latest book called Breezes of Tobago . Today we stumbled upon a game of night football at the recreational ground. There was a red card and a penalty. Somehow the striker was able to bend the ball into the corner of the net and with what looked to me like help from a strong breeze. I was a neutral supporter and was just waiting for goals to be scored. Tobago has produced the famous Man United player in Dwight Yorke. My friend Chatty says that there is something special about local football where the breeze, the crowd noise, and pure instinct all become part of the play. Maybe we are here watching the next Dwight Yorke in the making, his story just beginning to unfold under the lights. Maybe the next famous Tobagonian footballer will play for the noisy neighbors of Man City. I spoke to a young lad selling juices from a cooler and he had to agree. He wiped his hands on his shorts and looked out at the pitch with a seriousness beyond his years. The ice clinked in...