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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:38:04+00:00 2026-06-15T15:38:04+00:00

This problem is going to be the death of me. I’m trying to make

  • 0

This problem is going to be the death of me. I’m trying to make a starfield type animation from scratch using jquery. The link to my jfiddle is http://jsfiddle.net/wompdesigns/jNBAk/4/ . This gives me 12 randomly placed small divs on the screen just fine. I don’t really have a problem doing an animation codewise. What I do have a problem with is finding the destination point with the placed divs (red) from the center point div (green). In other words, I want to go from the placed divs (red) to the end of the parent div at an angle corresponding from the center (green). I hope this question makes sense and thank you to anyone who tries to solve this. The jquery code is as follows:

$('.cs').each(function(index) {
    var posx = Math.ceil(Math.random() * (60-40+1)) + 40;
    var posy = Math.ceil(Math.random() * (60-40+1)) + 40;
    $(this).css({left: posx+"%", top: posy+"%", });
});
  • 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-15T15:38:05+00:00Added an answer on June 15, 2026 at 3:38 pm

    Probably you should post this in a math or geometry stach exchange site too… Anyway finding the angle should be simple math. My approach would be:

    for each red dot
      Get the center of the red dot:
      X = $(this).position().left + $(this).width() / 2
      Y = $(this).position().top + $(this).heigh() / 2
    
    Likewise, get the green dot center as well 
      Cx, Cy = something (it is not 0,0)
    
    for each red dot,
      the angle is the arctan((Y-Cy)/(X-Cx))
      to make things simple:
        for every 1 (or -1 if X<Cx) pixel step horizontally
        make (Y-Cy)/(X-Cx) pixel steps vertically
    

    Sorry about the ugly pseudo-code, you should be able to quickly convert it into JS. You don’t even need to calculate the arctan as long as you step the right amount in the appropriate directions.

    Let me know if it works…

    Something like this is the result: http://jsfiddle.net/jNBAk/7/

    It was some good fun to make it work! 🙂

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

Sidebar

Related Questions

this problem is going to make me bald. Save my hair plz. i have
I am going to generate report by using FPDF . My Problem Like this
This problem is going to be hard for me to explain but I will
This problem may be a little broad, but I'm going to go ahead and
I've been going at this problem for a solid couple hours now and having
Firstly, this is going to sound like homework, but it ain't. Just a problem
This problem is caused by my acknowledge of English and jQuery or maybe something
i was going smooth with my html and css codes until this problem i
this is my first Windows 8 app... I'm having this last problem before going
I'm really going mad with this problem! I have an app that contains a

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.