0

I have a seat function which takes a number of values, 3 of which are used to draw circles on the canvas.

each circle is a var named after a person and containing the values from the seat function.

I have the following function which I use to draw the individual circles:

                ctx.fillPerson = function(p){
                    this.fillStyle = p.fillStyle;
                    this.arc(p.centerX, p.centerY, p.radius, 0, 2*Math.PI, false);
                    this.fill();
                }

this works great when I do for example, ctx.fillPerson(johnSmith); however I am creating multiple groupings of people in array form and I need a function to draw the people in these arrays.

I have an array containing the variables mentioned above like this: var seatingOne = [johnSmith, joanSmith, bobJohnson, jillJohnson];

However, I can't seem to get the function right, I feel like I am on the right track, but my limited javascript knowledge is holding me back. So far I have this:

            ctx.fillSeats = function(s){
                for ( var i=0; i<s.length; ++i ){
                    ctx.beginPath();
                    ctx.fillPerson(indexOf(s));
                }
            }

My thinking is that I step through the array and perform a beginPath(); and ctx.fillPerson(); for each array item. I THINK(?) indexOf if the right tool to use but I am unsure if it is and exactly how to get the desired result.

Any help is much appreciated and please correct me if I said anything improperly (not hip to the all the lingo quite yet either ;) )

Thanks

3
  • I think you want s[i] instead of indexOf(s)? Commented Jul 22, 2011 at 20:49
  • that is probably correct and I made the change but still nothing is being drawn when I use ctx.fillSeats(myArray); Commented Jul 22, 2011 at 20:58
  • This turned out to be correct, my typo was to blame. thanks Commented Jul 22, 2011 at 21:09

1 Answer 1

1

ctx.fillPerson(s[i]);

I don't know off the top of my head if you need to end the path each loop.

Sign up to request clarification or add additional context in comments.

1 Comment

I made this change, but it still isn't drawing anything when i use ctx.fillSeats(myArray); I know before I started grouping that I could just list the ctx.fillPerson(myVar); each with a ctx.beginPath(); before it and it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.