Created
May 19, 2017 09:59
-
-
Save eppfel/e5edba282ec7a5f6e302b943fa9036c4 to your computer and use it in GitHub Desktop.
p5.js Template for classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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