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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:22:47+00:00 2026-06-09T15:22:47+00:00

I did an experiment today to see what I can do with <div> s.

  • 0

I did an experiment today to see what I can do with <div>s. So I made a simple Paint-like program, which you can draw with <div>s.

$(window).mousemove(function(e){
    if(!mousedown){
        return false;
    }
    var x = e.clientX,
        y = e.clientY;

    drawDot(x,y,ele);

    lastX = x;
    lastY = y;          
});

This is part of the code. It works, but there are gaps between dots. So I created a function called fillDot which will draw a line from point A (last point) to point B (current point).

drawDot(x,y,ele);

fillDot(lastX,lastY,x,y,ele);
function fillDot(lx,ly,x,y,canvas){
    var rise = y - ly,
        run = x - lx,
        slope = rise / run,
        yInt = y - (slope * x);
    if( lx < x ){
        for(var i = lx; i < x ; i+=.5){
            var y = slope * i + yInt;
            drawDot(i,y,canvas);
        }
    }else if( x < lx ){
        for(var i = x; i < lx ; i++){
            var y = slope * i + yInt;
            drawDot(i,y,canvas);
        }
    }
}

It works fine only when I am drawing horizontal-ish lines. When I draw from top to bottom or bottom to top, there will still be gaps. I found something called Bresenham’s line algorithm which can do the same thing, but I don’t know how to use it…

Any idea how to fill all points in between?

ps: I know there is <canvas>, but I am testing what I can do with <div>.

  • 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-09T15:22:49+00:00Added an answer on June 9, 2026 at 3:22 pm

    Nevermind, I translated the Bresenham’s line algorithm into JavaScript and it works perfectly now!

    function fillDot(x0, y0, x1, y1){
       var dx = Math.abs(x1-x0);
       var dy = Math.abs(y1-y0);
       var sx = (x0 < x1) ? 1 : -1;
       var sy = (y0 < y1) ? 1 : -1;
       var err = dx-dy;
    
       while(true){
    
         drawDot(x0,y0);
    
         if ((x0==x1) && (y0==y1)) break;
         var e2 = 2*err;
         if (e2>-dy){
           err -= dy;
           x0  += sx;
         }
         if (e2 < dx){
           err += dx;
           y0  += sy;
         }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did anyone tried to customize the window in which the quicktime is playing video?
My coworker did this experiment: public class DoubleDemo { public static void main(String[] args)
Basically I did the Cavendish experiment, and I have a damped sinusoidal wave plotted
Did you used Dynamic websites before? you see its a good way for making
As an experiment, I did this: letters=['a','b','c','d','e','f','g','h','i','j','k','l'] for i in letters: letters.remove(i) print letters
So I'm writing an experiment program. One of the steps include querying an entry
In order to have a well scrambled table (for a psychological experiment), I'd like
i did this code : from scitools.std import * npoints=10 vectorpoint=array(random.uniform(-1,1,[1,2])) experiment=array(random.uniform(-1,1,[npoints,2])) print(vectorpoint=,vectorpoint) print(experiment=,experiment)
I'm trying experiment with DabbleDB to see if it's something that I could use
I have a misterious problem with my first omniauth experiment. I can log in

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.