Hi,
I am attempting to make a simple ideal gas simulation.
I have created particles in a list as such, where the user will input n:
However no collisions will be detected, does anyone have any thoughts on how I could achieve this?
I am attempting to make a simple ideal gas simulation.
I have created particles in a list as such, where the user will input n:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import random import math import turtle as tt no_particles = int (n) ball = [] for i in range (no_particles): ball.append(tt.Turtle()) ball[i] = tt.Turtle() ball[i].speed( 0 ) ball[i].shape( "circle" ) ball[i].color( "White" ) ball[i].penup() ball[i].goto(((right_edge * random.random()) - (right_edge / 2 )),(top_edge * random.random()) - (top_edge / 2 )) ball[i].dx = random.random() * 3 ball[i].dy = random.random() * 3 However I am struggling to detect collisions of these particles, I have attempted using the code below while True : for i in range (no_particles): ball[i].setx(ball[i].xcor() + ball[i].dx) ball[i].sety(ball[i].ycor() + ball[i].dy) if distance < 25 : collision_counter + = 1 counter.clear() counter.write( "Collison counter: {}" . format (collision_counter), align = "left" , font = ( "Courier" , vhalf, "normal" )) ball[ 0 ].dx * = - 1 ball[ 0 ].dy * = - 1 ball[ 1 ].dy * = - 1 ball[ 1 ].dx * = - 1 |
Larz60+ write Apr-06-2021, 03:29 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.