Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:24:58+00:00 2026-06-17T06:24:58+00:00

I’m trying to animate smooth motion between two points on the screen. At the

  • 0

I’m trying to animate smooth motion between two points on the screen. At the moment, I am using the following python generator function to determine the point at which to draw the image:

#indexes (just for readability)
X=0
Y=1

def followLine(pointA, pointB, speed):
    x1, y1 = pointA
    x2, y2 = pointB
    movement=[0, 0]
    pos=list(pointA)
    diffY=y2-y1
    diffX=x2-x1
    if abs(diffY) > abs(diffX):
        #Y distance is greater than x distace
        movement[Y]=speed
        numFrames=abs(diffY)//speed
        if numFrames==0:
            movement[X]=0
        else:
            movement[X]=abs(diffX)//numFrames
    elif abs(diffY) < abs(diffX):
        #Y distance is less than x distace
        movement[X]=speed
        numFrames=abs(diffX)//speed
        if numFrames==0:
            movement[Y]=0
        else:
            movement[Y]=abs(diffY)//numFrames
    else: #Equal
        movement=[speed]*2

    if diffY < 0:
        #is negative
        movement[Y] *= -1
    if diffX < 0:
        movement[X] *= -1

    yield pointA
    while (abs(pos[X]-x2) > speed)or(abs(pos[Y]-y2) > speed):
        pos[X] += movement[X]
        pos[Y] += movement[Y]
        yield pos
    yield pointB

However, this has 2 problems:

  • First, my main concern is that if pointA and pointB are very far apart, or if the speed is too low, the animation will pass right by pointB, and will keep going for infinity;

  • The other problem is that, at the end of the animation, there is a sort of jolt as the image snaps into place. This jolt is usually fairly imperceptible, but I’d like to try and make the animation smoother.

How can I do this? I’ve been looking into the use of trig functions and that seems promising, but I’m not much of a math person, so I’m having trouble understanding exactly how I might implement it using trig.

Also, for what it’s worth I’m using Python 3.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:24:59+00:00Added an answer on June 17, 2026 at 6:24 am

    There’s missing information, I think. Seems like you need to either substitute a numFrames arg for speed, or add a time arg in addition to speed. Assuming the former, how about this. Note this generates numFrames+1 points so that pointA and pointB are always the first and last point, respectively, but that’s trivial to change if that’s not the behavior you want:

    def followLine(pointA, pointB, numFrames):
        x1, y1 = pointA
        x2, y2 = pointB
        diffY = float(y2 - y1) /    numFrames
        diffX = float(x2 - x1) /    numFrames
    
        yield(pointA)
        for f in range(1,numFrames):
        point = (x1 + f * diffX, y1 + f * diffY)
            yield(point)
        yield(pointB)
    
    points = followLine((0,0), (1,1), 10)
    
    # then iterate over the points and do whatever                                                                                                
    for p in points:
        print str(p)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.