in Education by
I have drawn an image in the device context using python and I want to move it smoothly/animate either vertically or horizontally. What algorithm should I use? Where can I get info for this kind of tasks in python? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Once an object is drawn in a device context it stays there. If you want to move it you need to redraw it. You can keep a background that's fixed and only redraw the movable elements each time they move. Basically that's how it's done. To move an object smoothly over a line you have to do something like this (I don't have a program ready, so can only give you an idea): choose the start and end position: point A(x1, y1) and B(x2, y2) choose in how much time the object should change position from A to B (say 10 seconds). use a timer set to a certain interval (say 2 seconds) calculate the delta X and Y that the object should change for each timer interval. In this case dx = (x2-x1)*2/10 and dy = (y2-y1)*2/10 in the timer callback increment the current object position with dx and dy and redraw the image That would be the algorithm. I suggest that you also take a look to PyGame. Maybe you can use that and it also has some tutorials.

Related questions

0 votes
    I have drawn an image in the device context using python and I want to move it smoothly/animate either ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have drawn an image in the device context using python and I want to move it smoothly/animate either ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    I'm trying to make the text move continuously by pressing a button but right now it only moves an ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how I can represent the equivalent of an Enum in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I know if an object has some attribute in Python, Is there a way to do it? E.g. >>> q = ... property before using it in syntax? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How can I do the following in Python? array = [0, 10, 20, 40] for (i = array.length() - 1; i >= ... but from the end to the beginning. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I would like to get a list of Python modules, which are in my Python installation (UNIX server). How can ... in your computer? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How can I remove the last character of a string in a newline, In perl I used chomp function what's equivalent to that in Python? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to put time delay in the script of Python? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    This is my code: import SimpleITK as sitk reader = sitk.ImageFileReader() reader.SetFileName(filePath) reader.ReadImageInformation() img ... meta = { "a": reader.GetMetaData('0'),...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    How to remove an element from a list by index in Python, I tried list.remove method but it search the list and ... How can I do this? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me where can I learn Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what jobs can I get with Python? Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
...