Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws2021:code [2021/01/16 12:48] jessica.03 |
ws2021:code [2021/02/03 18:32] (aktuell) sarah-j-28 |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
<code Python> | <code Python> | ||
- | #Bouncing Balls Simulator | + | #Bouncing Vall Simulator |
import turtle | import turtle | ||
- | import random | + | import random |
- | from erste_klasse import Agent | + | from klasse_agenten import Agent |
- | #ag1 = Agent() | + | #ag1 = Agent() |
#print(ag1) | #print(ag1) | ||
Zeile 28: | Zeile 28: | ||
- | #balls = [] | ||
agents = [] | agents = [] | ||
- | for _ in range(50): #range(Anzahl der bälle) | + | for _ in range(50): #range(anzahl der bälle) |
agents.append(Agent(_)) #create balls | agents.append(Agent(_)) #create balls | ||
- | |||
- | #colors = ["red","green","black"] | ||
Zeile 40: | Zeile 37: | ||
agent.ball.shape("circle") | agent.ball.shape("circle") | ||
agent.ball.color("green") | agent.ball.color("green") | ||
- | agent.ball.penup() | + | agent.ball.penup() #not draw a line |
agent.ball.speed(1) #Geschwindigkeitsänderung | agent.ball.speed(1) #Geschwindigkeitsänderung | ||
Zeile 58: | Zeile 55: | ||
agent.ball.dx = random.randint(-1,1) | agent.ball.dx = random.randint(-1,1) | ||
- | #ball.da = 1 | ||
agents[1].anstecken() #first ball will be colored red | agents[1].anstecken() #first ball will be colored red | ||
- | ball_no = [1] #numbers as the positions in the list of balls, which are colored red | + | infizierten = [1] #numbers as the positions in the list of balls, which are colored red |
+ | recovered = [] | ||
while True: | while True: | ||
Zeile 95: | Zeile 92: | ||
#check for a collision | #check for a collision | ||
if agents[i].ball.distance(agents[j].ball) < 20: # because each ball has 20 pixels width | if agents[i].ball.distance(agents[j].ball) < 20: # because each ball has 20 pixels width | ||
+ | |||
+ | |||
#switch the behaviours of these two balls | #switch the behaviours of these two balls | ||
agents[i].ball.dx , agents[j].ball.dx = agents[j].ball.dx, agents[i].ball.dx | agents[i].ball.dx , agents[j].ball.dx = agents[j].ball.dx, agents[i].ball.dx | ||
agents[i].ball.dy , agents[j].ball.dy = agents[j].ball.dy, agents[i].ball.dy | agents[i].ball.dy , agents[j].ball.dy = agents[j].ball.dy, agents[i].ball.dy | ||
- | | ||
- | |||
- | # 0.9 = Wahrscheinlichkeit einer Infektion | ||
+ | |||
+ | # 0.9 = Wahrscheinlichkeit einer Infektion | ||
if i in infizierten and j not in recovered and random.random()<0.9: | if i in infizierten and j not in recovered and random.random()<0.9: | ||
Zeile 122: | Zeile 120: | ||
recovered.append(k) | recovered.append(k) | ||
infizierten.remove(k) | infizierten.remove(k) | ||
+ | wn.mainloop() | ||
- | + | # To fix: they get stuck together, maybe because they have similar behaviurs and go to the direction of each other over and over | |
- | wn.mainloop() | + | |
</code> | </code> |