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 9213541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:46:22+00:00 2026-06-18T01:46:22+00:00

I’m trying to figure out how to make an animation for an algorithm in

  • 0

I’m trying to figure out how to make an animation for an algorithm in JavaScript. More general though, how are algorithm animations done in other languages (i.e. Java)? Is the animation aspect separate from the algorithm logic? So, for example, I have my sorting algorithm working, and I would have a special Animation object that just “observes” the state of the list in question for any changes, or are the snippets in the algorithm logic that notifies the animation object of modifications to the list, and invokes the necessary animation methods?

Back to JavaScript, in may case, I have implemented an Huffman encoding algorithm that works; the only thing I’m trying to do is make an accompanying animation to demonstrate what its actually doing. So far, my approach is to use the d3 library or jquery for the animations, the only thing I’m stuck on is how to actually invoke any animation routines from my algorithm code.

I realize that its not really possible in JavaScript to pause execution at a line of code (or wait) for an animation to complete.

Any suggestions on the best way to approach this problem?

EDIT:
For example, the below code builds a queue of elements, and I would like to animate the queue being built as its doing it:

var i,j;
var input = $('#input').val();
var input_array = input.split('');
for (i=0; i<input_array.length; i++){
    var temp = new Node(input_array[i], 1);
    for (j=i+1; j<input_array.length; j++) {
        if (input_array[j] == input_array[i]) {
            temp.frequency++;
            input_array.splice(j, 1);
         }
     }
     Queue.push(temp);
}
  • 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-18T01:46:23+00:00Added an answer on June 18, 2026 at 1:46 am

    not possible to pause execution at a line of code or wait for an animation to complete.

    Yes, that’s true, since animations in JS are asynchronous. You have 2 choices:

    • Make your algorithm asynchronous as well. This would be a function that gets the current state of the algorithm and returns the state after one step (and/or possibly the step itself so the matching single animation can be chosen). The step function would then be called from the animation loop each time.
    • Maintain an animation queue (I guess your libraries have helper functions for that). Then run your algorithm as it is, and in each step chain another animation-to-be-executed at the end of the queue. Once the algorithm is ran, start the animation queue.

    Option #1 is more elegant, but of course more complicated – all loops will need to become recursive functions etc. Yet this is the only possibility if your algorithm is non-terminating, or the animation queue of option #2 would become too long (and memory-eating).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to render a haml file in a javascript response like so:
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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 am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I

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.