If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Removing paths, printing arrays, and array errors(3 questions)

I have three issues that I'm hoping someone can help me with. I'm a mathematician and not a programmer so I apologize in advance for the horrible mess you're about to see!

This first issue has been resolved. Thanks Old Pendant!My first issue is that my code worked perfectly fine when I used a static value for the size of my array but as soon as I tried to edit it to allow for user input the nodes(dots) are not drawn and after the first button click I get a script error I can't even check for other issues beyond that. Using a variable did work for array size in other areas of my code so I'm completely lost! Can you please take a look at the code and see if you can figure out what I'm doing wrong? Everywhere you see an n there was the number 10. It worked with the 10 but now fails with the n.

My second issue is that I can't seem to figure out how to erase the paths. I need to figure out how to erase all of the purple lines without resetting the whole system. So far everything I've tried fails. Any help here would be extremely appreciated!I've commented out my most recent completely futile and wrong attempt.

My third issue is that I want to print a counter array but only the values corresponding to the nodes where the counter array would be increasing. That will make a whole lot more sense if you look at my code. The "nodes" are a triangle of dots and I want to print out just the corresponding values from the counter array in a corresponding format. I've only found the print option where it prints in the form counter[i][j] = 0 and not just printing out the array values. Do you have any idea how to get around that? It seems like it should be simple but I can't seem to find a way to do it.

Why create all the array/subarrays in one operation and then fill the values in a separate one? Do them all at once. And don't use arrayname.length if you already know what the length is. It's much less efficient and, I think, mildly misleading in meaning. Since, in this case, your goal is to always use n as the length.

Why create all the array/subarrays in one operation and then fill the values in a separate one? Do them all at once. And don't use arrayname.length if you already know what the length is. It's much less efficient and, I think, mildly misleading in meaning. Since, in this case, your goal is to always use n as the length.

I haven't implemented your coding suggestions yet. I'm about to do that now but I did edit my OP with your suggestions of explaining what the errors are and posting the code somewhere that you can see it in action. I'm going to try out your fix not. Thanks!

ETA: I tried your fix. The button click works now and applying your fix to the array to draw the nodes fixed that issue too! Thanks so much!!!

I really didn't think that what I was suggesting was at the root of your problem. So I must have missed some errant code same as you did. I'm glad that worked!

To answer your question about erasing the paths: I've never used Raphael, but it *LOOKS* to me like the only way to do this is somewhat ugly:

To erase a path from circle c1 to circle c2:
(1) redraw the path from c1 to c2 using the background color.
(2) redraw circle c1
(3) redraw circle c2

The image you are creating on the canvas is *NOT* a set of images or layers, so far as I can tell. So you are actually simply changing individual pixel colors when you draw a shape. And that being so, the only reason to "erase" something is to restore the original colors (that is, the colors as they existed before you drew the element).

You don't *have* to do things this way in JavaScript. Instead of drawing on a canvas, you could have multiple "sprites" (actually, small <div>s containing some image or canvas of their own). You overlay a sprite on the background by controlling its z-index. And so to remove an element, you just remove the sprite (change it's style.display property to "none", for example). But that methodology has its own tediousness, and likely the erasure method I described will be less trouble than starting over.

I really didn't think that what I was suggesting was at the root of your problem. So I must have missed some errant code same as you did. I'm glad that worked!

To answer your question about erasing the paths: I've never used Raphael, but it *LOOKS* to me like the only way to do this is somewhat ugly:

To erase a path from circle c1 to circle c2:
(1) redraw the path from c1 to c2 using the background color.
(2) redraw circle c1
(3) redraw circle c2

The image you are creating on the canvas is *NOT* a set of images or layers, so far as I can tell. So you are actually simply changing individual pixel colors when you draw a shape. And that being so, the only reason to "erase" something is to restore the original colors (that is, the colors as they existed before you drew the element).

You don't *have* to do things this way in JavaScript. Instead of drawing on a canvas, you could have multiple "sprites" (actually, small <div>s containing some image or canvas of their own). You overlay a sprite on the background by controlling its z-index. And so to remove an element, you just remove the sprite (change it's style.display property to "none", for example). But that methodology has its own tediousness, and likely the erasure method I described will be less trouble than starting over.