Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws1617:the_art_of_music:protokolle:08 [2017/02/23 11:06] cm.mint.2016 angelegt |
ws1617:the_art_of_music:protokolle:08 [2017/02/23 14:28] (aktuell) cm.mint.2016 |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== 2017-02-16: ====== | ====== 2017-02-16: ====== | ||
+ | |||
+ | test-moving-circles_b1206-alpha_defining new circles ist ein Programm, welches 20 Kreise, welche eine zufällige Farbe und eine in 0,01er Schritten steigenden Radius besitzen, übereinander zeichnet. | ||
+ | |||
+ | <code python> | ||
+ | from __future__ import division | ||
+ | |||
+ | import numpy as np | ||
+ | import moving_circles | ||
+ | from scipy.fftpack import * | ||
+ | from moving_circles import Canvas, Circle | ||
+ | from microlistener import MicroListener | ||
+ | from random import randint | ||
+ | |||
+ | # chose 'VISPY' or 'MATPLOTLIB' | ||
+ | |||
+ | PREFERRED_BACKEND = 'MATPLOTLIB_WX' | ||
+ | |||
+ | ###################################################### | ||
+ | # One possible use case: | ||
+ | # Use timer event of backend to change graphic objects. | ||
+ | # Here 10 circles are created and a callback function | ||
+ | # action(...) is registered to be called at each timer | ||
+ | # event. | ||
+ | ###################################################### | ||
+ | ###micolistener### | ||
+ | CHANNELS=2 | ||
+ | RATE=44100 | ||
+ | CHUNK=2**11 | ||
+ | z=[] | ||
+ | last_values1 = (0,0,0) | ||
+ | last_values2 = (0,0,0) | ||
+ | last_values3 = (0,0,0) | ||
+ | |||
+ | def micro_callback(in_data, frame_count, time_info,status): | ||
+ | global z | ||
+ | y=np.array(np.fromstring(in_data,dtype=np.short),dtype=np.float) | ||
+ | yf = fft(y) | ||
+ | xf = np.linspace(0.0, (2.0*RATE), CHUNK/2) | ||
+ | if CHANNELS==2: | ||
+ | y=y.reshape((y.shape[0]//2,2)) | ||
+ | else: | ||
+ | y=y.reshape((y.shape[0],1)) | ||
+ | #print int(np.linalg.norm(y[:,0])/2000.)*'*' | ||
+ | z=np.abs(yf) | ||
+ | return (in_data, status) | ||
+ | |||
+ | listen=MicroListener(RATE,CHANNELS,CHUNK,micro_callback) | ||
+ | ### | ||
+ | l_kreise=[] | ||
+ | def action(objects, event): | ||
+ | | ||
+ | global z, last_values1, last_values2, last_values3 | ||
+ | n = 50 | ||
+ | #print z[2048]/1000000.0 | ||
+ | last_values1 = (last_values1[1], last_values1[2], sum(z[186:186+n])/(n*100000.0)) ##1000 Hz (?) | ||
+ | # last_values2 = (last_values2[1], last_values2[2], sum(z[19:19+n])/(n*1000000.0)) ##100 Hz (?) | ||
+ | # last_values3 = (last_values3[1], last_values3[2], sum(z[1115:1115+n])/(n*10000.0)) ##6000 Hz (?) | ||
+ | # circ.set_radius(sum(last_values1)/3) | ||
+ | # circ2.set_radius(sum(last_values2)/3) | ||
+ | # circ3.set_radius(sum(last_values3)/3) | ||
+ | #dt, elapsed = event.dt, event.elapsed | ||
+ | #for i,circ in enumerate(objects): | ||
+ | # circ.move(0.7*dt*np.sin(elapsed*(i+1)), 0.7*dt*np.cos(elapsed*(i+1))) | ||
+ | # circ.set_color( (np.abs(np.sin(elapsed*(i+1))),np.abs(np.sin(elapsed*2*(i+1))), np.abs(np.sin(elapsed*3*(i+1))),0.3) ) | ||
+ | i = 0.01 | ||
+ | for circ_temp in l_kreise: | ||
+ | circ_temp.set_radius(i) | ||
+ | i+=0.01 | ||
+ | |||
+ | |||
+ | |||
+ | # create objects, register callback and start program. | ||
+ | |||
+ | win = Canvas() | ||
+ | objects = [] | ||
+ | |||
+ | #for i in range(10): | ||
+ | # circ = Circle(win, pos=(-0.6+0.05*i,0), radius=0.1,color = (1,0,0,0.2)) | ||
+ | # objects.append(circ) | ||
+ | |||
+ | #coordinates | ||
+ | x1=0.0 | ||
+ | y1=0.25 | ||
+ | x2=-0.5/np.sqrt(5) | ||
+ | y2=-0.25/np.sqrt(5) | ||
+ | x3=0.5/np.sqrt(5) | ||
+ | y3=-0.25/np.sqrt(5) | ||
+ | |||
+ | |||
+ | for i in range(20): | ||
+ | l_kreise.append(Circle(win,pos=(0,0),radius=0, color=(randint(0,10)/10,randint(0,10)/10,randint(0,10)/10,0.2))) | ||
+ | |||
+ | #circ = Circle(win, pos=(x1,y1),radius = 0.1, color=(1,0,0,0.2)) | ||
+ | #circ2 = Circle(win, pos=(x2,y2),radius = 0.1, color=(0,1,0,0.2)) | ||
+ | #circ3 = Circle(win, pos=(x3,y3),radius = 0.1, color=(0,0,1,0.2)) | ||
+ | |||
+ | while True: | ||
+ | win.set_action(action, objects) | ||
+ | #print z[0] | ||
+ | win.run() | ||
+ | </code> | ||
+ | |||
+ | |||
+ | Außerdem haben wir test-moving-circles b1205 moving-average entwickelt, welches im Gegensatz zu test_moving_circles_1.2 4-Kreise-Frequenzband jeweils die letzten drei Ergebnisse nimmt und den daraus resultierenden gleitenden Mittelwert benutzt. | ||
+ | |||
+ | <code python> | ||
+ | from __future__ import division | ||
+ | |||
+ | import numpy as np | ||
+ | import moving_circles | ||
+ | from scipy.fftpack import * | ||
+ | from moving_circles import Canvas, Circle | ||
+ | from microlistener import MicroListener | ||
+ | |||
+ | # chose 'VISPY' or 'MATPLOTLIB' | ||
+ | |||
+ | PREFERRED_BACKEND = 'MATPLOTLIB_WX' | ||
+ | |||
+ | ###################################################### | ||
+ | # One possible use case: | ||
+ | # Use timer event of backend to change graphic objects. | ||
+ | # Here 10 circles are created and a callback function | ||
+ | # action(...) is registered to be called at each timer | ||
+ | # event. | ||
+ | ###################################################### | ||
+ | ###micolistener### | ||
+ | CHANNELS=2 | ||
+ | RATE=44100 | ||
+ | CHUNK=2**11 | ||
+ | z=[] | ||
+ | last_values1 = (0,0,0) | ||
+ | last_values2 = (0,0,0) | ||
+ | last_values3 = (0,0,0) | ||
+ | |||
+ | def micro_callback(in_data, frame_count, time_info,status): | ||
+ | global z | ||
+ | y=np.array(np.fromstring(in_data,dtype=np.short),dtype=np.float) | ||
+ | yf = fft(y) | ||
+ | xf = np.linspace(0.0, (2.0*RATE), CHUNK/2) | ||
+ | if CHANNELS==2: | ||
+ | y=y.reshape((y.shape[0]//2,2)) | ||
+ | else: | ||
+ | y=y.reshape((y.shape[0],1)) | ||
+ | #print int(np.linalg.norm(y[:,0])/2000.)*'*' | ||
+ | z=np.abs(yf) | ||
+ | return (in_data, status) | ||
+ | |||
+ | listen=MicroListener(RATE,CHANNELS,CHUNK,micro_callback) | ||
+ | ### | ||
+ | |||
+ | def action(objects, event): | ||
+ | global z, last_values1, last_values2, last_values3 | ||
+ | n = 50 | ||
+ | #print z[2048]/1000000.0 | ||
+ | last_values1 = (last_values1[1], last_values1[2], sum(z[186:186+n])/(n*100000.0)) ##1000 Hz (?) | ||
+ | last_values2 = (last_values2[1], last_values2[2], sum(z[19:19+n])/(n*1000000.0)) ##100 Hz (?) | ||
+ | last_values3 = (last_values3[1], last_values3[2], sum(z[1115:1115+n])/(n*10000.0)) ##6000 Hz (?) | ||
+ | circ.set_radius(sum(last_values1)/3) | ||
+ | circ2.set_radius(sum(last_values2)/3) | ||
+ | circ3.set_radius(sum(last_values3)/3) | ||
+ | #dt, elapsed = event.dt, event.elapsed | ||
+ | #for i,circ in enumerate(objects): | ||
+ | # circ.move(0.7*dt*np.sin(elapsed*(i+1)), 0.7*dt*np.cos(elapsed*(i+1))) | ||
+ | # circ.set_color( (np.abs(np.sin(elapsed*(i+1))),np.abs(np.sin(elapsed*2*(i+1))), np.abs(np.sin(elapsed*3*(i+1))),0.3) ) | ||
+ | |||
+ | |||
+ | # create objects, register callback and start program. | ||
+ | |||
+ | win = Canvas() | ||
+ | objects = [] | ||
+ | |||
+ | #for i in range(10): | ||
+ | # circ = Circle(win, pos=(-0.6+0.05*i,0), radius=0.1,color = (1,0,0,0.2)) | ||
+ | # objects.append(circ) | ||
+ | |||
+ | #coordinates | ||
+ | x1=0.0 | ||
+ | y1=0.25 | ||
+ | x2=-0.5/np.sqrt(5) | ||
+ | y2=-0.25/np.sqrt(5) | ||
+ | x3=0.5/np.sqrt(5) | ||
+ | y3=-0.25/np.sqrt(5) | ||
+ | |||
+ | circ = Circle(win, pos=(x1,y1),radius = 0.1, color=(1,0,0,0.2)) | ||
+ | circ2 = Circle(win, pos=(x2,y2),radius = 0.1, color=(0,1,0,0.2)) | ||
+ | circ3 = Circle(win, pos=(x3,y3),radius = 0.1, color=(0,0,1,0.2)) | ||
+ | |||
+ | while True: | ||
+ | win.set_action(action, objects) | ||
+ | #print z[0] | ||
+ | win.run() | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ |