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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:06:52+00:00 2026-06-03T05:06:52+00:00

so I have some code that draws a path and a circle. the circle

  • 0

so I have some code that draws a path and a circle. the circle is animated across the path every single time the function is initiated. I simply want to create 10 paths, each with their own circle that animates across each path. When I simply execute the function 10 times, the paths are generated fine, however the circle all animate along the same, single path. what am I doing wrong here? Is the best method here to create a for(i=0) loop?

You can view my code on jfiddle, or take a look at it here:

function commerce() {
Raphael("commercebounce", function () {
            var r = this;   
            function pathfade() {
            var pa = .1,
                pb = .4, 
                pc = [0, 2], 
                pd = [50, 300], 
                pe = [150, 800], 
                pf = [150, 350], 
                pg = pd[0] + Math.random() * (pd[1] - pd[0]), 
                ph = pe[0] + Math.random() * (pe[1] - pe[0]), 
                pi = pf[0] + Math.random() * (pf[1] - pf[0]),
                bd = .1,
                be = .9,
                pathspot = bd + Math.random() * (be - bd),
                colours = ["215,10,45", "115,115,115"],
                stroke = ["", "- "];
                opacity = pa + Math.random() * (pb - pa), colour = "rgb(" + colours[Math.round(Math.random())] + ")", strokeW = pc[Math.round(Math.random())];
                pj = r.path("M 0 " + pg + " C 0 " + pg + " " + (ph - 100) + " " + pg + " " + ph + " 400 M " + ph + " 400 C " + ph + " 400 " + (ph + 100) + " " + pg + " 960 " + pi).attr({stroke: colour,"stroke-dasharray": stroke[Math.round(Math.random())],"opacity": 0});
                bh = r.circle(0, 0, 7, 7).attr({"stroke-width": this.strokeW,stroke: colour,"stroke-opacity": this.opacity,fill: "none","fill-opacity": 0}).onAnimation(function() {
                var t = this.attr("transform")})
                leng = pj.getTotalLength();
                r.customAttributes.along1 = function (v) {
                    var point = pj.getPointAtLength(v * leng);
                    return {
                        transform: "t" + [point.x, point.y] + "r" + point.alpha
                       }
                };
                return bh.attr({along1:0}), bh.animate({along1:pathspot},300), pj.animate({opacity:opacity},300), pj, bh
             }
pathfade();//how do i repeat this function n times?               
    }); 
}
commerce();
  • 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-03T05:06:53+00:00Added an answer on June 3, 2026 at 5:06 am

    You need to break the pathfade() function into multiple simple functions that do only a few task.

    There are two main problems.
    First, you’re placing a semi-colon where there should be a comma during your variable declarations. Look at the stroke variable.
    Second, pathfade is returning multiple values when javascript only supports one. Remember that once you return from a function the rest of the statements don’t get executed.

    And lastly, use a for, do-while, or while loop to repeat your function calls.

    Here’s the fix. Sorry I didn’t have time to refactor.

    function commerce() {
        Raphael("commercebounce", function () {
            var r = this;
            function pathfade() {
                var pa = 0.5,
                pb = 0.9,
                pc = [0, 2],
                pd = [50, 300],
                pe = [150, 800],
                pf = [150, 350],
                pg = pd[0] + Math.random() * (pd[1] - pd[0]),
                ph = pe[0] + Math.random() * (pe[1] - pe[0]),
                pi = pf[0] + Math.random() * (pf[1] - pf[0]),
                bd = 0.1,
                be = 0.9,
                pathspot = bd + Math.random() * (be - bd),
                colours = ["215,10,45", "115,115,115"],
                stroke = ["", "- "],
                opacity = pa + Math.random() * (pb - pa),
                colour = "rgb(" + colours[Math.round(Math.random())] + ")",
                strokeW = pc[Math.round(Math.random())],
                pj = r.path("M 0 " + pg + " C 0 " + pg + " " + (ph - 100) + " " + pg + " " + ph + " 400 M " + ph + " 400 C " + ph + " 400 " + (ph + 100) + " " + pg + " 960 " + pi).attr({
                        stroke : colour,
                        "stroke-dasharray" : stroke[Math.round(Math.random())],
                        "opacity" : 0
                    }),
                bh = r.circle(0, 0, 7, 7).attr({
                        "stroke-width" : this.strokeW,
                        stroke : colour,
                        "stroke-opacity" : this.opacity,
                        fill : "none",
                        "fill-opacity" : 0
                    }).onAnimation(function () {
                        var t = this.attr("transform")
                    }),
                    leng = pj.getTotalLength();
                r.customAttributes.along1 = function (v) {
                    var point = pj.getPointAtLength(v * leng);
                    return {
                        transform : "t" + [point.x, point.y] + "r" + point.alpha
                    }
                };
                bh.attr({
                    along1 : 0
                });
                bh.animate({
                    along1 : pathspot
                }, 300);
                pj.animate({
                    opacity : opacity
                }, 300);
            }
            var i = 10;
            while( i-- ){
                pathfade();
            }
        });
    }
    commerce();
    

    Demo: http://jsfiddle.net/VEdwG/6/

    Your should read “The Elements of C# Style”.

    http://www.amazon.com/The-Elements-Style-Kenneth-Baldwin/dp/0521671590/ref=cm_cr-mr-title

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

Sidebar

Related Questions

I want a JLabel that draws a circle around it. I have some code
I have some OpenGL code that behaves inconsistently across different hardware. I've got some
I have some very simple code that 'correctly' draws a short vertical black line
I have the following function that draws some data from a chi-squared distribution and
We have some code that draws things using RVG in RMagick. We scale them
I have some code that looks like this (I left out the parts that
i have some code that tries to list images based on their height. the
I have some code that creates a new event source: EventLog.CreateEventSource(Source, LogName); I know
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion

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.