Пример #1
0
def display():
    vp.scene.append_to_title('\n')
    vp.button(text="credits", bind=showat, pos=vp.scene.title_anchor)
    vp.scene.append_to_caption('\n')
    vp.button(text="Pause", bind=Pause)
    vp.scene.append_to_caption('\n')
    t = vp.slider(min=-20000, max=20000, value=1, length=675, bind=setyear)
    vp.scene.append_to_caption('\n')
    print("B")
    celestpos = Jacob(t.value)
    # makes the sun shine
    vp.sphere(color=vp.color.yellow, emissive=True)
    vp.local_light(pos=vp.vector(0, 0, 0), color=vp.color.yellow)
    # creates the visual representation of the planets
    earth = vp.sphere(texture=vp.textures.earth,
                      pos=vp.vector(celestpos[0] / 10000000,
                                    celestpos[1] / 10000000,
                                    celestpos[2] / 10000000),
                      make_trail=True,
                      trail_type="points",
                      interval=10,
                      retain=25)
    mars = vp.sphere(color=vp.vector(1, 0, 0),
                     pos=vp.vector(celestpos[3] / 10000000,
                                   celestpos[4] / 10000000,
                                   celestpos[5] / 10000000),
                     make_trail=True,
                     trail_type="points",
                     interval=10,
                     retain=25)
    #    venus = vp.sphere(color = vp.vector(1,1,.8), pos = vp.vector(celestpos[0] / 10000000,celestpos[0] / 10000000,celestpos[0] / 10000000), make_trail=True, trail_type="points", interval=10, retain=10)
    #    mercury = vp.sphere(color = vp.vector(.3,.3,.3), pos = vp.vector(celestpos[0] / 10000000,celestpos[0] / 10000000,celestpos[0] / 10000000), make_trail=True, trail_type="points", interval=10, retain=5)
    #    moon = vp.sphere(color = vp.vector(.3,.3,.3), pos = vp.vector(Moon.xPos / 10000000, Moon.yPos / 10000000,0))
    vp.scene.append_to_caption('\n')
    sl = vp.slider(min=-20, max=20, value=1, length=675, bind=setspeed)
    while True:
        while pause == False:

            celestpos = Jacob(sl.value)
            # simulates motion
            #            Moon.simulate_orbit(i, 0)
            #            Earth.simulate_orbit(t, 0)
            #            Venus.simulate_orbit(t, 0)
            #            Mercury.simulate_orbit(t, 0)
            earth.pos = vp.vector(celestpos[0] / 10000000,
                                  celestpos[1] / 10000000,
                                  celestpos[2] / 10000000)
            mars.pos = vp.vector(celestpos[3] / 10000000,
                                 celestpos[4] / 10000000,
                                 celestpos[5] / 10000000)
            #            venus.pos = vp.vector(Venus.xPos / 10000000,Venus.yPos / 10000000,0)
            #            mercury.pos = vp.vector(Mercury.xPos / 10000000, Mercury.yPos / 10000000,0)
            #       moon.pos = vp.vector(Moon.xPos / 10000000, Moon.yPos / 10000000,0)
            if (sl.value > 0):
                t.value += 1
                time.sleep(0.01)
            else:
                t.value -= 1
                time.sleep(.01)
Пример #2
0
def form_box():
    """
    this function handle the form box
    :return: None
    """
    text_box.text = TEXT_BOX_STYLE
    scene.bind(KEY_RECOGNIZE_BY, key_input)
    vpython.button(bind=word_checker, text=lang.BUTTON_TEXT)
Пример #3
0
    def __add_mode_button(self):
        """
        Adds a button to the UI that toggles the UI mode

        :returns: A button
        :rtype: class:`vpython.button`
        """
        btn_text = self.__toggle_button_text_dict.get(self.__ui_mode, "Unknown Mode Set")

        self.scene.append_to_caption('\n')
        btn_toggle = button(bind=self.__toggle_mode, text=btn_text)
        self.scene.append_to_caption('\n\n')

        return btn_toggle
Пример #4
0
def Reset():
    vp.scene.width = 800
    vp.scene.height = 800
    vp.scene.range = 1.3
    vp.scene.title = "ANTIKYTHERA\n"
    vp.button(text="display", bind=display, pos=vp.scene.title_anchor)
    vp.scene.append_to_title('\n')
    vp.button(text="display at", bind=showat, pos=vp.scene.title_anchor)
    vp.scene.append_to_title('\n')
    vp.button(text="credits", bind=credits, pos=vp.scene.title_anchor)
    vp.scene.append_to_title('\n')
    vp.winput(bind=seteclipse, pos=vp.scene.title_anchor, text = 'YEAR')
    vp.button(text="eclipes predictor", bind=prediction, pos=vp.scene.title_anchor)
    vp.scene.append_to_title('\n')
    current_date = datetime.datetime.today()
    guidate = vp.wtext(text=" ")
