User:Thierry Dugnolle/Python/High definition crossing of lines

main.py

edit
# 2023, September 24. Version 230924.

# 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 Line3Ddrawer import a3DlineDrawer
from Vector3D import aNew3Dvector, aNew3Dline
from Vector2D import aNew2Dvector

print ("Mathematical painter")

# The drawer:
TheDrawer = a3DlineDrawer()

# 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
TheRealWidth = TheWidth/TheLengthUnit
TheRealHeight = TheHeight/TheLengthUnit
TheCanvasColor = (255, 255, 255) # (red, green, blue) here white
TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
TheDrawer.canvas.imageCenter = aNew2Dvector( 0.0*TheRealWidth, 0.0*TheRealHeight)

# The line of vision:
Theta = 90.0 # the angle (in degrees) of the line of vision relative to the z axis.
Phi = 90.0 # the angle (in degrees) between the projection of the line of vision on the xy plane and the x axis.
# The position of the optical center is determined by the position of the object seen, the line of vision
# and the distance between the object and the optical center:
TheObjectCenter = aNew3Dvector(0.0, 0.0, 0.0) # position of the center of the object seen.
TheDistance = 100.0 # ŧ distance between the object center and the optical center

# The Zoom = 1.0 means that the image is neither reduced nor enlarged.
TheZoom = 100

# Psi is the angle (in degrees) of rotation of the image around the line of vision
Psi = 0.0

TheDrawer.choosesApointOfView(TheObjectCenter, TheDistance, Phi, Theta, Psi, TheZoom)

# The paintbrush:
TheDrawer.paintbrush.color = (255, 0, 0)
TheDrawer.paintbrush.powerOfSquaredCos = 1
TheDrawer.paintbrush.haloHalfWidth = 0.2 # (The halo half width * the length unit) is the
# number of pixels in the half width of the halo.
TheDrawer.paintbrush.fringeWidth = 0.1 # (The fringe width * the length unit) is the
# number of pixels in the fringe width of the halo.
TheDrawer.paintbrush.totalHalfWidth = TheDrawer.paintbrush.haloHalfWidth + TheDrawer.paintbrush.fringeWidth

# The line:
TheNumberOfPoints = 100
depth = 1.0
TheLine = aNew3Dline(TheNumberOfPoints)
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

# The drawing
    TheDrawer.takesAnewCanvas(TheWidth, TheHeight, TheLengthUnit, TheCanvasStyle, TheCanvasColor)
    TheDrawer.drawsA3Dline(TheLine)
    TheDrawer.givesApainting("Curl.png")

print("Good bye")

Other files

edit

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