LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programatically draw new circles on a picture control

Solved!
Go to solution

Hi, I am fairly new to LV and to programming in general. I'm creating a program to get better. In this program I have balls bouncing around on a picture control. I use an array to keep track of my ball's position (x,y) and another to track their speed. I want that each time a ball reaches the border of the picture, it splits into 2 balls. My problem is that I can't find a way to programatically add these new balls because each draw circle vis need to be serialy linked and then drawn onto the picture. What am I missing?

0 Kudos
Message 1 of 12
(3,558 Views)

You'll need a For Loop in your innermost loop that iterates through drawing each of the balls.  Keep track of the balls in an array.  If you only have 1 ball, the For Loop runs once.  If you have 2 balls, the loop will run twice.  Four, it will run 4 times.  Each time a ball splits, you add the new ball to the array.

0 Kudos
Message 2 of 12
(3,555 Views)

In addition to what RavensFan says, right click on the for loop and Add Shift Register.  Wire in your picture to this shift register and it will pass the picture to the next iteration of the loop. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 12
(3,545 Views)

Thank you RavensFan and aputman!

 

I had thought of the for loop, but couldn't figure out how to all add them to the same picture. I think the shift register is what I was missing.

0 Kudos
Message 4 of 12
(3,537 Views)

Wait, after playing with it a little, I still can't get it to work. I wired the number of iterations to my index array function so that each iteration could pull the coordinates from the next line in my postion array. But this only made it so that the ball being drawn is the one corresponding to my ball counter. If the ball counter goes up, the current ball ceases to be drawn and the one on the next line starts being drawn. Using shift register results in all the instances of my ball staying on the control (showing a trajectory instead of only current position).

0 Kudos
Message 5 of 12
(3,528 Views)

This is the point where you will post a VI showing what you have so we don't have to guess what the problem may be.

0 Kudos
Message 6 of 12
(3,521 Views)

Oops, sorry I'm new at this stuff. Attached is my latest iteration.

0 Kudos
Message 7 of 12
(3,513 Views)
Solution
Accepted by topic author julmich

You need to iterate on your array of balls.  That means using auto-indexing.  Right now, you have no reason to wire a value to N in the For Loop.  And wiring that value to the Array Index function gives you invalide data that is either nothing, or the same ball if it exists in the array.

 

I cleaned up some other things in your code.

1.  Negate function.  No need to multiply by -1.

2  Index Array.  It is expandable.  Drag the bottom border downwards.

 

Your next bit of code to add would be where you decide to add another ball and put that into the Speed and Position Arrays.

 

 

Message 8 of 12
(3,507 Views)

After you move the location of all of the balls, you will need to clear out your picture indicator and then draw the next location.  Otherwise you will get a trail effect.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 9 of 12
(3,504 Views)

Oh wow Awesome thanks! 

 

I think I get it, correct me if I'm wrong: I don't need to wire anything to N because the loop will only iterate for the number of auto indexed item (in this case 2) If I add another line of coordinate to my position array, it will automatically run another iteration of that For loop.

 

I also have 2 questions:

1. What's the advantage in using a wait vi instead of the wait until?

2. Whats is that thing on the left side of the shift register that you added? it juste shows as an empty white box and the context help says nothing.

 

Many thanks for all your help.

0 Kudos
Message 10 of 12
(3,492 Views)