def draw(self): w = 200 self.c = controls.controls(x=0, y=0, width=w, height=w, range=100) controls.button(pos=(-60,30), height=30, width=40, text='<<' , action=lambda: self.first()) controls.toggle(pos=(0,30),height=30, width=40, text='Pause', action=lambda: self.pauseToggle()) controls.button(pos=(60,30), height=30, width=40, text='>>',action= lambda: self.last()) self.timelabel = controls.label(pos=(-15,-55),display=self.c.display) self.s1=controls.slider(pos=(-15,-30), width=7, length=70, axis=(1,0,0), action=lambda: self.slider1()) self.s1.value = 0 self.s2=controls.slider(pos=(-15,80),min=-1,max=3, width=7, length=70, axis=(1,0,0),action=lambda: self.slider2()) self.s2.value = 0 self.pause = False self.advancestep = 1
def draw(self): w = 200 self.c = controls.controls(x=0, y=0, width=w, height=w, range=100) controls.button(pos=(-60, 30), height=30, width=40, text='<<', action=lambda: self.first()) controls.toggle(pos=(0, 30), height=30, width=40, text='Pause', action=lambda: self.pauseToggle()) controls.button(pos=(60, 30), height=30, width=40, text='>>', action=lambda: self.last()) self.timelabel = controls.label(pos=(-15, -55), display=self.c.display) self.s1 = controls.slider(pos=(-15, -30), width=7, length=70, axis=(1, 0, 0), action=lambda: self.slider1()) self.s1.value = 0 self.s2 = controls.slider(pos=(-15, 80), min=-1, max=3, width=7, length=70, axis=(1, 0, 0), action=lambda: self.slider2()) self.s2.value = 0 self.pause = False self.advancestep = 1
def draw(self): self.sliders = [] self.slidercaptions = [] w = 500.0 spacing_px = 40.0 button_px = 100 marginbottom_px = 20.0 margintop_px = 20.0 button_area_px = 100.0 button_height_px = 80 r = 100.0 h = len( self.variables ) * spacing_px + marginbottom_px + margintop_px + button_area_px + button_height_px spacing = (spacing_px / h) * r posy = -r / 2 + marginbottom_px / h * r + len(self.variables) * spacing self.c = controls.controls(x=0, y=0, width=w, height=h, range=r) for v in self.variables: s = controls.slider(pos=(-15, posy), width=7, length=70, axis=(1, 0, 0)) s.value = v.default s.min, s.max = v.bounds sc = controls.label(text=v.name, align='right', pos=(r * (-0.5 + 0.1), posy), display=self.c.display, box=False) self.sliders.append(s) self.slidercaptions.append(sc) print posy posy -= spacing controls.button(pos=(0, r * (0.5 - button_area_px / h)), height=button_height_px / h * r, width=r / 2, text='reset', action=lambda: self.reset())
def draw(self): self.sliders=[] self.slidercaptions = [] w = 500.0 spacing_px = 40.0 button_px = 100 marginbottom_px = 20.0 margintop_px = 20.0 button_area_px = 100.0 button_height_px = 80 r= 100.0 h = len(self.variables)*spacing_px + marginbottom_px + margintop_px + button_area_px + button_height_px spacing = (spacing_px / h) * r posy = -r/2 + marginbottom_px/h*r + len(self.variables)*spacing self.c = controls.controls(x=0, y=0, width=w, height=h, range=r) for v in self.variables: s = controls.slider(pos=(-15,posy), width=7, length=70, axis=(1,0,0)) s.value = v.default s.min,s.max = v.bounds sc = controls.label(text=v.name,align='right', pos=(r*(-0.5+0.1),posy),display=self.c.display,box = False ) self.sliders.append(s) self.slidercaptions.append(sc) print posy posy-=spacing controls.button(pos=(0,r*(0.5-button_area_px/h)), height=button_height_px/h*r, width=r/2, text='reset' , action=lambda: self.reset())
qn = 0.5; un = (3/(x[n-1]-x[n-2]))*(ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2])) y2[n - 1] = (un - qn*u[n - 2])/(qn*y2[n - 2] + 1.) for k in range(n - 2, 1, - 1): y2[k] = y2[k]*y2[k + 1] + u[k] for i in range(1, Nfit + 2): # Begin fit xout = x[0] + (x[n - 1] - x[0])*(i - 1)/(Nfit) klo = 0; khi = n - 1 # Bisection algor while (khi - klo >1): k = (khi + klo) >> 1 if (x[k] > xout): khi = k else: klo = k h = x[khi] - x[klo] if (x[k] > xout): khi = k else: klo = k h = x[khi] - x[klo] a = (x[khi] - xout)/h b = (xout - x[klo])/h yout = a*y[klo] + b*y[khi] + ((a*a*a-a)*y2[klo]+(b*b*b-b)*y2[khi])*h*h/6 funct2.plot(pos = (xout, yout) ) c = controls(x=500,y=0,width=200,height=200) # Control via slider control = slider(pos=(-50,50,0), min = 2, max = 100, action = update) toggle(pos = (0, 35, - 5), text1 = "Number of points", height = 0) control.value = 2 update() while 1: c.interact() rate(50) # update < 10/sec funct2.visible = 0
# which can be read and set. # The pos attribute for buttons, toggles, and menus is the center of the control (like "box"). # The pos attribute for sliders is at one end, and axis points to the other end (like "cylinder"). # By default a control is created in the most recently created "controls" window, but you # can change this by specifying "controls=..." when creating a button, toggle, slider, or menu. # The Python construct "lambda: setdir(-1)" below passes the location of the setdir function # to the interact machinery, which uses "apply" to call the function when an action # is to be taken. This scheme ensures that the execution of the function takes place # in the appropriate namespace context in the case of importing the controls module. BL = ctrls.button(pos=(-30, 30), height=30, width=40, text='Left', action=lambda: setdir(-1)) BR = ctrls.button(pos=(30, 30), height=30, width=40, text='Right', action=lambda: setdir(1)) S1 = ctrls.slider(pos=(-15, -40), width=7, length=70, axis=(1, 0.7, 0), action=lambda: setrate(S1)) S2 = ctrls.slider(pos=(-30, -50), width=7, length=50, axis=(0, 1, 0), action=lambda: setrate(S2)) T1 = ctrls.toggle(pos=(40, -30), width=10, height=10, text0='Red', text1='Cyan', action=lambda: togglecubecolor()) M1 = ctrls.menu(pos=(0, 0, 0), height=7, width=25, text='Options') # After creating the menu heading, add menu items: M1.items.append(('Left', lambda: setdir(-1))) # specify menu item title and action to perform M1.items.append(('Right', lambda: setdir(1))) M1.items.append(('---------', None)) # a dummy separator M1.items.append(('Red', lambda: cubecolor(vp.color.red))) M1.items.append(('Cyan', lambda: cubecolor(vp.color.cyan))) S1.value = 70 # update the slider setrate(S1) # set the rotation rate of the cube setdir(-1) # set the rotation direction of the cube