A potential employer asked me to code up a quick Android application as a challenge. I enjoyed doing it, but in the course of building it I discovered, surprisingly, that “image loading” spinner art was not just a simple web search away – or, at least, I wasn’t able to find any easily. Sure, I could pay for one – but why would I do that? Instead, I quickly cranked out something by hand, so I could submit the application. However, I thought to myself that as soon as I had a moment, I should write a quick script to generate a pretty spinner (prettier than I did by hand, that’s for sure.) Here’s the script:
#! /usr/bin/python
import math
from PIL import Image
def makeSpinner(filename, size, thickness):
"""Make a spinner image. A square image of size x size will be allocated.
The spinner will be contained in a ring with an outer diameter of size
and an inner diameter of size-thickness."""
image = Image.new('RGBA', (size,size), 0)
center = int(size / 2.0)
radius = int(size / 2.0)
angle = 0.0
anglestep = math.atan(0.5 / radius) * (180.0 / math.pi)
while angle < 360.0:
bright = int(255 * (1.0 - angle/360.0))
color = (bright, bright, bright, 255)
angle_radians = math.pi * angle/180.0
for r in range(radius-thickness, radius):
x = round(center + r * math.cos(angle_radians))
y = round(center - r * math.sin(angle_radians))
Always buying this levitra from canada take the medicine with full precaution so that it will ease down the condition of penile erection. Once taken, the medicine reaches the reproductive organ and thus stops the PDE-5 from coming in the way of the chemicals sent by the brain that trigger the dilation of the blood along the penile region & this is possible by being more physically active, which can be achieved through exercise. buy viagra Before choosing the herbal remedies for weak ejaculation treatment, you should know the effectiveness of the ingredients buy viagra soft and how long it stays effective. It is very beneficial to reduce viagra for sale mastercard sexual inhibitions and boost sensitivity to touch.
coordinate = (int(x), int(y))
#print coordinate, color
image.putpixel(coordinate, color)
angle += anglestep
image.save(filename + '.png', 'PNG')
# Make the spinners for the application.
makeSpinner('ic_progress', 128, 16)
makeSpinner('ic_progress_small', 64, 8)
And here are the outputs of this script. I think they look pretty nice (although the one part that doesn’t show well here is the transparency):
This is just another example of how, right out of the box, with all its libraries, Python is a fantastic and versatile tool. I particularly like the ability to so easily generate and manipulate images! The whole project, including the script shown above, can be found here, on my github page.