我有一个工程在做。我是菜鸟,室友是软件工程师,建议我在该项目中使用python。我的问题在下面列出。首先,这是我要完成的工作的概述。
项目概况:
一组可寻址RGB led矩阵,例如50 led x 50 led(250 led)。led矩阵连接到arduino并由其运行,它将从分散的程序中接收矩阵的模式信息。(我们稍后会担心arduino的功能)
该程序的目的是为每个可寻址LED生成图案信息并将其发送到arduino。
该程序将托管一个GUI,以便实时更改和可视化输出矩阵或当前矩阵的颜色图和图案(即,打开/关闭闪光灯效果,打开/关闭淡入淡出效果)。然后,程序将从gui中读取以生成并转换RGB值以发送到arduino。
这是我的位置,需要指导。到目前为止,在继续进行此项目的下一部分之前,我将重点放在使GUI正常工作上。
我正在使用matplotlib,希望可以创建一个50x50平方(或像素)的图,并保持对每个单独点的值的控制,并努力应对。理想情况下,我将能够每秒绘制30次或多次绘制该图,以便它看起来像是在“实时”更新。
这是一些示例代码,因此您可以更好地了解我要完成的工作:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm
from numpy.random import random
fig = plt.figure()
matrix = random((50,50))
plt.imshow(matrix, interpolation='nearest', cmap=cm.spectral)
def update(data):
print("IN UPDATE LOOP")
matrix = random((50,50))
return matrix
def data_gen():
print("IN DATA_GEN LOOP")
while True: yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
plt.imshow(matrix, interpolation='nearest', cmap=cm.spectral)
plt.show()
plt.draw()
网格不会更新,不确定为什么...
为什么我的网格没有更新?
忽略前两个问题,因为它们不是这里的主题,代码的问题是您实际上从未更新过图像。这应该在动画功能中完成。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import cm
from numpy.random import random
fig = plt.figure()
matrix = random((50,50))
im = plt.imshow(matrix, interpolation='nearest', cmap=cm.Spectral)
def update(data):
im.set_array(data)
def data_gen():
while True:
yield random((50,50))
ani = animation.FuncAnimation(fig, update, data_gen, interval=1000)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句