Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
updated to setuptools, anti-aliasing for AnalogClock.py
Browse files Browse the repository at this point in the history
  • Loading branch information
adammhaile committed Jun 19, 2016
1 parent b1f0d87 commit c44fd09
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -55,3 +55,5 @@ target/
.remote-sync.json
.remote-sync.json
.remote-sync.json

BiblioPixelAnimations.egg*
66 changes: 43 additions & 23 deletions BiblioPixelAnimations/matrix/AnalogClock.py
@@ -1,71 +1,83 @@
from bibliopixel.animation import BaseMatrixAnim
import bibliopixel.colors as colors
from bibliopixel.util import pointOnCircle
import time, math
import time
import math


class AnalogClock(BaseMatrixAnim):
def __init__(self, led):
def __init__(self, led, aa=False):
super(AnalogClock, self).__init__(led)
self._centerX = (self._led.width - 1) / 2
self._centerY = (self._led.height - 1) / 2
self.aa = aa

def step(self, amt = 1):
def step(self, amt=1):
self._led.all_off()
t = time.localtime()
hrs = t.tm_hour % 12
min = t.tm_min
mins = t.tm_min
sec = t.tm_sec

p_hrs = pointOnCircle(self._centerX, self._centerY, int(self._centerX *0.7), hrs * 30)
p_min = pointOnCircle(self._centerX, self._centerY, self._centerX, min * 6)
p_hrs = pointOnCircle(self._centerX, self._centerY, int(self._centerX * 0.7), hrs * 30)
p_min = pointOnCircle(self._centerX, self._centerY, self._centerX, mins * 6)
p_sec = pointOnCircle(self._centerX, self._centerY, self._centerX, sec * 6)

self._led.drawLine(self._centerX, self._centerY, p_hrs[0], p_hrs[1], (255, 0, 0))
self._led.drawLine(self._centerX, self._centerY, p_min[0], p_min[1], (0, 255, 0))
self._led.drawLine(self._centerX, self._centerY, p_sec[0], p_sec[1], (0, 0, 255))
self._led.drawLine(self._centerX, self._centerY, p_hrs[0], p_hrs[1], (255, 0, 0), aa=self.aa)
self._led.drawLine(self._centerX, self._centerY, p_min[0], p_min[1], (0, 255, 0), aa=self.aa)
self._led.drawLine(self._centerX, self._centerY, p_sec[0], p_sec[1], (0, 0, 255), aa=self.aa)

self._step = 0


class RGBAnalogClock(BaseMatrixAnim):

def __init__(self, led):
def __init__(self, led, aa=False):
super(RGBAnalogClock, self).__init__(led)
self._centerX = (self._led.width - 1) / 2
self._centerY = (self._led.height - 1) / 2
self.aa = aa

def step(self, amt = 1):
def step(self, amt=1):
self._led.all_off()
t = time.localtime()
hrs = t.tm_hour % 12
min = t.tm_min
mins = t.tm_min
sec = t.tm_sec

p_hrs = pointOnCircle(self._centerX, self._centerY, int(self._centerX * 0.7), hrs * 30)
p_min = pointOnCircle(self._centerX, self._centerY, self._centerX, min * 6)
p_min = pointOnCircle(self._centerX, self._centerY, self._centerX, mins * 6)
p_sec = pointOnCircle(self._centerX, self._centerY, self._centerX, sec * 6)

c_hrs = colors.hue2rgb_rainbow(t.tm_hour * (256/24))
c_hrs = colors.hue2rgb_rainbow(t.tm_hour * (256 / 24))

c_min = colors.hue2rgb_rainbow(min * (256/60))
c_min = colors.hue2rgb_rainbow(mins * (256 / 60))

c_sec = colors.hue2rgb_rainbow(sec * (256/60))
c_sec = colors.hue2rgb_rainbow(sec * (256 / 60))

self._led.drawLine(self._centerX, self._centerY, p_hrs[0], p_hrs[1], c_hrs)
self._led.drawLine(self._centerX, self._centerY, p_min[0], p_min[1], c_min)
self._led.drawLine(self._centerX, self._centerY, p_sec[0], p_sec[1], c_sec)
self._led.drawLine(self._centerX, self._centerY, p_hrs[0], p_hrs[1], c_hrs, aa=self.aa)
self._led.drawLine(self._centerX, self._centerY, p_min[0], p_min[1], c_min, aa=self.aa)
self._led.drawLine(self._centerX, self._centerY, p_sec[0], p_sec[1], c_sec, aa=self.aa)

self._step = 0



MANIFEST = [
{
"class": AnalogClock,
"controller": "matrix",
"desc": "Displays analog clock with red, green, and blue hands.",
"desc": "Displays analog clock with red, green, and blue hands.",
"display": "AnalogClock",
"id": "AnalogClock",
"params": [],
"params": [
{
"default": True,
"help": "",
"id": "aa",
"label": "AntiAlias",
"type": "bool"
}
],
"type": "animation"
},
{
Expand All @@ -74,7 +86,15 @@ def step(self, amt = 1):
"desc": "Displays analog clock with hand colors based on their angle converted to a hue value.",
"display": "RGBAnalogClock",
"id": "RGBAnalogClock",
"params": [],
"params": [
{
"default": True,
"help": "",
"id": "aa",
"label": "AntiAlias",
"type": "bool"
}
],
"type": "animation"
}
]
16 changes: 9 additions & 7 deletions setup.py
@@ -1,17 +1,19 @@
from distutils.core import setup
from setuptools import setup
import BiblioPixelAnimations
import urllib2, json
_ver = "BAD_INSTALL"
import sys
_ver = "DEV"

try:
head = urllib2.urlopen("https://api.github.com/repos/ManiacalLabs/BiblioPixelAnimations/git/refs/head").read()
head_data = json.loads(head)
if len(head_data) > 0:
_ver = head_data[0]["object"]["sha"]
if not 'develop' in sys.argv:
head = urllib2.urlopen("https://api.github.com/repos/ManiacalLabs/BiblioPixelAnimations/git/refs/head").read()
head_data = json.loads(head)
if len(head_data) > 0:
_ver = head_data[0]["object"]["sha"]
except:
pass

if not 'pip' in __file__:
if not 'pip' in __file__ and not 'develop' in sys.argv:
print """
This installer MUST be run from pip!
Please install using the following command:
Expand Down

0 comments on commit c44fd09

Please sign in to comment.