LED

2054 days ago by JAVIER

import numpy as np import matplotlib as mpl from matplotlib.patches import Rectangle import matplotlib.pyplot as plt #from mpl_toolkits.mplot3d import Axes3D #import matplotlib.animation as animation 
       
N = 10 
       
def led_on(N,length): L = [] for i in xrange(N): if(i < length): L.append(circle((0,0),1,fill=True,facecolor=(0,0,1),axes=False)) else: L.append(circle((0,0),1,fill=False,facecolor=(0,0,1),axes=False)) return L 
       
N = 4 S1 = animate(led_on(N,1),xmin=-1,ymin=-1,xmax=1,ymax=1,figsize=[2,2]) S2 = animate(led_on(N,2),xmin=-1,ymin=-1,xmax=1,ymax=1,figsize=[2,2]) S3 = animate(led_on(N,3),xmin=-1,ymin=-1,xmax=1,ymax=1,figsize=[2,2]) S4 = animate(led_on(N,4),xmin=-1,ymin=-1,xmax=1,ymax=1,figsize=[2,2]) S1.show(delay=2) S2.show(delay=2) S3.show(delay=2) S4.show(delay=2) 
       



def draw_rectangle(axes,point,width,height,r,g,b): col = (r,g,b) axes.add_artist(Rectangle(point, width, height, fill=True, color=(r,g,b))) 
       
fig = plt.figure() axes= fig.add_subplot(111) N = 256 dx = 1/N x = 0 for i in xrange(N): draw_rectangle(axes,(x,0),dx,1,0,0,i/N) x += dx fig.set_size_inches(4,4) fig.savefig('test.png') plt.clf() 
       
fig2 = plt.figure() axes2= fig2.add_subplot(111) N = 256 dx = 1/N x = 0 xx = np.logspace(0,1,N)/10 #print xx for i in xrange(N-1): draw_rectangle(axes2,(x,0),xx[i+1]-xx[i],1,0,0,xx[i]) x += dx fig2.set_size_inches(4,4) fig2.savefig('test2.png') plt.clf()