Site Sponsors:
zPython Clock, Revisited 
Here is an upgrade for zClock:



from tkinter import *
import time

zProgram = Tk()
zProgram.title("zPython Clock - Soft9000.com")
zClock = Label(zProgram,
font=('ariel', 72, 'bold'),
bg='gold',
fg='white')

zDay = Label(zProgram,
font=('ariel', 36, 'bold'),
bg='gold',
fg='green')

zDate = Label(zProgram,
font=('ariel', 36, 'bold'),
bg='gold',
fg='blue')

zClock.pack(fill=BOTH, expand=1)
zDay.pack(side='left', fill=X, expand=1)
zDate.pack(side='right', fill=X, expand=1)


def zTimer():
zClock.config(text=time.strftime('%H:%M:%S'))
zDay.config(text=time.strftime('%a'))
zDate.config(text=time.strftime('%m/%d/%y'))
zClock.after(500, zTimer)


zTimer()
zProgram.mainloop()


Here is zVideo :-)


[ add comment ] ( 262 views )   |  permalink  |  related link
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'),
bg='gold',
fg='white')
zClock.pack(fill=BOTH, expand=1)


def zTimer():
zClock.config(text=time.strftime('%H:%M:%S'))
zClock.after(500, zTimer)


zTimer()
zProgram.mainloop()


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!

-Rn

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 ] ( 192 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():
turtle.bye()

def zoom():
zSet[0].tilt(2)
zSet[1].tilt(-2)
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):
zTurtle.left(angle)
zTurtle.forward(zRange)
locs[zLine][1] = zTurtle.pos()
zTurtle.back(zBite)
locs[zLine][0] = zTurtle.pos()
zTurtle.goto(0, 0)
print(locs[zLine])
zLine += 1

turtle.home()
# 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

turtle.hideturtle()
turtle.delay(0)
turtle.penup()

# Create cog
turtle.penup()
turtle.begin_poly()
turtle.hideturtle()
ok = draw_pin_wheel(zSlices=10, zRange=100, zBite=30)
if not ok:
print("Bad Slice")
turtle.bye()

turtle.end_poly()

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]
zTurtle.shape("MyPinwheel")
zTurtle.showturtle()
zTurtle.penup()

turtle.goto(0, 200)
turtle.color('green')
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)

turtle.listen()

turtle.mainloop()

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!

-Rn


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

<<First <Back | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Next> Last>>