User:Thierry Dugnolle/Python/Sinusoidal progressive wave

Sinusoidal progressive wave

main.py

edit
# 2023, September 21. Version 230921.

# The drawer paints and draws an animation of a sinusoidal progressive wave.

# 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 aNewGaussian1Dfield, aNewSinus1Dfield
from Vector2D import aNew2Dvector

print ("Mathematical painter")

# The drawer
TheDrawer = aScalar1DfieldDrawer()

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

# 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

# The palette:
def ThePalette(shade): # depthColors : black, blue, cyan, white.
    return TheDrawer.palette.depthColors(shade)

# The field:
ThePixelNumberOfPoints = 1 # number of points in the field in the width of a pixel
TheNumberOfPoints = TheWidth*ThePixelNumberOfPoints
k = 1.0
omega = 1.0

# The animation:
TheNumberOfImages = 200
dt = 2*math.pi/TheNumberOfImages
for i in range(TheNumberOfImages):
    print("image", i)
    phi = -omega*i*dt
    TheField = aNewSinus1Dfield(TheNumberOfPoints, 4 * math.pi, k, phi).times(0.5).verticallyShifted(0.5)
    TheDrawer.paintsAndDrawsAreal1Dfield(TheField, ThePixelNumberOfPoints, ThePalette)
    TheDrawer.givesApainting("Animation/Wave" + 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.