Site Sponsors:
zClock: Python3 Clock in 11 Statements 
When the atomic clock went on the fritz lately (probably was the first popular commercial version ever available!) I went lookin'.

Finding a few for under $20, it occurred to me that - attached as we are to the DST-capable world-time-zone, that I could easily slap one together in Python.

Looking for a way to keep braggin' over how easy it is to get things done using Python 3, I decided to see just how few lines I could use to encode the idea.

Here is what I came up with:

from tkinter import *
import time

zProgram = Tk()
zProgram.title("zClock: Python3 Clock in 11 Statements")
zClock = Label(zProgram,
font=('ariel', 72, 'bold'),
zClock.pack(fill=BOTH, expand=1)

def zTimer():
zClock.after(500, zTimer)


While I could have written the above in even fewer lines using Turtle Graphics, having just cobbled-together a training offering on the same I thought that using TK would make for a refreshingly different blog post.

Here is a link to zVideo :-)

Enjoy the Journey!


p.s: Feel free to add more features (date, day... temperature probe support for your Raspberry Pi) as your time and obsession(s) may allow.

[ add comment ] ( 93 views )   |  permalink  |  related link
Python Animation: Pinwheel Cogs In Action 
Every new concept needs to have a programatic test.

While working fine in the woodshop, in as much as I decided to create a complete series on Python last year, I decided to update that training opportunity with a training module dedicated to Turtle Graphics.

Using the concepts being taught therein, please allow me to present the graphical proof that pinwheel gears are not only easier to cut, but that pinwheel cogs can indeed present a type of motion that allot more horologists - than we steam-punk 'tinkerers - will surely find gear-headily attractive:

import turtle

zSet = (turtle.Turtle(), turtle.Turtle())

num_msec = 100

def quit():

def zoom():
turtle.ontimer(zoom, num_msec)

# Return False if the number of slices will not work (e.g 7, 14, 16, etc.)
def draw_pin_wheel(zTurtle=turtle, zSlices=10, zRange=100, zBite=-1):
# Check for hgte 'pi problem'
if 360 % zSlices:
return False

angle = int(360 / zSlices)
locs = [[[None for z in range(1)] for y in range(2)] for x in range(zSlices + 1)]
if zBite <= 0:
zBite = int(zRange / 10)

zSize = len(locs)
zLine = 0
for ref in range(zSize):
locs[zLine][1] = zTurtle.pos()
locs[zLine][0] = zTurtle.pos()
zTurtle.goto(0, 0)
zLine += 1

# Demonstrative - let's keep it sane 4 others =)
for line in range(zSize):
listA = locs[line][0]
zTurtle.goto(listA[0], listA[1]) # Key Point
listB = locs[0][1]
if line < (zSize - 1):
listB = locs[line + 1][1]

# Cut-draw the outer 'cut'
zTurtle.goto(listB[0], listB[1]) # Cog-Angle
zTurtle.goto(listA[0], listA[1]) # Inner-Polygon

return True


# Create cog
ok = draw_pin_wheel(zSlices=10, zRange=100, zBite=30)
if not ok:
print("Bad Slice")


shape = turtle.Shape("compound")
points = turtle.get_poly()
shape.addcomponent(points, "black", "black")
turtle.register_shape("MyPinwheel", shape)

for ss in range(len(zSet)):
zTurtle = zSet[ss]

turtle.goto(0, 200)
turtle.write("PINWHEEL COGS IN-ACTION", font=("Arial", 24, "normal"), align='center')
zSet[0].goto(90, 100)
zSet[1].goto(-90, 97)

# Schedule event
turtle.onkey(quit, "q")
turtle.ontimer(zoom, num_msec)



Once the above dual-gear demonstration is running on your machine, just press "q" to stop the animation.

If you don't want to read the code to see the animation in-action ... and if one can believe how overly obsessed we are with the web-gear topic ... then here is the movie.

If one has read this far, then here is a short video of a 2:1 x 3 multi-gear simulation that you may also enjoy. --The above might not look like it wood work (horrific pun - sorry!), but it do.

Sharing is caring!


[ add comment ] ( 123 views )   |  permalink  |  related link

<<First <Back | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Next> Last>>