Пример #5
0
    def __setup_ui_controls(self, list_of_names):
        """
        The initial configuration of the user interface

        :param list_of_names: A list of names of the robots in the screen
        :type list_of_names: `list`
        """
        # Button to reset camera
        btn_reset = button(bind=self.__reset_camera, text="Reset Camera")
        self.scene.append_to_caption('\t')

        chkbox_cam = checkbox(bind=self.__camera_lock_checkbox, text="Camera Lock", checked=self.__camera_lock)
        self.scene.append_to_caption('\t')

        chkbox_rel = checkbox(bind=self.__grid_relative_checkbox, text="Grid Relative", checked=self.__grid_relative)
        self.scene.append_to_caption('\n\n')

        # Drop down for robots / joints in frame
        menu_robots = menu(bind=self.__menu_item_chosen, choices=list_of_names)
        if not len(list_of_names) == 0:
            menu_robots.index = self.__selected_robot
        self.scene.append_to_caption('\t')

        # Button to delete the selected robot
        btn_del = button(bind=self.__del_robot, text="Delete Robot")
        self.scene.append_to_caption('\t')

        # Button to clear the robots in screen
        btn_clr = button(bind=self.clear_scene, text="Clear Scene")
        self.scene.append_to_caption('\n\n')

        # Checkbox for grid visibility
        chkbox_grid = checkbox(bind=self.__grid_visibility_checkbox, text="Grid Visibility",
                               checked=self.__grid_visibility)
        self.scene.append_to_caption('\t')

        # Checkbox for reference frame visibilities
        if len(self.__robots) == 0:
            chkbox_ref = checkbox(bind=self.__reference_frame_checkbox, text="Show Reference Frames", checked=True)
        else:
            chk = self.__robots[self.__selected_robot].ref_shown
            chkbox_ref = checkbox(bind=self.__reference_frame_checkbox, text="Show Reference Frames", checked=chk)
        self.scene.append_to_caption('\t')

        # Checkbox for robot visibility
        if len(self.__robots) == 0:
            chkbox_rob = checkbox(bind=self.__robot_visibility_checkbox, text="Show Robot", checked=True)
        else:
            chk = self.__robots[self.__selected_robot].rob_shown
            chkbox_rob = checkbox(bind=self.__robot_visibility_checkbox, text="Show Robot", checked=chk)
        self.scene.append_to_caption('\n\n')

        # Slider for robot opacity
        self.scene.append_to_caption('Opacity:')
        if len(self.__robots) == 0:
            sld_opc = slider(bind=self.__opacity_slider, value=1)
        else:
            opc = self.__robots[self.__selected_robot].opacity
            sld_opc = slider(bind=self.__opacity_slider, value=opc)
        # self.scene.append_to_caption('\n\n')

        # Prevent the space bar from toggling the active checkbox/button/etc (default browser behaviour)
        self.scene.append_to_caption('''
                    <script type="text/javascript">
                        $(document).keyup(function(event) {
                            if(event.which === 32) {
                                event.preventDefault();
                            }
                        });
                    </script>''')
        # https://stackoverflow.com/questions/22280139/prevent-space-button-from-triggering-any-other-button-click-in-jquery

        # Control manual
        controls_str = '<br><b>Controls</b><br>' \
                       '<b>PAN</b><br>' \
                       'W , S | <i>forward / backward</i><br>' \
                       'A , D | <i>left / right</i><br>' \
                       'SPACE , SHIFT | <i>up / down</i><br>' \
                       '<b>ROTATE</b><br>' \
                       'CTRL + LMB | <i>free spin</i><br>' \
                       'ARROWS KEYS | <i>rotate direction</i><br>' \
                       'Q , E | <i>roll left / right</i><br>' \
                       '<b>ZOOM</b></br>' \
                       'MOUSEWHEEL | <i>zoom in / out</i><br>' \
                       '<script type="text/javascript">var arrow_keys_handler = function(e) {switch(e.keyCode){ case 37: case 39: case 38:  case 40: case 32: e.preventDefault(); break; default: break;}};window.addEventListener("keydown", arrow_keys_handler, false);</script>'
        # Disable the arrow keys from scrolling in the browser
        # https://stackoverflow.com/questions/8916620/disable-arrow-key-scrolling-in-users-browser
        self.scene.append_to_caption(controls_str)

        return [btn_reset, menu_robots, chkbox_ref, chkbox_rob, chkbox_grid, chkbox_cam, chkbox_rel, sld_opc, btn_del,
                btn_clr]
Пример #6
0
 def __init__(self, bind: Callable, text: str, helptext: str):
     global last_div_id
     self._button = vpython.button(text=text, bind=bind)
     last_div_id += 1
     vpython.canvas.get_selected().append_to_caption(
         f"<span class='helptext'>{helptext}</span>\n")
Пример #7
0
 def __start_over_button__(self):
     vp.button(bind=self.GI.restart_agent, text='Restart')
Пример #8
0
 def __step_button__(self):
     vp.button(bind=self.GI.determine_agent_step, text='Step')
Пример #9
0
 def makeColorbar(self, doOrnaments=True, colorscale='jet', bg='default'):
     title = None
     if doOrnaments:
         title = MooView.consolidatedTitle + "\n"
     barWidth = SCALE_SCENE * 1.5
     self.colorbar = vp.canvas(title=title,
                               width=barWidth,
                               height=self.swy * SCALE_SCENE,
                               background=bgLookup(bg),
                               align='left',
                               range=1,
                               autoscale=False)
     #self.colorbar = vp.canvas( title = title, width = barWidth, height = self.swy * SCALE_SCENE, background = vp.color.cyan, align = 'left', range = 1, autoscale = False )
     self.colorbar.userzoom = False
     self.colorbar.userspin = False
     self.colorbar.userpan = False
     height = 0.10
     width = 5
     axOrigin = vp.vector(0, -5.5, 0)
     for idx, rgb in enumerate(self.rgb):
         cbox = vp.box(canvas=self.colorbar,
                       pos=vp.vector(0, height * (idx - 26), 0),
                       width=width,
                       height=height,
                       color=rgb)
     barName = self.title.replace(' ', '\n')
     self.barName = vp.label(canvas=self.colorbar,
                             align='left',
                             pixel_pos=True,
                             pos=vp.vector(2,
                                           (self.swy - 0.32) * SCALE_SCENE,
                                           0),
                             text=barName,
                             height=15,
                             color=vp.color.black,
                             box=False,
                             opacity=0)
     self.barMin = vp.label(canvas=self.colorbar,
                            align='center',
                            pixel_pos=True,
                            pos=vp.vector(barWidth / 2,
                                          self.swy * SCALE_SCENE * 0.22, 0),
                            text="{:.3f}".format(self.valMin),
                            height=12,
                            color=vp.color.black,
                            box=False,
                            opacity=0)
     self.barMax = vp.label(canvas=self.colorbar,
                            align='center',
                            pixel_pos=True,
                            pos=vp.vector(barWidth / 2,
                                          (self.swy - 1.2) * SCALE_SCENE,
                                          0),
                            text="{:.3f}".format(self.valMax),
                            height=12,
                            color=vp.color.black,
                            box=False,
                            opacity=0)
     self.xAx = vp.cylinder(canvas=self.colorbar,
                            pos=axOrigin,
                            axis=vp.vector(0.8, 0, 0),
                            radius=0.04,
                            color=vp.color.red)
     self.yAx = vp.cylinder(canvas=self.colorbar,
                            pos=axOrigin,
                            axis=vp.vector(0, 0.8, 0),
                            radius=0.04,
                            color=vp.color.green)
     self.zAx = vp.cylinder(canvas=self.colorbar,
                            pos=axOrigin,
                            axis=vp.vector(0, 0, 0),
                            radius=0.04,
                            color=vp.color.blue)
     self.axisLength = vp.label(pos=axOrigin + vp.vector(0, 1, 0),
                                text="1.00 <i>u</i>m",
                                color=vp.color.black,
                                box=False)
     if doOrnaments:
         self.timeLabel = vp.wtext(text="Time =  0.000 sec",
                                   pos=self.colorbar.title_anchor)
         self.sleepLabel = vp.wtext(text="    Frame dt = 0.005 sec",
                                    pos=self.colorbar.title_anchor)
         self.sleepSlider = vp.slider(pos=self.colorbar.title_anchor,
                                      length=200,
                                      bind=self.setSleepTime,
                                      min=0.0,
                                      max=0.2,
                                      value=self.sleep)
         self.replayButton = vp.button(text="Start Replay",
                                       pos=self.colorbar.title_anchor,
                                       bind=self.toggleReplay,
                                       disabled=True)
         self.colorbar.append_to_title("\n")
Пример #10
0
def setyear(y):
    year = y


pause = False

t = 0

day = 0


def Pause(a):
    global pause
    pause = not pause


vp.scene.width = 800
vp.scene.height = 800
vp.scene.range = 1.3
vp.scene.title = "ANTIKYTHERA\n"

vp.button(text="display", bind=display, pos=vp.scene.title_anchor)
vp.scene.append_to_title('\n')
vp.button(text="display at", bind=showat, pos=vp.scene.title_anchor)
vp.scene.append_to_title('\n')
vp.winput(bind=setday, pos=vp.scene.title_anchor)
vp.winput(bind=setmonth, pos=vp.scene.title_anchor)
vp.winput(bind=setyear, pos=vp.scene.title_anchor)
vp.scene.append_to_title('\n')
print("A")
def Run(b):
    global running
    running = not running
    if running:
        b.text = "Pause"
    else:
        b.text = "Run"


# Create a Vpython Canvas for the T_shaped_handle Animation
origin = vp.vector(0, 0, 0)
T_shaped_handle = vp.canvas(width=900, height=740, center=origin)
T_shaped_handle.align = 'right'
T_shaped_handle.forward = vp.vector(-1, -.03, -1)
T_shaped_handle.background = vp.color.white
button = vp.button(text="Pause", pos=T_shaped_handle.title_anchor, bind=Run)

# Create the T-shaped handle from the T_shaped_handle Effect
p_hat_pos = vp.cylinder(pos=origin,
                        axis=vp.vector(Px[0], Py[0], Pz[0]),
                        radius=.15,
                        color=vp.color.gray(.65))
p_hat_neg = vp.cylinder(pos=origin,
                        axis=vp.vector(-Px[0], -Py[0], -Pz[0]),
                        radius=.15,
                        color=vp.color.gray(.65))
q_hat_DE = vp.cylinder(pos=origin,
                       axis=vp.vector(Qx[0], Qy[0], Qz[0]),
                       radius=.1,
                       color=vp.color.gray(.65))
Пример #12
0
# SET THE SCENE AND 3D OBJECTS
scene = vp.canvas(width=500,
                  height=400,
                  userspin=False,
                  userzoom=False,
                  title="Ideal Pendulum Simulation by haiq70",
                  autoscale=False,
                  center=vp.vector(0, -3, 0))
bob = vp.sphere(pos=vp.vector(0, -length, 0), radius=0.5)
string = vp.cylinder(pos=vp.vector(0, 0, 0),
                     axis=vp.vector(0, -length, 0),
                     radius=0.02)

# BUTTONS
vp.button(bind=start_button_clicked, text='Start')
vp.button(bind=pause_button_clicked, text='Pause')
scene.append_to_caption('\n\n')

# SLIDER (SPATIAL DEVIATION)
scene.append_to_caption("Spatial deviation: ")
slider_sd = vp.slider(min=0.1, max=90, bind=get_theta, step=0.1, value=5)
theta_output = vp.wtext(text=slider_sd.value)
scene.append_to_caption(" \u00b0 \n")

