Skip to content

Commit

Permalink
Merge pull request #290 from roger20ub/master
Browse files Browse the repository at this point in the history
Many photons
  • Loading branch information
brunojulia authored Jun 6, 2024
2 parents 6be76c1 + ccaaf5b commit 0f56950
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 53 deletions.
168 changes: 159 additions & 9 deletions Ekert_91_kivy/ekert91.kv
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,27 @@
source: source
label_source: label_source

photon_alice: photon_alice
photon_bob: photon_bob
photon_alice_1: photon_alice_1
photon_alice_2: photon_alice_2
photon_alice_3: photon_alice_3
photon_alice_4: photon_alice_4
photon_alice_5: photon_alice_5
photon_alice_6: photon_alice_6
photon_alice_7: photon_alice_7
photon_alice_8: photon_alice_8
photon_alice_9: photon_alice_9
photon_alice_10: photon_alice_10

photon_bob_1: photon_bob_1
photon_bob_2: photon_bob_2
photon_bob_3: photon_bob_3
photon_bob_4: photon_bob_4
photon_bob_5: photon_bob_5
photon_bob_6: photon_bob_6
photon_bob_7: photon_bob_7
photon_bob_8: photon_bob_8
photon_bob_9: photon_bob_9
photon_bob_10: photon_bob_10

alice_filter: alice_filter
bob_filter: bob_filter
Expand Down Expand Up @@ -463,6 +482,7 @@
root.stop_animation(root.alice_filter)
if root.tut_alice_button.opacity == 1: root.tut_bob_button.opacity = 1; root.filter_animation(root.bob_filter)
root.tut_alice_button.opacity = 0
root.tut_emmited.opacity = 0
Slit:
id: alice_slit
size_hint: 0.13, 0.006
Expand Down Expand Up @@ -590,30 +610,160 @@


Photon:
id: photon_alice
id: photon_alice_1
opacity: 1
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_2
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_3
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_4
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_5
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_6
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_7
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_8
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_9
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_alice_10
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0

Photon:
id: photon_bob
id: photon_bob_1
opacity: 1
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_2
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_3
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_4
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_5
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_6
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_7
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_8
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_9
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0
Photon:
id: photon_bob_10
opacity: 0
size_hint: 0.01, 0.01 * root.width / root.height
#pos_hint: {"center_x": 0.5,"center_y": 0.5}
#center: root.center
pos: 0, 0



Round_Button:
id: source
size_hint: 0.04, 0.04 * root.width / root.height
size_hint: 0.045, 0.045 * root.width / root.height
pos_hint: {"center_x": 0.5,"center_y": 0.5}
always_release: True
on_press:
root.emission()
root.stop_animation(root.source)
if root.tut_press_source.opacity == 1: root.tut_alice_button.opacity = 1; root.filter_animation(root.alice_filter)
root.tut_press_source.opacity = 0
if root.tut_press_source.opacity == 1: root.tut_emmited.opacity = 1; root.tut_alice_button.opacity = 1; root.filter_animation(root.alice_filter)
root.tut_press_source.opacity = 0

Label:
id: label_source
color: 0, 0, 0, 1
Expand Down Expand Up @@ -652,7 +802,7 @@
color: [0.1, 0.45, 0.8, 1]
opacity: 0
font_size: 0.022 * game_layout.height
pos_hint: {"center_x": 0.5, "center_y": 0.56}
pos_hint: {"center_x": 0.5, "center_y": 0.57}
font_name: 'NunitoSans'
text: "Press me!"
halign:"center"
Expand All @@ -663,7 +813,7 @@
color: [0.1, 0.45, 0.8, 1]
opacity: 0
font_size: 0.022 * game_layout.height
pos_hint: {"center_x": 0.5, "center_y": 0.58}
pos_hint: {"center_x": 0.5, "center_y": 0.59}
font_name: 'NunitoSans'
text: "You have emitted a pair\nof photons!"
halign:"center"
Expand Down
135 changes: 91 additions & 44 deletions Ekert_91_kivy/ekert91.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty, BooleanProperty, StringProperty, Property

OFFSET = 12

class Round_Button(Button):

def on_touch_down(self, touch):
Expand Down Expand Up @@ -161,8 +159,51 @@ def __init__(self, **kwargs):

source = ObjectProperty(None)

photon_alice = ObjectProperty(None)
photon_bob = ObjectProperty(None)
photon_alice_1 = ObjectProperty(None)
photon_alice_2 = ObjectProperty(None)
photon_alice_3 = ObjectProperty(None)
photon_alice_4 = ObjectProperty(None)
photon_alice_5 = ObjectProperty(None)
photon_alice_6 = ObjectProperty(None)
photon_alice_7 = ObjectProperty(None)
photon_alice_8 = ObjectProperty(None)
photon_alice_9 = ObjectProperty(None)
photon_alice_10 = ObjectProperty(None)

photons_alice = ReferenceListProperty(
photon_alice_1,
photon_alice_2,
photon_alice_3,
photon_alice_4,
photon_alice_5,
photon_alice_6,
photon_alice_7,
photon_alice_8,
photon_alice_9,
photon_alice_10 )

