Visualize Squirmers
The visualization shown here is based on simulation data generated as part of the work “Modeling a spheroidal microswimmer and cooperative swimming in a narrow slit” (DOI).
More information about the implementation of the simulation program can be found here. In this article, I restrict myself exclusively to the visualization of the squirmers.
Originally, the data from the individual time steps was read in using a complex visualization system. Generating a video sequence from this data was associated with a certain operating effort.
However, with modern programming languages (such as Julia) there are now ways to simplify the creation of such video sequences. Here we use the GR-Framework for the visualization, since it is particularly suitable for such problems due to the integrated video API. No further packages are necessary.
using GR
For the representation of the squirmers we use simple ellipses, which are again drawn with the GR path function. First of all we have to provide the coordinates to draw an ellispe using four Bezier Cubic Splines.
const ⬮x = [0.0, 0.5523, 1.0, 1.0, 1.0, 0.5523, 0.0, -0.5523, -1.0, -1.0, -1.0, -0.5523, 0.0]
const ⬮y = [1.0, 1.0, 0.5523, 0.0, -0.5523, -1.0, -1.0, -1.0, -0.5523, 0.0, 0.5523, 1.0, 1.0]
We need a function to rotate the squirmers and to fill an ellipse with a given center (x,y), a rotation angle and two radii (a,b).
function rotate(x, y, θ)
x .* cos(θ) - y .* sin(θ), x .* sin(θ) + y .* cos(θ)
end
function squirmer(x, y, angle, a, b)
Δx, Δy = rotate(⬮x .* a, ⬮y .* b, angle)
path(x .+ Δx, y .+ Δy, "MCCCCF")
end
The next function creates the graphics window and scales it according the coordinate range of the center positions and maps them to the full viewport.
function createwindow()
setwindow(0, 300, 0, 300)
setviewport(0, 1, 0, 1)
end
The visualization of the squirmers of a single time step is done in the showscene function. The positions and angles result from the read-in data, the semi-axes of the ellipses are fixed.
function showscene(data, num_particles)
particles = reshape(parse.(Float64, split(data)), 12, num_particles)'
clearws()
settransparency(0.5)
setfillcolorind(3)
setbordercolorind(1)
for particle in eachrow(particles)
θ = -atan(particle[4], particle[6])
squirmer(particle[1], particle[3], θ, 3, 6)
end
updatews()
end
The animation function finally reads the simulation data and calls the showscene function with the name of our dataset and the number of squimers num_particles.
function animation(path, num_particles)
file = open(path, "r")
while !eof(file)
data = readline(file)
showscene(data, num_particles)
sleep(1/60)
end
close(file)
end
With this, we can now start the visualization.
createwindow()
animation("squirmer.dat", 800)
We can view the animation in an output window (GKSTerm on macOS or GKS QtTerm on Linux/Windows).
Alternatively, you can redirect the output directly to a video file and create the animation as a movie.
env GKSwstype=mov julia squirmer.jl
If you want to try the above visualisation yourself on your computer - here you can download the above Julia script and the dataset.