# SLIDER (LENGTH OF THE STRING)
scene.append_to_caption("Length of the string: ")
slider_l = vp.slider(min=0.1, max=10, bind=get_length, step=0.1, value=3)
length_output = vp.wtext(text=slider_l.value)
scene.append_to_caption(" m\n\n")
    def start(self):
        """open the vpython window and start the simulation"""
        # set up important boolean values from options
        testing = self.options.testing
        central_centered = self.options.central_centered
        show_pointers = self.options.pointers

        # set up canvas, bodies and pointers
        scene = vp.canvas(title="Simulation zum Zweikörperproblem",
                          height=self.options.canvas.height,
                          width=self.options.canvas.width)
        central = Body(sim=self,
                       name="central",
                       mass=self.values.central.mass,
                       velocity=vp.vector(self.values.central.velocity.x,
                                          self.values.central.velocity.y,
                                          self.values.central.velocity.z),
                       radius=self.values.central.radius,
                       make_trail=True,
                       color=vp.vector(self.options.colors.bodies.x / 255,
                                       self.options.colors.bodies.y / 255,
                                       self.options.colors.bodies.z / 255))
        sat = Body(sim=self,
                   name="sat",
                   mass=self.values.sat.mass,
                   velocity=vp.vector(self.values.sat.velocity.x,
                                      self.values.sat.velocity.y,
                                      self.values.sat.velocity.z),
                   pos=vp.vector(
                       self.values.distance + self.values.central.radius +
                       self.values.sat.radius, 0, 0),
                   radius=self.values.sat.radius,
                   make_trail=True,
                   color=vp.vector(self.options.colors.bodies.x / 255,
                                   self.options.colors.bodies.y / 255,
                                   self.options.colors.bodies.z / 255))
        central_ptr = vp.arrow()
        sat_ptr = vp.arrow()
        if show_pointers:
            central_ptr = vp.arrow(axis=vp.vector(
                0, -((self.values.distance + central.radius + sat.radius) / 2),
                0),
                                   color=vp.vector(
                                       self.options.colors.pointers.x,
                                       self.options.colors.pointers.y,
                                       self.options.colors.pointers.z))
            central_ptr.pos = (central.pos - central_ptr.axis) + vp.vector(
                0, self.values.central.radius, 0)
            sat_ptr = vp.arrow(axis=vp.vector(
                0, -((self.values.distance + central.radius + sat.radius) / 2),
                0),
                               color=vp.vector(self.options.colors.pointers.x,
                                               self.options.colors.pointers.y,
                                               self.options.colors.pointers.z))
            sat_ptr.pos = sat.pos - sat_ptr.axis + vp.vector(
                0, self.values.sat.radius, 0)

        # set up buttons
        pause_sim = vp.button(text="Pause", bind=self.pause)
        vp.button(text="Stop",
                  bind=lambda: os.kill(os.getpid(), signal.SIGINT))
        vp.button(text="Restart", bind=self.restart)
        scene.append_to_caption("\n")

        # set up sliders for changing the radius of the two bodies
        central_slider = vp.slider(
            max=((self.values.distance + self.values.central.radius) /
                 self.values.central.radius),
            min=1,
            value=1,
            top=12,
            bottom=12,
            bind=lambda: self.adjust_radius(slider=central_slider,
                                            sphere=central))
        vp.button(text="Reset", bind=lambda: self.reset_slider(central_slider))
        scene.append_to_caption("\n")
        sat_slider = vp.slider(
            max=((self.values.distance + self.values.sat.radius) /
                 self.values.sat.radius),
            min=1,
            value=1,
            top=12,
            bottom=12,
            bind=lambda: self.adjust_radius(slider=sat_slider, sphere=sat))
        vp.button(text="Reset", bind=lambda: self.reset_slider(sat_slider))

        # set up time variables
        t = 0
        t_max = self.options.rate * self.options.sim_time
        # main simulation loop
        if central_centered:
            scene.camera.follow(central)
        while t <= t_max:
            # weird behaviour of those two
            vp.rate(self.options.rate)
            # vp.sleep(1/self.options["update_rate"])
            if pause_sim.text == "Pause":
                # physical calculations
                r = sat.pos - central.pos
                fv = (6.67430e-11 * central.mass * sat.mass) / (vp.mag(r)**2)
                central.force = fv * vp.norm(r)
                sat.force = fv * vp.norm(-r)
                central.calculate(self.options.delta_t)
                sat.calculate(self.options.delta_t)
                if show_pointers:
                    # move pointers
                    central_ptr.pos = central.pos - central_ptr.axis + \
                                      vp.vector(0, central.radius, 0)
                    sat_ptr.pos = sat.pos - sat_ptr.axis + vp.vector(
                        0, sat.radius, 0)
                if self.options.sim_time > 0:
                    t += 1
        if bool(self.options.restart):
            self.restart()
Пример #14
0
vp.scene.append_to_title("<div id='fps'/>")

run = True


def Runbutton(b):
    global run
    if b.text == 'Pause':
        run = False
        b.text = 'Run'
    else:
        run = True
        b.text = 'Pause'


vp.button(text='Pause', bind=Runbutton)
vp.scene.append_to_caption("""
To rotate "camera", drag with right button or Ctrl-drag.
To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel.
  On a two-button mouse, middle is left + right.
To pan left/right and up/down, Shift-drag.
Touch screen: pinch/extend to zoom, swipe or two-finger rotate.""")

p = []
last = vp.vec(0, 0, 0)
for i in range(N):
    next = last + 0.1 * vp.vec.random()
    while vp.mag(
            next
    ) > 1:  # if next is outside the sphere, try another random value
        next = last + 0.1 * vp.vec.random()
import vpython as vp
import numpy as np
import sys

vp.box()


def B(b):
    print("The button said this: ", b.text)


vp.button(bind=B, text='Click me!')
# vp.scene.append_to_caption('\n\n')


def T(s):
    print(s, type(s.number), s.number)


vp.winput(bind=T)

# def R(r):
#     print(r.checked)  # alternates
#
#
# vp.radio(bind=R, text='Run')  # text to right of button
# vp.scene.append_to_caption('\n\n')
#
#
# def C(r):
#     print(r.checked)  # alternates
Пример #16
0
def create_widgets():
    Game.scene1.append_to_caption("\n\n")
    # ------- roughness of terrain ----------------
    Game.scene1.append_to_caption("change terrain roughness to")
    Game.slider_roughness = v.slider(bind=func_roughness,
                                     min=0,
                                     max=1.0,
                                     step=0.01,
                                     value=Game.roughness,
                                     length=500)
    Game.label_roughness = v.wtext(
        text=f" ={Game.roughness:.2f} (0 = very smooth, 1= very rough)")
    Game.scene1.append_to_caption(Game.label_roughness)
    Game.scene1.append_to_caption(
        v.button(text="generate new landscape", bind=func_recalc))
    Game.scene1.append_to_caption("\n\n")
    # ---- winputs fields: fields that accept an text entry that will be converted into a number ---
    Game.scene1.append_to_caption("type in values and press ENTER:\n\n ")
    # --------sea level---------------
    Game.scene1.append_to_caption("change sea level to")
    #Game.input_sea_level = v.slider(bind=func_sea_level, min=0.0, max=Game.snow_level, step=0.01, value=Game.sea_level)
    Game.input_sea_level = v.winput(bind=func_sea_level,
                                    type="numeric",
                                    text=Game.sea_level)
    Game.label_sea_level = v.wtext(text=f" ={Game.sea_level:.2f} ")
    Game.scene1.append_to_caption(Game.label_sea_level)
    Game.scene1.append_to_caption(" (must be lesser than snow level)\n\n")
    # ------- snow level --------------
    Game.scene1.append_to_caption("change snow level to")
    #Game.input_snow_level = v.slider(bind=func_snow_level, min=Game.sea_level, max=1.0, step=0.01, value=Game.snow_level)
    #Game.label_snow_level = v.wtext(text=f"{Game.snow_level*100:.0f} % of (max. height- min. height) = {Game.min_y + Game.snow_level*(Game.max_y-Game.min_y):.2f}")
    Game.input_snow_level = v.winput(bind=func_snow_level,
                                     type="numeric",
                                     text=Game.snow_level)
    Game.label_snow_level = v.wtext(text=f" ={Game.snow_level:.2f} ")
    Game.scene1.append_to_caption(Game.label_snow_level)
    Game.scene1.append_to_caption(" (must be greater than sea level)\n\n")

    # --------world size ---------------
    Game.scene1.append_to_caption("change world size to: ")
    #Game.input_world_size = v.slider(bind=func_world_size, min=1, max=100, step=1,
    #                                  value=Game.world_size)
    Game.input_world_size = v.winput(bind=func_world_size,
                                     type="numeric",
                                     text=Game.world_size)
    Game.label_world_size = v.wtext(
        text=f" = {Game.world_size} x {Game.world_size} tiles")
    Game.scene1.append_to_caption(Game.label_world_size)
    Game.scene1.append_to_caption("\n\n")
    # -------- min height, max height --------------
    Game.scene1.append_to_caption("change minimum height to:")
    Game.input_min_y = v.winput(bind=func_min_y,
                                type="numeric",
                                text=Game.min_y)
    Game.label_min_y = v.wtext(text=f" ={Game.min_y:.2f}")
    Game.scene1.append_to_caption(Game.label_min_y)
    Game.scene1.append_to_caption("  change maximum height to:")
    Game.input_max_y = v.winput(bind=func_max_y,
                                type="numeric",
                                text=Game.max_y)
    Game.label_max_y = v.wtext(text=f" ={Game.max_y:.2f}")
    Game.scene1.append_to_caption(Game.label_max_y)
    Game.scene1.append_to_caption("\n\n")
    # --------
    Game.scene1.append_to_caption("change color of ")
Пример #17
0
import numpy as np
import _thread

start = False

solenoid_list = []


def Standard():
    solenoid_list.append(
        SolenoidClass(vp.vec(-30, 0, 0), vp.vec(1, 0, 0), 10, 1, 1000, 50))
    solenoid_list.append(
        SolenoidClass(vp.vec(30, 0, 0), vp.vec(1, 0, 0), 10, 1, 1000, 50))


vp.button(bind=Standard, text='standard for testing')

Electrons = []
elec_vel = 1e6


def Electron():

    e = vp.sphere(pos=vp.vec(0, 5, 0),
                  radius=0.3,
                  color=vp.color.red,
                  make_trail=True,
                  retain=250)
    e.velocity = elec_vel * vp.vec(1, .3, .3)  #need to do angle thing
    Electrons.append(e)
    print('done')
vp.scene.title = "                                                                     <b>Visualizacion proyecto Practica Docente</b>\n\n"
vp.scene.background = vp.color.black
vp.scene.width = 1000 
vp.scene.height = 600

# BOTONES
running = False

def Run(b):
    global running
    running = not running
    if running: b.text = "Pause"
    else: b.text = "Run"

vp.button(text="Run", pos=vp.scene.title_anchor, bind=Run)    

t = 0
def Reset(r):
    global t
    t=0
    if menu.selected=="Informacion": mod_esc.escenario1_reiniciar()
    elif menu.selected=="Rutherford Scattering": mod_esc.escenario2_reiniciar()
    elif menu.selected=="Compton Scattering": mod_esc.escenario3_reiniciar()
    Ejecutar(menu)

vp.button(text="Reset", pos=vp.scene.title_anchor, bind=Reset)    

particula_enfocada=False
def mover_camara(posicion_nueva):
    global particula_enfocada
Пример #19
0
    def __init__(self):
        # When the user clicks a button, this will be set.
        self._user_args: Optional[List[str]] = None
        self._program: Optional[programs.Program] = None

        canvas = vpython.canvas(width=1, height=1)

        # Some basic but nice styling.
        common.include_vpython_footer_file(
            Path('orbitx', 'graphics', 'simple_css.css'))
        canvas.append_to_caption("""<style>
            .argname {
                font-weight: bold;
            }
        </style>""")

        # Set up some buttons asking what program the user wants to run.
        canvas.append_to_caption("<h1>OrbitX Launcher</h1>")
        canvas.append_to_caption("<h2>Select a program to launch</h2>")
        canvas.append_to_caption(
            "<input type='checkbox' id='description_checkbox'>"
            "Show descriptions"
            "</input>")

        for program in programs.LISTING:
            text_fields: List[vpython.winput] = []
            canvas.append_to_caption("<hr />")
            canvas.append_to_caption(f"<h3>{program.name}</h3>")
            vpython.button(text=f'Launch {program.name}!',
                           bind=functools.partial(self._set_args, program,
                                                  text_fields))
            canvas.append_to_caption(f"<p>{program.description}</p>")

            for arg in program.argparser._actions:
                if '--help' in arg.option_strings:
                    # This is the default help action, ignore it.
                    continue
                canvas.append_to_caption(
                    f"<span class='argname'>{arg.dest}:</span>")
                canvas.append_to_caption(
                    f"<span class='description'> {arg.help}</span>&nbsp;")
                arg_field = vpython.winput(
                    # The bind is a no-op, we'll poll the .text attribute.
                    type='string',
                    bind=lambda _: None,
                    text=arg.default)
                canvas.append_to_caption("<br />")

                # Monkey-patch this attribute so that we can build CLI args
                # properly.
                arg_field.arg = arg

                text_fields.append(arg_field)
                vpython_widgets.last_div_id += 1

        common.remove_vpython_css()

        # Make clicking the per-program launch button also submit all the args
        # that the user has entered.
        canvas.append_to_caption("""<script>
            buttons = document.querySelectorAll("button");
            for (const element of buttons) {
                element.addEventListener('mousedown', function(ev) {
                    // Send an 'enter' keypress so that python code gets the
                    // current value of each text input.
                    inputs = document.querySelectorAll('input');
                    for (const input of inputs) {
                        var ev = document.createEvent('Event');
                        ev.initEvent('keypress');
                        ev.keyCode = 13;
                        input.dispatchEvent(ev);
                    }
                });
            }

            description_checkbox = document.querySelector(
                '#description_checkbox');
            description_checkbox.addEventListener('change', function(event) {
                console.log(event);
                descriptions = document.getElementsByClassName("description");
                for (const element of descriptions) {
                    element.style.display = (event.target.checked ?
                        "initial" : "none"
                    );
                }
            })
        </script>""")

        # This is needed to launch vpython.
        vpython.sphere()
        vpython.canvas.get_selected().delete()
Пример #20
0
 def __auto_stepping_button__(self):
     vp.button(bind=self.GI.auto_stepping, text='Automate Episode')
