Sephfox commited on
Commit
bae4e7e
·
verified ·
1 Parent(s): 9ec2516

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -14,6 +14,7 @@ num_points = 20
14
  touch_points: List[Tuple[float, float]] = [(x, y) for x in range(50, WIDTH-50, int((WIDTH-100)/(num_points-1))) for y in range(50, HEIGHT-50, int((HEIGHT-100)/(num_points-1)))]
15
  original_points = touch_points.copy()
16
  velocities: List[Tuple[float, float]] = [(0.0, 0.0)] * len(touch_points)
 
17
 
18
  source = ColumnDataSource(data=dict(x=[x for x, y in touch_points], y=[y for x, y in touch_points]))
19
 
@@ -28,7 +29,7 @@ st.title("Artificial Touch Simulation")
28
  chart = st.bokeh_chart(p)
29
 
30
  def update_points():
31
- global touch_points, velocities
32
 
33
  # Apply spring force
34
  for i, (x, y) in enumerate(touch_points):
@@ -45,11 +46,14 @@ def update_points():
45
  vx, vy = velocities[i]
46
  touch_points[i] = (x + vx, y + vy)
47
 
 
 
 
48
  # Update Bokeh data source
49
  source.data = dict(x=[x for x, y in touch_points], y=[y for x, y in touch_points])
50
 
51
  def on_tap(event):
52
- global touch_points, velocities
53
 
54
  x, y = event.x, event.y
55
  for i, (tx, ty) in enumerate(touch_points):
@@ -58,6 +62,7 @@ def on_tap(event):
58
  force_x = (tx - x) / distance
59
  force_y = (ty - y) / distance
60
  velocities[i] = (velocities[i][0] - force_x * 10, velocities[i][1] - force_y * 10)
 
61
 
62
  st.write(f"Touch at ({x:.2f}, {y:.2f})")
63
  update_points()
 
14
  touch_points: List[Tuple[float, float]] = [(x, y) for x in range(50, WIDTH-50, int((WIDTH-100)/(num_points-1))) for y in range(50, HEIGHT-50, int((HEIGHT-100)/(num_points-1)))]
15
  original_points = touch_points.copy()
16
  velocities: List[Tuple[float, float]] = [(0.0, 0.0)] * len(touch_points)
17
+ is_affected: List[bool] = [False] * len(touch_points)
18
 
19
  source = ColumnDataSource(data=dict(x=[x for x, y in touch_points], y=[y for x, y in touch_points]))
20
 
 
29
  chart = st.bokeh_chart(p)
30
 
31
  def update_points():
32
+ global touch_points, velocities, is_affected
33
 
34
  # Apply spring force
35
  for i, (x, y) in enumerate(touch_points):
 
46
  vx, vy = velocities[i]
47
  touch_points[i] = (x + vx, y + vy)
48
 
49
+ # Reset affected flags
50
+ is_affected = [False] * len(touch_points)
51
+
52
  # Update Bokeh data source
53
  source.data = dict(x=[x for x, y in touch_points], y=[y for x, y in touch_points])
54
 
55
  def on_tap(event):
56
+ global touch_points, velocities, is_affected
57
 
58
  x, y = event.x, event.y
59
  for i, (tx, ty) in enumerate(touch_points):
 
62
  force_x = (tx - x) / distance
63
  force_y = (ty - y) / distance
64
  velocities[i] = (velocities[i][0] - force_x * 10, velocities[i][1] - force_y * 10)
65
+ is_affected[i] = True
66
 
67
  st.write(f"Touch at ({x:.2f}, {y:.2f})")
68
  update_points()