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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:31:42+00:00 2026-06-17T11:31:42+00:00

I am trying to create an application in jQuery (I am new to in

  • 0

I am trying to create an application in jQuery (I am new to in this) where circles appear randomly in canvas every second. I generate them in a for loop but dont know how to make them appear after some elapsed time. I tried using setInterval() and delay() but it didnt work (I think my syntax wasnt well written). Sorry if this question is too basic.

Here is my code:

var canvas, ctx;
var circles = [];
var selectedCircle;
var hoveredCircle;

function Circle(x, y, radius){
    this.x = x;
    this.y = y;
    this.radius = radius;
}

function clear() { // clear canvas function
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}

function drawCircle(ctx, x, y, radius) { // draw circle function
    ctx.fillStyle = 'rgba(255, 35, 55, 1.0)';
    ctx.beginPath();
    ctx.arc(x, y, radius, 0, Math.PI*2, true);
    ctx.closePath();
    ctx.fill();
}

$(function(){
    canvas = document.getElementById('scene');
    ctx = canvas.getContext('2d');

    var circleRadius = 15;
    var width = canvas.width;
    var height = canvas.height;

    var circlesCount = 60; // we will draw 60 circles randomly
    for (var i=0; i<circlesCount; i++) {
        var x = Math.random()*width;
        var y = Math.random()*height;    
        circles.push(new Circle(x,y,circleRadius));
        drawCircle(ctx, circles[i].x, circles[i].y, circleRadius);
    }
});

Thanks for any help!

EDIT: Here are few examples that didnt work:

delay(1000) // after drawing function
drawCircle(ctx, circles[i].x, circles[i].y, circleRadius).delay(1000);
setInterval(drawCircle(ctx, circles[i].x, circles[i].y, circleRadius) {
}, 2000);
drawCircle(ctx, circles[i].x, circles[i].y, circleRadius).delay(1000).setInterval(1000);
  • 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-17T11:31:42+00:00Added an answer on June 17, 2026 at 11:31 am

    Try below solution. Read the comment for more details

    $(function(){
        canvas = document.getElementById('scene');
        ctx = canvas.getContext('2d');
    
        var circleRadius = 15;
        var width = canvas.width;
        var height = canvas.height;
        var timer, index = 0;
    
        var circlesCount = 60; // we will draw 60 circles randomly
        for (var i=0; i<circlesCount; i++) {
            var x = Math.random()*width;
            var y = Math.random()*height;    
            circles.push(new Circle(x,y,circleRadius));
        }
    
        // draw one circle per second
        timer = setInterval(function(){
            // exit loop when there's no more circles to draw
            if(index >= circles.length) {
                 // also clear the timer
                 clearInterval(timer);
                 return;
            }
    
            drawCircle(ctx, circles[index ].x, circles[index ].y, (hoveredCircle == index) ? 25 : 15);
            // go to next circle
            index += 1;
        }, 1000);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create application from scratch. In new maven project i add a
I'm trying to create a chat application with jQuery without having to using setTimeout
I am a completely new to mvc and trying to create a dummy application
I'm trying to create a basic Node application, every time a client connects I
so i have an already working jquery ajax application that i'm trying to create
I'm trying to create a calender application using jquery. I'm using a table that
I am trying to create an application compatible with both retina and non-retina displays.
I am trying to create BB application that features the in-app purchase. I followed
I am trying to create an application that makes a window (external to the
I'm trying to create an application where there is a JSplitPane which contains the

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.