photon_bob_1 = ObjectProperty(None)
photon_bob_2 = ObjectProperty(None)
photon_bob_3 = ObjectProperty(None)
photon_bob_4 = ObjectProperty(None)
photon_bob_5 = ObjectProperty(None)
photon_bob_6 = ObjectProperty(None)
photon_bob_7 = ObjectProperty(None)
photon_bob_8 = ObjectProperty(None)
photon_bob_9 = ObjectProperty(None)
photon_bob_10 = ObjectProperty(None)

photons_bob = ReferenceListProperty(
photon_bob_1,
photon_bob_2,
photon_bob_3,
photon_bob_4,
photon_bob_5,
photon_bob_6,
photon_bob_7,
photon_bob_8,
photon_bob_9,
photon_bob_10 )

alice_filter = ObjectProperty(None)
bob_filter = ObjectProperty(None)
Expand Down Expand Up @@ -294,14 +335,20 @@ def stop_tutorial(self):

def emission(self):

self.photon_alice.center = self.center
self.photon_bob.center = self.center

velocity_x = (self.center_x - self.alice_filter.center_x)/60
velocity_y = 0.5 * self.photon_alice.height
velocity_y = 0.5 * self.photon_alice_1.height

for i in range(10):

self.photons_alice[i].center_x = self.center_x + self.photon_alice_1.width * i
self.photons_alice[i].center_y = self.center_y + np.random.randint(low=-0.25*self.source.height, high=0.25*self.source.height)

self.photon_alice.velocity = Vector(-velocity_x, velocity_y)
self.photon_bob.velocity = Vector(velocity_x, velocity_y)
self.photons_bob[i].center_x = self.center_x - self.photon_alice_1.width * i
#self.photons_bob[i].center_y = self.center_y + np.random.randint(low=-0.25*self.source.height, high=0.25*self.source.height)
self.photons_bob[i].center_y = self.photons_alice[i].center_y

self.photons_alice[i].velocity = Vector(-velocity_x, velocity_y)
self.photons_bob[i].velocity = Vector(velocity_x, velocity_y)

basis_a = self.alice_slit.angle_to_basis()
basis_b = self.bob_slit.angle_to_basis()
Expand Down Expand Up @@ -340,47 +387,47 @@ def emission(self):


def update(self, dt):

self.photon_alice.move()
self.photon_bob.move()

# For each frame, vertical velocity is inverted
if self.photon_alice.velocity_x != 0:
self.photon_alice.velocity_y *= -1
self.photon_bob.velocity_y *= -1
OFFSET = 0.05 * self.alice_filter.width

if OFFSET < self.eve_left_filter.center_x - self.photon_alice.x < 10 * OFFSET:
if self.switch_eve_left.active and self.switch_eve.active:
self.photon_alice.opacity = 0
for i in range(10):

if self.switch_eve_right.active and self.switch_eve.active:
self.photon_bob.opacity = 0
if self.slider.value >= 100 * i + 1 and self.photons_alice[i].x < self.center_x:
self.photons_alice[i].opacity = 1
else:
self.photons_alice[i].opacity = 0

self.e_left_bit = self.e_left_bit_old
self.e_right_bit = self.e_right_bit_old
else:
self.photon_alice.opacity = 1
self.photon_bob.opacity = 1

if self.photon_alice.x < self.alice_filter.center_x - OFFSET:
self.photon_alice.center = self.center
self.photon_bob.center = self.center
self.photon_alice.velocity = Vector(0, 0)
self.photon_bob.velocity = Vector(0, 0)
self.a_bit = self.a_bit_old
self.b_bit = self.b_bit_old


'''
if self.tut_slider.opacity == 1:
if self.big_cursor == False:
self.slider.cursor_size = 0.025*self.height, 0.025*self.height
if self.slider.value >= 100 * i + 1 and self.photons_bob[i].x > self.center_x:
self.photons_bob[i].opacity = 1
else:
self.slider.cursor_size = 0.02*self.height, 0.02*self.height
time.sleep(0.4)
'''
self.photons_bob[i].opacity = 0

self.photons_alice[i].move()
self.photons_bob[i].move()

# For each frame, vertical velocity is inverted
if self.photons_alice[i].velocity_x != 0:
self.photons_alice[i].velocity_y *= -1
self.photons_bob[i].velocity_y *= -1

if OFFSET < self.eve_left_filter.center_x - self.photons_alice[i].x < 11 * OFFSET:
if self.switch_eve_left.active and self.switch_eve.active:
self.photons_alice[i].opacity = 0

if self.switch_eve_right.active and self.switch_eve.active:
self.photons_bob[i].opacity = 0

self.e_left_bit = self.e_left_bit_old
self.e_right_bit = self.e_right_bit_old

if self.photons_alice[i].x < self.alice_filter.center_x - OFFSET:
self.photons_alice[i].center = self.center
self.photons_bob[i].center = self.center
self.photons_alice[i].velocity = Vector(0, 0)
self.photons_bob[i].velocity = Vector(0, 0)
self.a_bit = self.a_bit_old
self.b_bit = self.b_bit_old


class Ekert91App(App):

Expand Down

0 comments on commit 0f56950

Please sign in to comment.