vpython test_2nd.py
已有 225 次阅读2018-4-27 15:12
|系统分类:兴趣爱好
#!/usr/bin/env python2
# -*- coding:utf-8 -*-
from __future__ import division, print_function
from visual import *
from visual.graph import *
import wx
rod_init_length = 2
def rotate_r(evt):
value = r0.GetValue() * 2 * pi / 100
rod.axis.x = rod_init_length*cos(value)
rod.axis.y = rod_init_length*sin(value)
def set_x(evt): # called on slider events
value = s0.GetValue()
rod.axis.x = (value) # value is min-max slider position, 0 to 100
def set_y(evt): # called on slider events
value = s1.GetValue()
rod.axis.y = (value) # value is min-max slider position, 0 to 100
def send_out(evt):
print (rod.axis, rod.length)
L = 320
Hgraph = 400
# Create a window. Note that w.win is the wxPython "Frame" (the window).
# window.dwidth and window.dheight are the extra width and height of the window
# compared to the display region inside the window. If there is a menu bar,
# there is an additional height taken up, of amount window.menuheight.
# The default style is wx.DEFAULT_FRAME_STYLE; the style specified here
# does not enable resizing, minimizing, or full-sreening of the window.
w = window(width=2*(L+window.dwidth), height=window.dheight+window.menuheight+Hgraph,
menus=True, title='Widgets',
style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
# Place a 3D display widget in the left half of the window.
d = 20
disp = display(window=w, x=d, y=d, width=L-2*d, height=L-2*d, forward=-vector(0,1,2))
gdisplay(window=w, y=disp.height+50, width=2*(L+window.dwidth), height=Hgraph)
def M(m):
print(m.select)
rod = cylinder(pos=(0,2,1), axis=(5,5,0), color=color.yellow, radius=0.1, length=2)
# Place buttons, radio buttons, a scrolling text object, and a slider
# in the right half of the window. Positions and sizes are given in
# terms of pixels, and pos(0,0) is the upper left corner of the window.
p = w.panel # Refers to the full region of the window in which to place widgets
left = wx.Button(p, label='send out coordination', pos=(L+10,15))
left.Bind(wx.EVT_BUTTON, send_out)
wx.StaticText(p, pos=(1.0*L,0.55*L), label='Set rod x value')
s0 = wx.Slider(p, pos=(1.0*L,0.6*L), size=(0.9*L,20), minValue=0, maxValue=100)
s0.Bind(wx.EVT_SCROLL, set_x)
wx.StaticText(p, pos=(1.0*L,0.75*L), label='Set rod y value')
s1 = wx.Slider(p, pos=(1.0*L,0.8*L), size=(0.9*L,20), minValue=0, maxValue=100)
s1.Bind(wx.EVT_SCROLL, set_y)
wx.StaticText(p, pos=(1.0*L,0.95*L), label='rotate rod')
r0 = wx.Slider(p, pos=(1.0*L,1.0*L), size=(0.9*L,20), minValue=0, maxValue=100)
r0.Bind(wx.EVT_SCROLL, rotate_r)
t = 0
while t < 10:
rate(1)
#rod.axis.y = t + rod.axis.y
t = t + 1