Jump to content

User:Thierry Dugnolle/Python/Continuous line crossing transition

From Wikipedia, the free encyclopedia

main.py

[edit]
# 2023, October 19. Version 231019

import math
from Monocolor3Dpainter import aMonocolor3Dpainter
from Vector3D import The3Dvector
from Line3D import aNew3Dline
from time import process_time

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


# The drawer:
TheDrawer = aMonocolor3Dpainter()

# The canvas:
TheCanvasStyle= "color" # "color", "black on white" or "white on black"
TheWidth = 500 # number of pixels
TheHeight = 500 # number of pixels
TheLengthUnit = 200 # number of pixels
TheCanvasColor = (255, 255, 255) # (red, green, blue) here white

# The line of vision:
Phi = 90 # in degrees. The line of vision is parallel to the y axis.
Theta = 90 # in degrees. The line of vision is horizontal.
TheObjectCenter = The3Dvector(0, 0, 0)
TheDistance = 100 # The distance between the object center and the optical center.

TheZoom = 100
Psi = 0 # in degrees.The angle of rotation of the image around the line of vision.

# The paintbrush:
TheDrawer.paintbrush.color = (255, 0, 0) # red
TheDrawer.paintbrush.lineHalfWidth = 0.2 # (The line half width * the length unit) is the
# number of pixels in the half width of the line.
TheDrawer.brush3D.lineFringeRelativeWidth = 1.5
TheDrawer.brush3D.lineDepth = TheDrawer.paintbrush.lineHalfWidth*(1+TheDrawer.brush3D.lineFringeRelativeWidth)
TheDrawer.brush3D.lineOpacity = 2
TheDrawer.brush3D.intensity = 1

# The line:
TheNumberOfPoints = 100
TheLine = aNew3Dline(TheNumberOfPoints)

# The animation
TheNumberOfImages = 160
TheDrawer.choosesApointOfView(TheObjectCenter, TheDistance, Phi, Theta, Psi, TheZoom)
TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
for j in range(TheNumberOfImages):
    depth = 0.8-j*0.01
    for i in range(TheNumberOfPoints):
        x = i*2*math.pi/(TheNumberOfPoints - 1)
        TheLine.point[i].x = math.sin(1.5*x - math.pi/2)
        TheLine.point[i].z = -math.sin(x - math.pi/2)
        TheLine.point[i].y = i*depth/TheNumberOfPoints
    TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
    print("Time:", process_time(), "The drawer draws the image", j, ". depth =", depth)
    TheDrawer.drawsA3Dline(TheLine)
    print("Time:", process_time(), "The drawer gives the image", j, ". depth =", depth)
    TheDrawer.givesApainting("CurlTransition"+str(100+j)+".png")
    # str(100+i) is here because * in imagemagick works with a lexicographic order.

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

Other files

[edit]

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