Skip to content

Instantly share code, notes, and snippets.

@eppfel
Created May 19, 2017 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eppfel/e5edba282ec7a5f6e302b943fa9036c4 to your computer and use it in GitHub Desktop.
Save eppfel/e5edba282ec7a5f6e302b943fa9036c4 to your computer and use it in GitHub Desktop.
p5.js Template for classes
var MyClass = function(position, color) {
this.position = position;
this.color = color;
this.change = function () {
//z.B. die Position, Farbe, o.ä. ändern/neu berechnen
};
this.draw = function () {
// das einzelnen Objekt wird gezeichnet
};
}
var myObjects = [];
function setup() {
createCanvas(windowWidth, windowHeight);
//hier wird als Beispiel ein Objekt instanziert, sollen aber mehrere werden
myObjects[0] = new MyClass(createVector(0,0), '#ff0000');
}
function draw() {
background(255);
// Hier iterieren wir über alle Objekte und zeichnen sie
for (var myObject of myObjects) {
myObject.draw();
}
}
function mouseClicked() {
//hier könnte man auf den Mausklick reagieren, indem man einzelen Objekte anspricht
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment