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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:53:16+00:00 2026-06-17T13:53:16+00:00

I want to create a periodic process with inner cycles, using javascript. Each cycle

  • 0

I want to create a periodic process with inner cycles, using javascript. Each cycle is represented by consequently changing circles – with specified time interval between them and specified time interval between cycles. The problem is also getting harder, because I also need a variable time interval between cycles and circle (which I’m going to do using random number function).

Currently I have the following code, which doesn’t work properly:

<html>
<body>

<canvas id="canv" widht="800" height="500"></canvas>
<script>

var ctx=document.getElementById("canv").getContext('2d');
var cnt=0;

var int0=self.setInterval(function(){startDraw()},5000);

function startDraw ()
{
    var int1=self.setInterval(function(){DrawC()},1000);
    cnt++;
    if (cnt==3)
    {
        int0=window.clearInterval(int0);
    }
}

function DrawC()
{
    ctx.beginPath();
    ctx.arc(200, 200, 50, 0, 2*Math.PI, true);
    ctx.fillStyle="yellow";
    ctx.fill();
    ctx.closePath();  
    var int2=self.setInterval(function(){DrawGC()},1000);
    int1=window.clearInterval(int1);
}

function DrawGC() 
{
    ctx.beginPath();
    ctx.arc(200, 200, 50, 0, 2*Math.PI, true);
    ctx.fillStyle="green";
    ctx.fill();
    ctx.closePath();  
    var int3=self.setInterval(function(){DrawWC()},1000);
    int2=window.clearInterval(int2);
}

function DrawWC() 
{
    ctx.beginPath();
    ctx.arc(200, 200, 52, 0, 2*Math.PI, true);
    ctx.fillStyle="white";
    ctx.fill();
    ctx.closePath();  
    int3=window.clearInterval(int3);
}

  function getRandomInt(min, max)
{
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

</script>
</form>

</body>
</html> 
  • 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-17T13:53:18+00:00Added an answer on June 17, 2026 at 1:53 pm

    You should make the timer variables as global. Try:

    var int0, int1, int2, int3;
    

    Remove these variable declarations from the functions.

    Try out this code, is this what you need?

    <html>
    <body>
    
    <canvas id="canv" widht="800" height="500"></canvas>
    <script>
    
    var ctx=document.getElementById("canv").getContext('2d');
    var cnt=0;
    
    var int0, int1, int2, int3;
    
    circleTime = 1000;
    cycleTime = 5000;
    
    
    int0 = self.setInterval(startDraw, cycleTime);
    
    function startDraw ()
    {
        console.log("startDraw...");
        // Start drawing circles
        self.setTimeout(DrawC, circleTime);
    
        cnt++;
        if (cnt == 4)
        {
            // Stop startDraw
            int0 = window.clearInterval(int0);
    
            /*
            // Let's draw again
            cnt = 0;
            cycleTime = getRandomInt(5000, 10000);
            circleTime = getRandomInt(1000, 2000);
            int0 = self.setInterval(startDraw, cycleTime);
            */
        }
    }
    
    function DrawC()
    {
        console.log("Circle...");
    
        ctx.beginPath();
        ctx.arc(200, 200, 50, 0, 2*Math.PI, true);
        ctx.fillStyle="yellow";
        ctx.fill();
        ctx.closePath();  
    
        self.setTimeout(DrawGC, circleTime);
    }
    
    function DrawGC() 
    {
        console.log("greenCircle...");
    
        ctx.beginPath();
        ctx.arc(200, 200, 50, 0, 2*Math.PI, true);
        ctx.fillStyle="green";
        ctx.fill();
        ctx.closePath();  
    
        self.setTimeout(DrawWC, circleTime);
    }
    
    function DrawWC() 
    {
        console.log("whiteCircle...");
    
        ctx.beginPath();
        ctx.arc(200, 200, 52, 0, 2*Math.PI, true);
        ctx.fillStyle="white";
        ctx.fill();
        ctx.closePath();  
    }
    
    function getRandomInt(min, max)
    {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    
    </script>
    </form>
    
    </body>
    </html>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create a script in selenium IDE using html. I am not able
I want create twitter-parser, using tweepy - thats ok. But also, i want use
I want create own SetupTypeDlg using wix default dialogs to show the disk costs
I want create a site by command line using appcmd. How can I associate
I'm trying to create a periodic callback using QT. I'm thinking, something like OpenGL's
I want create a process under another user. So I use LogonUser and CreateProcessAsUser.
I want create batch process to update files on android tablet (for non-experienced user)
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that

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.