Project written for with P5.js library : Minimal project for manipulating objects stored in an array. See the project live on p5js.org.
Handling multiple objects in an array of objects is a frequent and important part of object-oriented programming.
Here is a minimal program to illustrate object handling with P5.js. The program automatically generates 20 rectangles of different sizes and colours. These are the properties of each 'rectangle' object.
Each rectangle is therefore an object, they are all registered when they are created in the array "rectangles = []". Each element of the array, thus each rectangle, can be manipulated individually thanks to the methods of the "rectangle.js" class. Clicking on a rectangle calls the 'delete' method which deletes the rectangle(s) under the mouse pointer. Double-clicking on the canva creates a new rectangle.
If these lines of code are useful to you or if you want to leave me a comment (always appreciated): contact me on Linktree
This is free software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. The Unlicense