'Creating an animation showing a line dropping vertically using wxPython

I wrote a code showing a line dropping vertically using wxPython. The issue Iam facing is when I keep the same y-coordinate (y2=y4 :drawing horizontal line on frame), the line is not visible on the window.

If I change the 4th parameter of the DrawLine(...) call by 1 unit (size[1]/2 -300+i*10 => size[1]/2 -301+i*10), the line is visible.

Can anyone explain where Iam going wrong.

My code where I kept same y-coordinate to draw horizontal line is below. In this case, line is not visible.

import wx;
import time;

app = wx.App();
frame=wx.Frame(None,-1,'Line');
frame.SetBackgroundColour('White');
frame.Centre();
frame.Show();
frame.Maximize();
dc=wx.ClientDC(frame);
size=dc.GetSize();
for i in range(1,50):
    dc.SetPen(wx.Pen('VIOLET'));
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -300+i*10);
    time.sleep(0.2);
    dc.SetPen(wx.Pen('WHITE')); # the pen is set to white and same line is drown to create the animation
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -300+i*10);
app.MainLoop();

Now, if I change y-coordinate by even by 1 unit (y4=y2+1), the line is visible and the animation is shown on the frame. The code is below

import wx;
import time;

app = wx.App();
frame=wx.Frame(None,-1,'Line');
frame.SetBackgroundColour('White');
frame.Centre();
frame.Show();
frame.Maximize();
dc=wx.ClientDC(frame);
size=dc.GetSize();
for i in range(1,50):
    dc.SetPen(wx.Pen('VIOLET'));
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -301+i*10);
    time.sleep(0.2);
    dc.SetPen(wx.Pen('WHITE')); # the pen is set to white and same line is drown to create the animation
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -301+i*10);
app.MainLoop();

Can anyone explain why this difference or where Iam going wrong?



Solution 1:[1]

An interesting problem. The increase in line width helped me:

import wx
import time

app = wx.App()
frame=wx.Frame(None,-1,'Line')
frame.SetBackgroundColour('White')
frame.Centre()
frame.Show()
frame.Maximize()
dc=wx.ClientDC(frame)
size=dc.GetSize()
pen1 = wx.Pen('VIOLET', width=2)
pen2 = wx.Pen('WHITE', width=2)
for i in range(1,50):
    dc.SetPen(pen1)
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -300+i*10)
    time.sleep(0.2)
    dc.SetPen(pen2) # the pen is set to white and same line is drown to create the animation
    dc.DrawLine(size[0] / 2-500, size[1]/2-300+i*10, size[0] / 2 , size[1]/2 -300+i*10)
app.MainLoop()

I don't know if this is the required solution. Probably a property.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Finke