Skip to content

P5.js. Minimal project : handling objects in an array.

License

Notifications You must be signed in to change notification settings

zeredbox/handling-array-of-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code snippet. Minimal project : handling multiple objects in an array

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

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.

hsb harmonic color

Write me or comment

If these lines of code are useful to you or if you want to leave me a comment (always appreciated): contact me on Linktree

License

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