Dynamic Duplication

For general discussion related FlowStone
Post Reply
alexalthauser
Posts: 9
Joined: Thu Jan 20, 2011 7:29 am

Dynamic Duplication

Post by alexalthauser »

Image
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?
alexalthauser
Posts: 9
Joined: Thu Jan 20, 2011 7:29 am

Re: Dynamic Duplication

Post 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.
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: Dynamic Duplication

Post 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.
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: Dynamic Duplication

Post by tor »

I tried to make an example for you. It is very basic and can make only two squares:
Add squares.fsm
(2.04 KiB) Downloaded 1089 times

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.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Dynamic Duplication

Post 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.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
alexalthauser
Posts: 9
Joined: Thu Jan 20, 2011 7:29 am

Re: Dynamic Duplication

Post 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.
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: Dynamic Duplication

Post by tor »

Just tell if you need more info :)

Glad to help ;)
Post Reply