I want to make this animation in OpenGL, here I attached a simple gif how I want it to looks like:
Main problem is that I can not figure out how to move by corner - circle should smoothly move by corner, not to just jump to another side's begin position.
import Blender from Blender import Draw,BGL from Blender.BGL import * from math import sin,cos import time squareLength, squareX, squareY, circleRadius = 200, 200, 200, 20 movingX, movingY = 0, 0 def event(evt, val): if evt == Draw.ESCKEY : Draw.Exit() def gui(): global movingX, movingY glClearColor(0.17, 0.24, 0.31, 1.0) glClear(BGL.GL_COLOR_BUFFER_BIT) glLineWidth(1) glColor3f(0.74, 0.76, 0.78) glBegin(GL_QUADS) glVertex2i(squareX, squareY) glVertex2i(squareX, squareY + squareLength) glVertex2i(squareX + squareLength, squareY + squareLength) glVertex2i(squareX + squareLength, squareY) glEnd() glColor3f(0.58, 0.65, 0.65) glPushMatrix() if movingX == -circleRadius: if movingY < squareLength: movingY += 1 else: movingX = 0 movingY = squareLength + circleRadius else: if movingY == squareLength + circleRadius: if movingX < squareLength: movingX += 1 else: movingX = squareLength + circleRadius movingY = squareLength else: if movingY < 0: if movingX > 0: movingX -= 1 else: movingX = -circleRadius movingY = 0 else: if movingY > 0: movingY -= 1 else: movingX = squareLength movingY = -circleRadius glTranslatef(movingX, movingY, 0) glBegin(GL_LINE_LOOP) for i in xrange(0, 360, 1): glVertex2f(squareX + sin(i) * circleRadius, squareY + cos(i) * circleRadius) glEnd() glPopMatrix() Draw.Redraw(1) Draw.Register(gui, event, None)
Can you please say me, how can I optimize this code to make circle moving by corners?
Just start learning computer graphics and think up such exercises for training, so I will really appreciate for any help.