brownian module#

class Circle(coords, diameter, velocity=None, theta=3, stop_and_rotate=False)[source]#

Class representing a point/circle with Brownian motion.

Parameters:
  • coords (numpy.ndarray) – The initial coordinates of the circle.

  • diameter (int) – Diameter of the circle.

  • velocity (numpy.ndarray, optional) – Initial velocity of the circle. If None, a random velocity is assigned.

  • theta (int, optional) – Angular velocity for rotation. (Defaul: 3)

  • stop_and_rotate (bool, optional) – This is because of the the ambigous requirement of the challenge (Default: False)

checkCollision(coords, boundary)[source]#

Check if the circle collides with the specified boundary.

Parameters:
Returns:

True if collision occurs, False otherwise.

Return type:

(bool)

move(dt, maxX, maxY)[source]#

Move the circle based on its state.

Parameters:
  • dt – Time step for movement.

  • maxX – Maximum x-coordinate for the boundary.

  • maxY – Maximum y-coordinate for the boundary.

get_random_velocity()[source]#

Generate a random velocity vector.

Samples velocity magnitude from a normal distribution \(\mathcal{N}(\mu, \sigma^2)\), where \(\mu = 500\) and \(\sigma = 200\), and clips it as

\[\begin{split}\lVert V \rVert = \begin{cases} V, & \text{if} \ V_{\text{min}} \leq V \leq V_{\text{max}} \\ V_{\text{min}}, & \text{if} \ V \leq V_{\text{min}} \\ V_{\text{max}}, & \text{if} \ V \geq V_{\text{max}} \end{cases}\end{split}\]

where \(V_{\text{min}} = 100\) and \(V_{\text{max}} = 900\).

Then randomly assigns direction to the velocity.

Returns:

Random velocity vector \(V\).

Return type:

(numpy.ndarray)

draw(canvas, **kwargs)[source]#

Draws the circle on the canvas.

Parameters:
  • canvas (tk.Canvas) – Canvas object for drawing.

  • **kwargs – Additional keyword arguments for drawing.

clean(canvas)[source]#

Removes the circle from the canvas.

Parameters:

canvas – Canvas object for cleaning.

class MainWindow(args, timDelta=0.001)[source]#

MainWindow for Brownian motion simulation using tkinter.

start()[source]#
step()[source]#
set_random_velocity()[source]#

Set a random velocity for the circle on button click. Internally calls Circle.get_random_velocity()

main()[source]#