User:Thierry Dugnolle/Python/Travelling gaussian quantum 1D wave packet

The color (yellow, green, cyan) represents the phase of the quantum wave function. The brightness and the line represent its probability density.

main.py

edit
# 2023, September 20. Version 230920.

# The drawer paints and draws an animation of a free travelling quantum gaussian 1D wave packet.
# The drawer has a canvas which is defined by a matrix width*height of pixels.
# The canvas is projected on a plane: the vector image.
# The image center is the position of the center of the canvas in the vector image.
# The length unit is the number of pixels of a unit of length in the vector image.

import math
from Scalar1DfieldDrawer import aScalar1DfieldDrawer
from Scalar1Dfield import aNewGaussianQuantum1DwavePacket, gaussianQuantum1DwavePacket
from Vector2D import aNew2Dvector

print ("Mathematical painter")

# The drawer
TheDrawer = aScalar1DfieldDrawer()

# The canvas:
TheCanvasStyle= "color" # "color", "black on white" or "white on black"
TheWidth = 800 # number of pixels
TheHeight = 250 # number of pixels
TheLengthUnit = 100 # number of pixels
TheCanvasColor = (0, 0, 0) # (red, green, blue) here black
TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
TheDrawer.canvas.imageCenter = aNew2Dvector( 0.0, 0.5*TheHeight/TheLengthUnit)

# The paintbrush:
TheDrawer.paintbrush.haloHalfWidth = 0.04 # (The halo half width * the length unit) is the
# number of pixels in the half width of the halo.
TheDrawer.paintbrush.powerOfSquaredCos = 1
TheDrawer.paintbrush.totalHalfWidth = TheDrawer.paintbrush.haloHalfWidth
def ThePalette(colorNumber, brightness): # periodicYellowGreenCyan
    return TheDrawer.palette.periodicYellowGreenCyan(colorNumber, brightness)

# The field:
ThePixelNumberOfPoints = 1 # number of points in the field in the width of a pixel
TheNumberOfPoints = TheWidth*ThePixelNumberOfPoints
TheRealWidth = TheWidth/TheLengthUnit
TheRealHeight = TheHeight/TheLengthUnit
m = 8.0  # mass
a = 3.0  # packet width
k0 = 8.0 # momentum
t = 0.0  # time
xStart = -1.8*TheRealWidth/2  # position at t = 0
max = abs(gaussianQuantum1DwavePacket(m, a, k0, 0, 0))
maxField = math.sqrt(0.9*TheRealHeight)
maxField2 = maxField*maxField

# The animation:
TheNumberOfImages = 300
The_dt = 15/TheNumberOfImages
for i in range(TheNumberOfImages):
    print("image", i)
    TheField = (aNewGaussianQuantum1DwavePacket(TheNumberOfPoints, TheRealWidth, m, a, k0,
                                                xStart, i*The_dt).times(maxField/max))
    TheDrawer.paintsAndDrawsAcomplex1Dfield(TheField, ThePixelNumberOfPoints, maxField2, ThePalette)
    TheDrawer.givesApainting("Quantum1D" + str(100 + i) + ".png")

print("Good bye")

Other files

edit

This program requires the following additional files: Painter.py, Palette.py, Line2Ddrawer.py, Scalar1DfieldDrawer.py, Scalar1Dfield.py and Vector2D.py. They are all on this page : User:Thierry Dugnolle/Python/Mathematical painter.