Generating OBJECTS one next to each other randomly.
in
Programming Questions
•
11 months ago
I am an architecture student which I am developing a simulator where the program will put blocks together according to some parameters of the user input.
The image above is the logic diagram of what I am trying to do as the first step before introducing more complexity. I have been trying to find examples from the internet, but seems there isn't any simular project.
So I have a few questions for the processing communicate.
- What is the best way to code this system? I will add more relationships between the the type of modules later
- What external library should i use if i need any?
- Any precedent?
Many thanks to the community! I have got a code as a starting point abou the creation of new modules below.
- int moduleCount_=100;
- ArrayList moduleCollection;
- void setup() {
- size(600, 600);
- moduleCollection = new ArrayList();
- for (int i = 0; i<moduleCount_; i++) {
- if (i<1) {
- Module myModule = new Module (width/2, height/2, 10, 10, 0);
- moduleCollection.add(myModule);
- }
- else {
- moduleCollection.get(i-1);
- Module myModule = new Module (int(random(0, width/10))*10, 100, 10, 10, random(100, 200));
- moduleCollection.add(myModule);
- }
- }
- }
- void draw() {
- background(255);
- for (int i = 0; i < moduleCount_; i++) {
- Module myModule=(Module) moduleCollection.get(i);
- myModule.display();
- }
- }
- class Module {
- //GLOBALS VALUES
- float xPos, yPos; //xy position
- float xDim, yDim; //xy Dimension
- float cFill;
- Module(float xPos_, float yPos_, float xDim_, float yDim_, float cFill_) {
- xPos = xPos_;
- yPos = yPos_;
- xDim = xDim_;
- yDim = yDim_;
- cFill=cFill_;
- }
- //Drawing of Modules
- void display() {
- rectMode(CENTER);
- fill(cFill);
- rect(xPos, yPos, xDim, yDim);
- }
- }
1