"Tutorial 3" is a sample of contact judgment. The visualization is PyOpenGL. -PyOpenGL setup is required. -Since it is OpenGL, there are many visualization code descriptions because it is 3D.
It was a little difficult. ・ Https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl I got "PyOpenGL-3.1.5-cp38-cp38-win_amd64.whl" from and installed it with pip. → Tutorial 3 works normally.
"Tutorial 3" has moved. I added an image saving routine to make a GIF movie. (Use Pillow)
・ The value of the viewpoint has been changed from the original code.
Outputs a PNG image group and one GIF video as a file. Only the additional part will be placed on ↓.
How to use: -Install "Pillow". -Create two current folders "img" and "gif" in advance before execution. -Call the additional routine "capture ()" after the original line 231 "glutSwapBuffers ()". ・ Similarly, on line 220, call "export_movie ()" before "sys.exit (0)".
Generate snapshot from PyOpenGL/Save
from PIL import Image
from PIL import ImageOps
step=-1
intvl = 10
imgs = []
def capture():
global step
step += 1
if step % intvl != 0:
return
pad_step = '{0:04d}'.format(step)
print( pad_step )
savepath = "img/tutorial3_"+pad_step+".png "
width = glutGet(GLUT_WINDOW_WIDTH)
height = glutGet(GLUT_WINDOW_HEIGHT)
glReadBuffer(GL_FRONT)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
#image = Image.fromstring("RGBA", (width, height), data)
image = Image.frombytes("RGBA", (width, height), data)
image = ImageOps.flip(image)
image.save( savepath )
imgs.append( image )
GIF video save routine
def export_movie():
if not imgs:
return
imgs[0].save('gif/tutorial3.gif'
, save_all=True
, append_images=imgs[1:]
, optimize=False
, duration=100 #40
, loop=0)
Recommended Posts