@Phuket2
Thanks again. So finally it worked. Here the total code. This plots the parabolic trajectory as a function of angle and initial velocity. I just need to figure out how to delete the previous image and not have them superimposed when the sliders are used.
import matplotlib.pyplot as plt
import numpy as np
import ui
from io import BytesIO
g=9.81
def plotparabole(alpha,v_0):
#Le programme calcule en radians, mais un input en degres est plus intuitif
alpharad=alpha*np.pi/180
#le graphe sera de 100 points, pour un temps entre 0 et 9 secondes,
#mais suivant les conditions, le temps de vol réel peut être plus court
t = np.linspace(0,9,100)
#représentation du vecteur vitesse à t=0
vit=[0,0,v_0*np.cos(alpharad),v_0*np.sin(alpharad)]
ax = plt.gca()
ax.quiver(0,0,v_0*np.cos(alpharad),v_0*np.sin(alpharad),color='red',angles='xy', scale_units='xy', scale=1)
plt.axis([0, 170, 0, 100])
#tracé de la trajectoire, grâce à des coordonnées parametrées en fonction du temps
plt.plot(v_0*np.cos(alpharad)*t, -0.5*g*t**2+v_0*np.sin(alpharad)*t)
plt.axes().set_aspect('equal')
b = BytesIO()
plt.savefig(b)
img = ui.Image.from_data(b.getvalue())
return(img)
#########################################################
def slider_action(sender):
# Get the root view:
v = sender.superview
# Get the sliders:
v0 = v['slider1'].value*40
alpha = v['slider2'].value*90
v['alpha'].text = 'alpha=%f degres' % (alpha)
v['v0'].text = 'vitesse=%f m/s' % (v0)
img=plotparabole(alpha,v0)
v['imageview1'].image=img
v = ui.load_view('Balistique')
slider_action(v['imageview1'])
if ui.get_screen_size()[1] >= 768:
# iPad
v.present('sheet')
else:
# iPhone
v.present()
and here the pyui file:
[
{
"selected" : false,
"frame" : "{{0, 0}, {560, 427}}",
"class" : "View",
"nodes" : [
{
"selected" : false,
"frame" : "{{15, 380}, {242, 34}}",
"class" : "Slider",
"nodes" : [
],
"attributes" : {
"flex" : "W",
"border_width" : 1,
"action" : "slider_action",
"frame" : "{{180, 168}, {200, 34}}",
"border_color" : "RGBA(1.000000,0.200000,0.200000,1.000000)",
"class" : "Slider",
"value" : 0.5,
"uuid" : "0EBE87B6-3527-4D66-B9D6-F1361D7BB24F",
"corner_radius" : 2,
"name" : "slider1"
}
},
{
"selected" : false,
"frame" : "{{295, 387}, {232, 34}}",
"class" : "Slider",
"nodes" : [
],
"attributes" : {
"action" : "slider_action",
"flex" : "W",
"frame" : "{{180, 168}, {200, 34}}",
"uuid" : "6D51E0F1-9BE3-4486-8962-D365342746A5",
"class" : "Slider",
"value" : 0.5,
"name" : "slider2"
}
},
{
"selected" : false,
"frame" : "{{295, 340}, {198, 32}}",
"class" : "Label",
"nodes" : [
],
"attributes" : {
"font_name" : "<System>",
"frame" : "{{205, 169}, {150, 32}}",
"uuid" : "733AE3FF-A92D-41CD-B37D-66EF27B4DD3A",
"class" : "Label",
"alignment" : "left",
"text" : "alpha",
"font_size" : 18,
"name" : "alpha"
}
},
{
"selected" : false,
"frame" : "{{15, 340}, {178, 32}}",
"class" : "Label",
"nodes" : [
],
"attributes" : {
"font_name" : "<System>",
"frame" : "{{205, 169}, {150, 32}}",
"uuid" : "733AE3FF-A92D-41CD-B37D-66EF27B4DD3A",
"class" : "Label",
"alignment" : "left",
"text" : "v0",
"name" : "v0",
"font_size" : 18
}
},
{
"selected" : true,
"frame" : "{{15, 28}, {524, 304}}",
"class" : "ImageView",
"nodes" : [
],
"attributes" : {
"alpha" : 1,
"frame" : "{{230, 164}, {100, 100}}",
"class" : "ImageView",
"background_color" : "RGBA(0.956522,1.000000,0.869565,1.000000)",
"uuid" : "60FC8613-07A2-4229-ACFE-B8DD87CC03FE",
"name" : "imageview1",
"image_name" : "iob:alert_256"
}
}
],
"attributes" : {
"enabled" : true,
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)",
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)",
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
"flex" : ""
}
}
]