Friday, July 27, 2012

Creating a background image for this blog

So, for whatever reason, I have decided to start a blog.  I wanted to create my own background image here, but I didn't know where to start.  Eventually I hit on the idea of putting together a series of Spirograph-type images and using it as a background.

As I am currently learning Python, I thought that this would be a good programming exercise.  I Googled for a while and decided on using a rose curve.

After playing around a while with the output in Photoshop, I settled on what's currently in the background.

If you're curious, the Python code is below.  To generate it image, I took the rose curve from the code below, layered it on itself many times, adjusted the color, applied some Gaussian blur, and then resized.

import matplotlib.pyplot as plt
import numpy as np

###############################################################
def rose1(angle,a,n,d):
    r=1+(a*np.cos((n/d)*angle))
    return(r)
#############################################################

print("\nEquation is of the form:")
print("For phi in (0,2*D*pi): r=1+(A*(cos((N/D)phi))")
print("N and D should be relatively prime whole numbers.")

A=float(raw_input("\nWhat do you want A to be? "))
N=float(raw_input("What do you want N to be? "))
D=float(raw_input("What do you want D to be? "))

theta=np.arange(0,2*D*3.14159265359,0.005)
r=rose1(theta,A,N,D)

x=r*np.cos(theta)
y=r*np.sin(theta)

fig1=plt.figure(figsize=(15,15))
sub1=fig1.add_subplot(111,frameon=False,aspect='equal')
sub1.plot(x,y)
sub1.tick_params(axis='both',which='both',length=0, width=0, labelbottom=False,labeltop=False,labelleft=False,labelright=False)
plt.show()



This code creates a rose curve without any axes or grid marks, making it much easier to copy into Photoshop (sample output below):  



All of this can probably be coded much more efficiently, but this version worked for my purposes.