#!/usr/bin/env python
from rgbmatrix import RGBMatrix
from random import randint
import sys, time
import numpy, math

pi = numpy.pi
rows = 16
chains = 1
parallel = 1
ledMatrix = RGBMatrix(rows, chains, parallel)

numRows = 16
height = ledMatrix.height
width = ledMatrix.width
barWidth = width / numRows
tempXAxis = numpy.empty([numRows])
for i in range(numRows):
	tempXAxis[i] = i * pi / numRows

try:
	print "Press Ctrl + C to stop executing"
	while True:
		nextFrame = ledMatrix.CreateFrameCanvas()
		barHeights = numpy.empty([numRows])
		for i in range(len(tempXAxis)):
			x = tempXAxis[i]
			barHeights[i] = (math.sin(randint(-3, 3) * x) + math.cos(randint(-3, 3) * x) + math.cos(randint(-3, 3) * x)) / 3

		for x in range(width):
			barHeight = int(barHeights[int(x / barWidth)] * height)
			for y in range(height):
				if height - y <= barHeight:
					if y < 2:
						nextFrame.SetPixel(x, y, 255, 0, 0) # Red
					elif y < 5:
						nextFrame.SetPixel(x, y, 200, 200, 0) # Yellow
					else:
						nextFrame.SetPixel(x, y, 0, 200, 0) # Green

		ledMatrix.SwapOnVSync(nextFrame)
		time.sleep(0.1)
except KeyboardInterrupt:
	print "Exiting\n"
	sys.exit(0)
@@ -209,19 +209,19 @@
 el)%0A%0Anum
-Row
+Bar
 s = 16%0Ah
@@ -291,19 +291,19 @@
 th / num
-Row
+Bar
 s%0AtempXA
@@ -320,27 +320,27 @@
 y.empty(%5Bnum
-Row
+Bar
 s%5D)%0Afor i in
@@ -349,19 +349,19 @@
 ange(num
-Row
+Bar
 s):%0A%09tem
@@ -384,19 +384,19 @@
 pi / num
-Row
+Bar
 s%0A%0Atry:%0A
@@ -529,11 +529,11 @@
 %5Bnum
-Row
+Bar
 s%5D)%0A

Rename numRows -> numBars