Youscope Emulator

Youscope Emulator written for panda3d

The Source code:

#!/usr/bin/env python
# uses : panda3d
# Author: Norbert Feurle
# Date: 12.1.2012
# Some code i copied from:
# https://code.google.com/p/felipesanches/source/browse/trunk/youscope-emu/youscope-emu.py
# (c)2007 Felipe Sanches <juca@members.fsf.org>
# (c)2007 Leandro Lameiro <lameiro@gmail.com>
# which is licensed under GNU GPL v3 or later

import direct.directbase.DirectStart
from direct.directtools.DirectGeometry import LineNodePath
from pandac.PandaModules import Point3,Vec3,Vec4
from pandac.PandaModules import *
import wave
import struct
import sys
import math
base.disableMouse()
base.setBackgroundColor(0,0.,0)

FPS=30
wro = wave.open('youscope-wave.wav')
READ_LENGTH = wro.getframerate()/FPS

Nachleuchten=10
linesArray=[LineNodePath(parent = render2d, thickness = 2.0, colorVec = Vec4(0.9, 0.0, 0.3, 1)) for i in range(Nachleuchten)]

for line in linesArray:
    line.setTransparency(TransparencyAttrib.MAlpha)
    line.setThickness(3.0)

x=0
alpha_array=[1 for i in range(Nachleuchten)]
framecount=0
def simulationTask(task):
  global x,linesArray,framecount

  frames = wro.readframes(READ_LENGTH)
  p2=Point3(0.0,0.0,0.0)
  x=(x+1)%Nachleuchten
  for ind in range(Nachleuchten):
    actualline=linesArray[ind]
    if ind==x:
      actualline.reset()
      for i in range(0,READ_LENGTH,4):
        r = struct.unpack('hh', frames[i:i+4])
        xpos = (r[1])*2.0/65535.0
        ypos = (r[0])*2.0/65535.0
        p1=Point3(xpos,0.0,ypos)
        lengthbetween=(p1-p2).length()
        alpha=1.0 #max(0,1.0-((lengthbetween)*1.0))
        actualline.setColor((1.0,1.0,1.0,alpha))
        alpha_array[ind]=1.0
        actualline.drawLines([(p1,p1+(0.008,0.0,0.0))])
        #actualline.create() 
        p2=p1
    else:
      alpha_array[ind]=max(0,alpha_array[ind]-alpha_array[ind]/(2.0*Nachleuchten/5.0))
      actualline.setAlphaScale(alpha_array[ind])  ##blur out
    actualline.create()

  return task.again

taskMgr.doMethodLater(1.0/FPS, simulationTask, "Simulation")
run()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: