def add_widgets(scene, cyclotron): """ Adds menus and sliders to the window to allow you to control the camera and simulation parameters. It's not important to understand this function. """ def follow_body(menu): scene.camera.follow(cyclotron.bodies[menu.index].visual) def change_dt(slider): global dt dt = 10 ** slider.value dt_text.text = "dt={:.2e}s:".format(dt) def change_E(slider): global E_mag E_mag = 10 ** slider.value E_text.text = "|E|={:.2e}s:".format(E_mag) def change_B(slider): global B_mag B_mag = 10 ** slider.value cyclotron.b_field = vec(0, 0, -B_mag) B_text.text = "|B|={:.2e}s:".format(B_mag) def toggle_infobox(checkbox): for body in cyclotron.bodies: body.info.visible = checkbox.checked def toggle_controls(checkbox): cyclotron.controls_label.visible = checkbox.checked vis.wtext(pos = scene.title_anchor, text = " ") vis.wtext(pos = scene.title_anchor, text = "Focus: ") vis.menu(pos = scene.title_anchor, choices = list(map(lambda body: body.name, cyclotron.bodies)), bind = follow_body) vis.wtext(pos = scene.title_anchor, text = " ") dt_text = vis.wtext(pos = scene.title_anchor, text = "dt={:.2e}s:".format(dt)) vis.slider(pos = scene.title_anchor, min = -15, max = -9, value = np.log10(dt), bind = change_dt, length = 200) E_text = vis.wtext(pos = scene.title_anchor, text = "|E|={:.2e}N/m:".format(E_mag)) vis.slider(pos = scene.title_anchor, min = 0, max = 12, value = np.log10(E_mag), bind = change_E, length = 200) B_text = vis.wtext(pos = scene.title_anchor, text = "|B|={:.2e}N/m:".format(B_mag)) vis.slider(pos = scene.title_anchor, min = -4, max = 0, value = np.log10(B_mag), bind = change_B, length = 200)
def __init__(self, choices: List[str], selected: str, bind: Callable, caption: str, helptext: str): global last_div_id self._menu = vpython.menu(choices=choices, selected=selected, bind=bind) last_div_id += 1 vpython.canvas.get_selected().append_to_caption( f" <b>{caption}</b> ") vpython.canvas.get_selected().append_to_caption( f"<span class='helptext'>{helptext}</span><br/>\n")
def add_widgets(scene, solar_system): """ Adds menus and sliders to the window to allow you to control the camera and simulation parameters. It's not important to understand this function. """ def follow_body(menu): scene.camera.follow(solar_system.bodies[menu.index].visual) def change_dt(slider): global dt dt = 10 ** slider.value dt_text.text = "dt={:.2e}s:".format(dt) def toggle_infobox(checkbox): for body in solar_system.bodies: body.info.visible = checkbox.checked def toggle_controls(checkbox): solar_system.controls_label.visible = checkbox.checked vis.wtext(pos = scene.title_anchor, text = " ") vis.wtext(pos = scene.title_anchor, text = "Focus: ") vis.menu(pos = scene.title_anchor, choices = list(map(lambda body: body.name, solar_system.bodies)), bind = follow_body) vis.wtext(pos = scene.title_anchor, text = " ") dt_text = vis.wtext(pos = scene.title_anchor, text = "dt={:.2e}s:".format(dt)) vis.slider(pos = scene.title_anchor, min = 0, max = 6, value = np.log10(dt), bind = change_dt) vis.wtext(pos = scene.title_anchor, text = " ") vis.checkbox(pos = scene.title_anchor, text = "Enable infoboxes", checked = True, bind = toggle_infobox) vis.wtext(pos = scene.title_anchor, text = " ") vis.checkbox(pos = scene.title_anchor, text = "Show controls", checked = False, bind = toggle_controls)
try: if running: mod_esc.escenario3_avance(dt) if mod_esc.n==20: message[2]+=""" El scattering de Compton, hace referencia al efecto que un foton presenta al incidir a un electron en reposo. \n Al incidirlo, el electron se deflecta y el foton se dispersa con un angulo que se conoce como angulo de dispersion.\n <img src="imagenes/comptonDiagram.png" width=500 height=300>\n El foton al ser dispersado, cambia su longitud de onda, siguiendo la formula de Rutheford:\n\n"""+' <img src="imagenes/comptonEquation.png" width=200 height=60>\n >' vp.scene.caption = message[2] break except: break else: # el evento == "Elige un escenario" vp.scene.caption=mensajeInicio mensajeInicio="""\n Diferentes escenarios creados con el fin de visualizar informacion acerca de las particulas del modelo estandar, para visualizar los efectos \n de scattering de particulas alpha incidiendo un nucleo (scattering de Rutherford) y por ultimo, para visualizar el scattering de un foton incidiendo en un electron en resposo (scattering de Compton). \n\n\n\n Para el escenario de Rutherford y Compton scattering, se usaron algunas graficas tomadas de los siguientes libros: Serway, R., Moyer, C., & Moses, C. (2005). Modern physics (3rd ed., pp. 90,92). Tipler, P., & Llewellyn, R. (2020). Modern Physics (6th ed., pp. 159,162).""" vp.wtext(pos=vp.scene.title_anchor, text=" ") # Menu de eleccion de escenarios: llama a la funcion Ejecutar(m) y ejecuta el escenario con el evento m correspondiente menu=vp.menu(choices=["Elige un escenario", "Informacion", "Rutherford Scattering", "Compton Scattering"], index=0, pos=vp.scene.title_anchor, bind=Ejecutar) vp.scene.append_to_caption(' ') vp.scene.append_to_caption(mensajeInicio) vp.scene.append_to_caption('\n')
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]
################################################################################ vp.scene.camera.pos = vp.vector(0, 0, 20) vp.scene.append_to_caption('\n') vp.scene.append_to_caption('\n') vp.wtext(text = "--------------------------------------------------------------\n") vp.wtext(text = " ECLIPSE PREDICTOR \n") vp.wtext(text = "--------------------------------------------------------------\n") vp.wtext(text = "\nEnter a year to predict eclipses in: ") vp.winput(bind=prediction) vp.wtext(text = " and press the 'Enter' key ") vp.wtext(text="\n ") for i in range(7): list_of_eclipse_predictions.append(vp.wtext(text="")) planetOne = list_of_planets[0] planetTwo = list_of_planets[0] vp.wtext(text = "\n\n\n--------------------------------------------------------------\n") vp.wtext(text = " PLANETARY TRANSFER ESTIMATOR \n") vp.wtext(text = "--------------------------------------------------------------\n") #for Hohmann Transfers vp.wtext(text = "Transfer from ") vp.menu(bind = setPlanet1,choices = ['Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto']) vp.wtext(text = " to ") vp.menu(bind = setPlanet2,choices =['Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto'] ) vp.wtext(text = " ") vp.button(text="Efficient Projectile estimated date", bind = projCalc) hohmann_result = vp.wtext(text = "")