import sys from qt import * from qtcanvas import * class App( QApplication ): def __init__( self, args ): QApplication.__init__( self, args ) self.a = 0 self.b = 0 tmp = map( float, sys.stdin.readlines() ) # read as numbers # Rescale values to the interval [0..1] ( mn, mx ) = ( min( tmp ), max( tmp ) ) self.data = map( lambda x: (x-mn)/(mx-mn), tmp ) self.mw = QHBox() self.mw.setFixedWidth( 693 ) self.mw.setFixedHeight( 405 ) self.canvas = QCanvas( 640, 400 ) self.view = QCanvasView( self.canvas, self.mw ) self.a_display = QCanvasText( str(self.a), self.canvas ) self.a_display.setX( 3 ) self.a_display.setY( 6 ) self.b_display = QCanvasText( str(self.b), self.canvas ) self.b_display.setX( 3 ) self.b_display.setY( 20 ) # Obtain a bunch of canvas-widgets. Don't set their coordinates yet. self.raw = [] self.smooth = [] for d in self.data: tmp = QCanvasLine( self.canvas ) tmp.setPen( QPen( QColor( 'red' ) ) ) self.raw.append( tmp ) tmp = QCanvasLine( self.canvas ) tmp.setPen( QPen( QColor( 'blue' ) ) ) self.smooth.append( tmp ) self.sli_a = QSlider( self.mw ) self.sli_a.setFixedHeight( 200 ) self.sli_b = QSlider( self.mw ) self.sli_b.setFixedHeight( 200 ) self.connect( self.sli_a, SIGNAL( "valueChanged(int)" ), self.changeA ) self.connect( self.sli_b, SIGNAL( "valueChanged(int)" ), self.changeB ) self.setMainWidget( self.mw ) # closing window terminates program self.mw.show() self.redraw() def redraw( self ): length = len( self.data ) s0 = self.data[0] s1 = self.data[0] t = 0 for i in xrange( length - 1 ): x0 = float(i)/length x1 = float(i+1)/length y0 = self.data[i] y1 = self.data[i+1] self.raw[i].setPoints( 640*x0, 400*(1-y0), 640*x1, 400*(1-y1) ) self.raw[i].show() s0 = s1 s1 = self.a*self.data[i+1] + (1-self.a)*(s1 + t) t = self.b*(s1 - s0) + (1-self.b)*t self.smooth[i].setPoints( 640*x0, 400*(1-s0), 640*x1, 400*(1-s1) ) self.smooth[i].show() self.a_display.setText( str( self.a ) ) self.b_display.setText( str( self.b ) ) self.a_display.show() self.b_display.show() self.canvas.update() def changeA( self, val ): self.a = float(val)/100.0 self.redraw() def changeB( self, val ): self.b = float(val)/100.0 self.redraw() app = App( sys.argv ) app.exec_loop()