From: Bruce S. <Bru...@nc...> - 2009-06-30 05:04:25
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> Fans of 3D, you might find this as intriguing as I did:<br> <br> <a href="http://ge.ecomagination.com/smartgrid/#/augmented_reality" _base_href="data:">http://ge.ecomagination.com/smartgrid/#/augmented_reality</a> <div style="font-family: Helvetica; font-size: 16px; color: black; text-align: left;"><br class="webkit-block-placeholder"> </div> <div style="font-family: Helvetica; font-size: 16px; color: black; text-align: left;"><font face="Times New Roman, Times, serif">Print the "Solar Panel Marker" page, then follow the rest of the instructions on the page.<br> <br> You need to have a webcam on your computer; the webcam views the special page that you print and follows the page as you move it around, thereby giving you navigation in the 3D scene.<br> <br> Bruce Sherwood<br> <br> </font></div> </body> </html> |
From: Kadir H. <kha...@ya...> - 2009-07-03 10:37:14
|
Hello All, Inspired by Bruce's notification on the demo, I perpared a quick Vpython version for the windmills part of it. I used PyAudio to capture mic input and used it to control head axis, and rotation speed. My laptop has a mono built-in mic, so I can only see the blades rotation. If you have a stereo built-in mic, I believe you should see both. I did not elaborate on using a web-cam's mic for stereo input since I could not see any support for it by PyAudio, and I did not want to go into details of wave library and WinMM api. The video part is more tricky of course. It needs a lot more work on image processing, and also some new capabilities on VPython side, to paint the background with a live video image, rather than a plane color, as it is today, which is well beyond my scope. Start the application, and just talk to the screen ( the mic)... Kadir # ecoMILLs in VPython from visual import * import pyaudio import sys from array import array ###### Set the Scene scene.autocenter = 0 scene.center = (0,10,0) scene.range = 20 scene.autoscale = 0 scene.width = 1024 scene.height = 768 scene.title = "ecoMILLs" field = box(size=(50,1,50), color=(0,1,0)) ###### Prepare Audio threshold = 200 maxValue = 0 chunk = 2048 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 1 p = pyaudio.PyAudio() stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, output = True, frames_per_buffer = chunk) ######### Setup a windmill class WindMill(): def __init__(self, offset=(0,0,0), color1=(1,0,0), color2=(1,1,0), color3=(0,0,1)): self.wndml = frame(pos=offset) self.head = frame(frame=self.wndml) self.wings = frame(frame=self.head) self.pole = cone(frame=self.wndml, radius=0.5, axis=(0,10,0)) self.dyno1 = cone(frame=self.head, pos=self.pole.axis-(0,0,1), radius=0.5, axis=(0,0,-1)) self.dyno2 = cylinder(frame=self.head, pos=self.pole.axis-(0,0,1), radius=0.5, axis=(0,0,1)) self.bld1 = pyramid(frame=self.wings, pos=self.pole.axis+(0,2.5,0), size=(0.5, 5.0, 0.05), color=color1) self.bld2 = pyramid(frame=self.wings, pos=self.pole.axis+(0,2.5,0), size=(0.5, 5.0, 0.05), color=color2) self.bld2.rotate(axis=(0,0,1), angle=pi*2/3, origin=self.pole.axis) self.bld3 = pyramid(frame=self.wings, pos=self.pole.axis+(0,2.5,0), size=(0.5, 5.0, 0.05), color=color3) self.bld3.rotate(axis=(0,0,1), angle=-pi*2/3, origin=self.pole.axis) self.shaft = cylinder(frame=self.wings, pos=self.pole.axis, radius=0.1, axis=(0,0,0.1), color=(0.4,0.4,0.4)) axis = (1,0,0) self.rotate_wings(pi/5+random.uniform(-pi/4,+pi/4)) def rotate_head(self, axis): self.head.axis = axis rotang = pi/64.0 def rotate_wings(self, rotang): self.wings.rotate(axis=self.dyno1.axis, origin=self.pole.axis, angle=rotang) ##### Create WindMills mills = [] mill1 = WindMill() mill2 = WindMill((10,0,3), color1=(0,1,0), color2=(0,1,1), color3=(1,0,1)) mill3 = WindMill((-10,0,3), color1=(1,1,1), color2=(1,1,0), color3=(1,0,0)) mills.append(mill1) mills.append(mill2) mills.append(mill3) left = 1 right = 1 headax = (1,0,0) rotang = pi/64. while left >0 or right > 0: for i in range(0, 44100 / chunk * RECORD_SECONDS): data = stream.read(chunk) asInts = array('h', data) for j in range(0,len(asInts),2): left += asInts[j] right += asInts[j+1] if left > threshold or right > threshold: headax = ((1,0,1-(right/left))) rotang = pi/64 + (pi/64)*(left+right)/10000 for mill in mills: mill.rotate_head(headax) mill.rotate_wings(rotang) left = 1 right = 1 stream.stop_stream() stream.close() p.terminate() ________________________________ From: Bruce Sherwood <Bru...@nc...> To: VPython <vis...@li...> Sent: Tuesday, June 30, 2009 8:03:28 AM Subject: [Visualpython-users] Very cool 3D demo Fans of 3D, you might find this as intriguing as I did: http://ge.ecomagination.com/smartgrid/#/augmented_reality Print the "Solar Panel Marker" page, then follow the rest of the instructions on the page. You need to have a webcam on your computer; the webcam views the special page that you print and follows the page as you move it around, thereby giving you navigation in the 3D scene. Bruce Sherwood |