Пример #21
0
day = 0
month = 0
#variables used for simulation control
current_date = datetime.datetime.today() # current date of the simulation
guiday = str(current_date.day)
guimonth = str(current_date.month)
guiyear = str(current_date.year)
#setting the scene
vp.scene.width = 800
vp.scene.height = 800
vp.scene.range = 1.3
vp.scene.title = "ANTIKYTHERA\n"
#vp.scene.append_to_title('\n')
vp.scene.append_to_title('\n')
#vp.scene.append_to_title('\n')
vp.button(text="credits", bind=credits, pos=vp.scene.title_anchor)
#vp.scene.append_to_title('\n')
#vp.scene.append_to_title('\n')
vp.wtext(text = "--------------------------------------------------------------\n")
vp.wtext(text = "                      SOLAR SYSTEM SIMULATOR \n")
vp.wtext(text = "--------------------------------------------------------------\n")
vp.wtext(text = "\nPress ")
vp.button(text="Start", bind=start)
vp.wtext(text = " to start the simulation\n")
vp.wtext(text = "\nEnter a date in 'mm/dd/yyyy' ")
vp.winput(bind=setdate, type="string")
vp.wtext(text = " and press the 'Enter' key to simulate the system at that time")
dateErrorText = vp.wtext(text = "\n")
vp.wtext(text = "\nThis is the current date: \n")
vp.wtext(text = "-----------------\n")
guidate = vp.wtext(text=" ")
Пример #22
0
 def __clear_records_button__(self):
     vp.button(bind=self.GI.clear_records, text='Clear Records')
Пример #23
0
def visualize(cluster, animation=False, transparent=False, scale=None, origin='auto'):
    """
    Create a 3D visualization of a particle cluster using VPython
    
    Arguments:
        cluster      sphere or particle cluster
        animation    (bool) an animation visualization
        transparent  (bool) transparent particles
        scale        (str) if set, display a scale bar
        origin       origin of camera view ('auto' for centroid, 'cluster' for cluster origin, or np.array)
    """
    import vpython
    vec = vpython.vec
    # scene = vpython.canvas(width=750, height=600, background=vec(1,1,1))

    if origin == 'auto':
        origin = vec(*np.average(cluster.position, axis=0))/nm
    elif origin == 'cluster':
        origin = vec(*cluster.origin)/nm
    else:
        origin = vec(*origin)/nm

    scene = vpython.canvas(width=500, height=325, background=vec(1,1,1), center=origin)

    if type(cluster) == miepy.sphere_cluster:
        for i in range(cluster.Nparticles):
            position = cluster.position[i]/nm
            radius = cluster.radius[i]/nm
            paint = get_paint(cluster.material[i])

            sphere = vpython.sphere(pos=vec(*position), radius=radius, texture=paint.texture, color=paint.color, shininess=paint.shininess)

    elif type(cluster) == miepy.cluster:
        for i in range(cluster.Nparticles):
            particle = cluster.particles[i]
            paint = get_paint(particle.material)

            obj = draw_particle(particle, paint)

    if transparent:
        for obj in scene.objects:
            obj.opacity = .5
            
    if cluster.interface is not None:
        scene.autoscale = False
        length = height = 1e-3/nm
        width = 1e-3/nm
        z = cluster.interface.z
        box = vpython.box(pos=vec(0,0,-z-width/2), width=width, height=height, length=length,
        color=vec(0.6,0.6,0.6), shininess=0)

    if animation:
        T = 300
        # cluster = vpython.compound(scene.objects)
        # cluster.rotate(angle=2*np.pi/T, origin=vec(0,0,0), axis=vec(0,1,0))

        scene.append_to_caption('\n')

        def setspeed(s):
            nonlocal T
            wt.text = 'f = {:1.2f} Hz'.format(s.value)
            T = 30/s.value
            
        sl = vpython.slider(min=0.01, max=.3, value=.1, length=180, bind=setspeed, right=15, top=7)
        wt = vpython.wtext(text='f = {:1.2f} Hz'.format(sl.value))

        def transparency(b):
            if b.checked:
                for obj in scene.objects:
                    obj.opacity = .5
            else:
                for obj in scene.objects:
                    obj.opacity = 1

        scene.append_to_caption('    ')
        vpython.checkbox(bind=transparency, text='Transparent')

        running = True
        def Run(b):
            nonlocal running
            running = not running
            if running:
                b.text = " ▌▌"
                b.color = vec(1,0,0)
            else:
                b.text = "  ►  "
                b.color = vec(0,.6,0)

        scene.append_to_caption('       ')
        vpython.button(text=" ▌▌", bind=Run, color=vec(1,0,0))


        for t in count():
            vpython.rate(30)

            # phi = 2*np.pi*t/T
            # scene.forward = vec(-np.sin(phi), 0, -np.cos(phi))
            
            if running:
                for obj in scene.objects:
                    obj.rotate(angle=2*np.pi/T, origin=origin, axis=vec(0,1,0))