''' The image with strange behaviour The discs looking 'normal' when using a background on the gizeh surface
Hi. I am using the above code snippet to get a series of frames of a gizeh surface with some discs drawn on it. The following is the make frame function which is causing the problem.
def make_frame(t):
surface = gizeh.Surface(1080,1080,bg_color=(0.2,0.5,0.2,1.0))
#draw border
border_width= 40.00
Border=gizeh.rectangle(1080, 1080, xy=((1080//2,1080//2)), stroke = (1.0,1.0,1.0), stroke_width = border_width)
Border.draw(surface)
for disc in discs:
Ball_w=gizeh.circle(r=(disc.size), xy=[disc.position[0] ,disc.position[1]], fill= (disc.color))
Ball_w.draw(surface)
disc.collide_with_wall(table_width, table_height, border_width)
#disc.collide_with_disc(discs)
disc.move()
return surface.get_npimage(transparent=True)
When I use moviepy to pull all the clips into a short .5..5 sec clip everything works as expected for the above code. However when I set the background to transparent by changing the surface bg color from
bg_color=(0.2,0.5,0.2,1.0) .... to this .... bg_color=(0.2,0.5,0.2,0.0)
The discs, which are moving show strange areas in front of the disc, in the direction the disc is moving. Also there is some strange leeching of color from one disc to another when they overlap. The two pictures show the issue (solid background , good. transparent background, bad). I have tried partial tranparency, and very very small numbers above 0 and just below 1 for the Alpha channel but the artifacts/leeching persist. I am at a total loss as to how to address this. I can share any further code you may wish to see. Two useful snippets may be the following. Disc Class.
class Disc:
def __init__(self, size, density, position, velocity, color):
self.size = size
self.density = density
self.mass = size*size*density
self.position = position
self.velocity = velocity
self.color = color
def move(self):
# Update the position of the disc based on its velocity
self.position[0] = (self.position[0] + self.velocity[0])
self.position[1] = (self.position[1] + self.velocity[1])
#self.position[0] = self.velocity[0] + self.position[0]
#self.position[1] = self.velocity[1] + self.position[1]
def update_position(self, new_position):
self.position = new_position
def update_velocity(self, new_velocity):
self.velocity = new_velocity
def collide_with_wall(self, width, height, border_width):
# Check for collisions with the walls of the pool table
if self.position[0] <=0+self.size+border_width/2:
self.velocity[0] =abs(self.velocity[0]) # Reverse the x-direction velocity
if self.position[0] >= width-self.size-border_width/2:
self.velocity[0] =-abs(self.velocity[0]) # Reverse the x-direction velocity
if self.position[1] <=0+self.size+border_width/2:
self.velocity[1] =abs(self.velocity[1]) # Reverse the y-direction velocity
if self.position[1] >= height-self.size-border_width/2:
self.velocity[1] =-abs(self.velocity[1]) # Reverse the y-direction velocity
This is the function that gets all the frames, pulls them together and sends them to the main function which uses this and other moviepy clips to produce a final video. Everything else in the program is working fine. I'm happy to do any heavy lifting on research but I've not seen this issue referred to anywhere and fear that a resolution will involve delving into the workings of Cairo, (which wouldn't be simple for me, even if I knew what to look for). Any suggestions on this would be grateful. I'm stumped.
for frame_no in range (0, int(num_frames)):
clip=get_array_clip(discs,frame_no)
palette_clip.append(clip)
final_vid=concatenate_videoclips(palette_clip, method="chain" )
final_vid.set_start(palette_start_time)
clip=[]
clip.append(final_vid.set_start(palette_start_time).set_position((0,420)))
return clipenter image description here