User:Thierry Dugnolle/Python/Cubic Galaxy

main.py

edit
# 2023, October 19. Version 231019

from Monocolor3Dpainter import aMonocolor3Dpainter
from Vector3D import The3Dvector
from Lattice import TheCubicCell, TheBodyCenteredCubicCell, TheFaceCenteredCubicCell, TheDiamondCell
from time import process_time

print ("Time:", process_time(), "Mathematical painter")

black = (0, 0, 0)
white = (255, 255, 255)

# The drawer:
TheDrawer = aMonocolor3Dpainter()

# The canvas:
TheCanvasStyle= "white on black" # "color", "black on white" or "white on black"
TheWidth = 500 # number of pixels
TheHeight = 500 # number of pixels
TheLengthUnit = 200 # number of pixels
TheCanvasColor = black
TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)

# The line of vision:
# The angle (in degrees) of the line of vision relative to the z axis:
Theta = 90
# The angle (in degrees) between the projection of the line of vision on the xy plane
# and the x axis:
Phi = 90
# The position of the optical center is determined by the position of the object,
# the direction of the line of vision and the distance between the object and
# the optical center:
# The position of the center of the object:
TheObjectCenter = The3Dvector(0, 0, 0)
# The distance between the object center and the optical center:
TheDistance = 0
# The zoom = 1 means that the image is neither reduced nor enlarged, > 1 that it is enlarged,
# > 0 and < 1 that it is reduced:
TheZoom = 2
TheDrawer.choosesApointOfView(TheObjectCenter, TheDistance, Phi, Theta, 0, TheZoom)

# The paintbrush:
TheDrawer.paintbrush.color = white
TheDrawer.brush3D.atomFringeRelativeWidth = 0
TheDrawer.brush3D.atomOpacity = 10
TheDrawer.brush3D.intensity = 1

# The cell:
TheCellSide = 2
TheBondColor = (0, 0, 0)
TheAtomRadius = 0.1
TheAtomColor = (255, 255, 255)
TheCell = TheCubicCell(TheCellSide, TheBondColor, TheAtomRadius, TheAtomColor)

# The lattice:
width = 51 # Number of cells
depth = width # Number of cells
height = width # Number of cells
TheCell = TheCell.times(1/width)
TheLattice = TheCell.atomsLattice(width, depth, height)

# The animation:
TheNumberOfImages = 400
Phi = 0
Theta = 90
for i in range(TheNumberOfImages):
    TheDistance = (1 - i/200)/width
    TheDrawer.choosesApointOfView(TheObjectCenter, TheDistance, Phi, Theta, 0, TheZoom)
    print("Time:", process_time(), "The drawer draws the image", i)
    TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
    TheDrawer.paintsAtomsOfDifferentKindsSimple(TheLattice)
    # The atoms of a lattice are usually of different kinds. Here the number of atom kinds = 1 .
    # The folder 'CubicGalaxy' for the images shall have been created:
    TheDrawer.givesApainting("CubicGalaxy/im" + str(1000+i) + ".png")

print("Time:", process_time(), "Good bye")

# 400 images are saved in the folder 'CubicGalaxy'. With imagemagick, they can be united to make a GIF:
# convert -delay 4 -loop 0 im*.png CubicGalaxyAnimation.gif

Other files

edit

This program requires the following additional files: Painter.py, Line2Ddrawer.py, Vector2D.py, Monocolor3Dpainter.py, Vector3D.py, Line3D.py, DepthMatrix.py, Atom.py, MonoAtomicLattice.py and Palette.py. They are all on this page : User:Thierry Dugnolle/Python/Mathematical painter.