User:Thierry Dugnolle/Python/The French flag model of Lewis Wolpert

The diffusion of a morphogen in an elongated compartment. The three colors blue, white and red represent three concentration ranges of the initial morphogen, which can then activate three gens in a differentiated manner, and thus be at the origin of three different parts of the organism.

main.py

edit
# 2023, September 20. Version 230920.

# The drawer paints and draws an animation of the diffusion of a morphogen in an
# elongated compartment. The three colors blue, white and red represent three
# concentration ranges of the initial morphogen, which can then activate three
# gens in a differentiated manner, and thus be at the origin of three different
# parts of the organism.

# 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 aNewGaussian1DdiffusionField
from Vector2D import aNew2Dvector

print ("Mathematical painter")

# The drawer
TheDrawer = aScalar1DfieldDrawer()

# The canvas:
TheCanvasStyle= "color" # "color", "black on white" or "white on black"
TheWidth = 500 # number of pixels
TheHeight = 250 # number of pixels
TheLengthUnit = 10 # 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 palette:
def ThePalette(shade): # WolpertFlagColors : black, red, grey, blue.
    return TheDrawer.palette.WolpertFlagColors(shade)

# The field:
ThePixelNumberOfPoints = 1 # number of points in the field in the width of a pixel
TheNumberOfPoints = TheWidth*ThePixelNumberOfPoints
sigma = 1.0
mu = -0.5*TheRealWidth
t_start = 1.0
TheField = aNewGaussian1DdiffusionField(TheNumberOfPoints, TheRealWidth, sigma, mu, t_start)
TheField.limitCondition = "constant"
# Its flow:
def TheFieldFlow(Afield):
    return Afield.diffusion1Dflow(sigma)

# The animation:
TheNumberOfImages = 300
TheNumberOf_dts = 3000
The_dt= 0.001
for i in range(TheNumberOfImages):
    print("image", i)
    TheDrawer.paintsAreal1Dfield(TheField, ThePixelNumberOfPoints, ThePalette)
    TheDrawer.givesApainting("Animation/WolpertFlag" + str(100 + i) + ".png")
    for j in range(TheNumberOf_dts):
        TheField = TheField.nextField(TheFieldFlow, The_dt)

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.