Page 1 of 1
Dynamic Duplication
Posted: Wed Jan 23, 2013 3:12 am
by alexalthauser

I built this schematic. Basically I am able to click on the square in the window, and drag it around on the screen.
I would like to know if there is an easy way to dynamically create a new square so that when I drag the mouse away from the square, it stays there, but a new square is created.
I am pretty certain that I can do it using Ruby, but I was wondering if there might be an answer using just components?
Re: Dynamic Duplication
Posted: Wed Jan 23, 2013 7:01 am
by alexalthauser
Not to 'bump' this post, but I wanted to add that a module which could build and place other stored modules would be incredibly useful.
Re: Dynamic Duplication
Posted: Wed Jan 23, 2013 1:46 pm
by tor
Is it possible to do this?
Yes, sort of. You would have to make a finite set of squares in forehand that is hidden until some user interaction will unhide them at the desired place. If it is easy or not depends on you and you skills. I really cant think of any examples atm either.
As you suggest Ruby is the best method here. But I am not that skilled with Ruby yet so I cant give you any good advice other than that.
Re: Dynamic Duplication
Posted: Wed Jan 23, 2013 3:43 pm
by tor
I tried to make an example for you. It is very basic and can make only two squares:
First click (and hold) anywhere in the field to make square 1. Drag to desired position.
Then click (and hold) on square 1 to make nr 2. Drag to desired position.
Click Reset button to restart the procedure.
It should be fairly easy for you to make more squares. If you need more guidance (I did not comment the scematic) please tell and I shall see if I can. It is also possible to move the squares after placement with some more logic not implemented here.
Re: Dynamic Duplication
Posted: Wed Jan 23, 2013 8:21 pm
by trogluddite
You don't necessarily need 'hidden' elements either.
The trick is to keep all of the data about each "object" in an array of some kind - and draw the objects by looping through the array. Once you have that structure, adding a new object is just a matter of adding new data to the array.
Similarly you can then delete objects by removing them from the array.
My
'button array' example shows an example of the kind of system needed - there's no adding/removing items currently - but everything is in place there to make it possible.
Something similar could also be done using primitives - float arrays and a 'Draw Loop'. The stock "multi-stage envelope" uses this approach to allow the number of envelope stages to be changeable.
Re: Dynamic Duplication
Posted: Wed Jan 23, 2013 11:18 pm
by alexalthauser
Tor:
I can follow some of the schematic, but other parts I don't understand. It works nicely though. I will work some more on studying it.
Trog:
I will have to learn a bit more about Ruby, but I understand most of the code.
I'm off to a good start, thank you both.
Re: Dynamic Duplication
Posted: Thu Jan 24, 2013 12:33 am
by tor
Just tell if you need more info

Glad to help
