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

  • Home
  • SEARCH
  • 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 8880889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:14:36+00:00 2026-06-14T20:14:36+00:00

I am using Raphael.js to visualize a convex hull algorithm. However I want to

  • 0

I am using Raphael.js to visualize a convex hull algorithm.
However I want to be able to step through the different parts of the code (or use something like sleep()/delay()). However, I can’t see a way of accomplishing this using setTimeOut(). Any ideas?

For example:

sort(points);
//sleep(...)/delay(...)/pause until click?
for(...) {
   message('Foo thing');
   //sleep(...)/delay(...)/pause until click?
   while() {
      message('Comparing points');
      //sleep(...)/delay(...)/pause until click?
   }
}

A screenshot of the result of the algorithm. Points in red indicate an element of the convex hull.

  • 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-14T20:14:36+00:00Added an answer on June 14, 2026 at 8:14 pm

    In JavaScript there is no way to suspend code execution with sleep function. Executing JavaScript code is designed to be non-blocking.

    Solution with using debugger keyword works on Chrome as well. You just have to open Developer Tools.

    I prepared demo which works in different way. It simulates sleep function using setInterval and does not block scripts execution. However, it involves some additional code.

    Let’s assume that we have initial code:

    var arr = [0, 1, 2, 3, 4];
    
    function step(val) {
        console.log(val);
    }
    
    for (var i = 0, len = arr.length; i < len; i++) {
        step(arr[i]);
    }
    

    Now, we’d like to rewrite it so that each log shows after one second:

    var arr = [0, 1, 2, 3, 4],
    steps = [];
    
    function step(val) {
      console.log(val);
    }
    
    for (var i = 0, len = arr.length; i < len; i++) {
      steps[i] = step.bind(null, arr[i]);
    }
    
    var int = setInterval(function() {
        var fun = steps.shift();
        if(!fun) {
            clearInterval(int); 
            return;
        }
        fun();
    }, 1000);
    

    Let me explain it a little bit. Firstly, I define steps array, where I put new functions with bound arguments. bind function basically creates new function with arguments which are bound to provided values. More details on MDN page.

    Example:

    function step(a) { console.log(a); }
    var step1 = step.bind(null, 1);
    // now step1 is like `var step1 = function() { console.log(1); }`
    

    In for loop I create and put new functions using bind. The last step is to extract these functions from steps array, starting from beginning (using Array.prototype.shift method), and execute them with interval equal to 1 second.

    I know it’s not a direct solution of your problem, but I hope it helps you convert your code properly. If you decide to do so, I advise to convert code blocks within for and while loops to functions. It simplifies conversion a little bit.

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

Sidebar

Related Questions

I am creating a module to graphically visualize workflows using raphael,which take data from
Very new to using Raphael.js I'm looking at the tutorials and I am able
I have converted svg to image using Raphael.js , canvg and jquery. But want
Using Raphael, I wish to be able to drag a shape (an ellipse in
I am using Raphael and I want to create a rect and control the
I'm trying to create an image animation using Raphael JS. I want the effect
So I have been using raphael to create a user interface and want it
I'm trying to be able to drag SVG elements (using Raphael) loaded from a
I'm using Raphael to build a map-like site. when panning and zooming I want
I am using Raphael graphics and animations which is a javascript library. I want

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.