xxxxxxxxxx
var Vollkorn;
var cover;//Quelle: https://www.instagram.com/p/Bd0E-qgju3Y/?taken-by=montagueprojects
var Kugeln = [];
function preload() {
Vollkorn = loadFont ("Vollkorn-Regular.ttf");
cover = loadImage ("abc.png");
}
function setup() {
createCanvas(330,500);
//reset();
background(100);
}
function draw() {
fill(100,115,118);
strokeWeight(0.5);
stroke (0);
// Hintergrund Buchcover
rect(0,0,330, 500);
fill(255, 204, 0);
// rotierendes Rechteck
push ();
translate (100,35);
rotate ((millis ()/1000)*5); // rotiert nur in eine Richtung
rectMode (CENTER)
rect (0,0,210,20);
pop (); // push&pop als Abgrenzung zum Rest des Codes
//kleine Punkte oben
ellipse( 223,37,15,15);
ellipse( 246,37,15,15);
ellipse( 269,37,15,15);
ellipse( 290,37,15,15);
//Überschrift
fill(0);
textFont (Vollkorn);
textSize (25)
textAlign(CENTER,CENTER);
text("Black Students",100,82);
text("in White Schools",109,108);
// Autor
textSize (16)
textAlign (CENTER, CENTER);
text("Edgar A. Epps ,Editor",229,286);
//springende Kugeln
for (var i = 0; i < Kugeln.length; i++) {
var gravity = createVector(0, 0.1*Kugeln[i].mass);
//Schwerkraft anwenden
Kugeln[i].applyForce(gravity);
// aktualisieren und anzeigen
Kugeln[i].update();
Kugeln[i].display();
Kugeln[i].checkEdges();
}
}
// zufälliger Neustart der Kugeln
function reset() {
for (var i = 0; i < 9; i++) {
// Größe Anzahl Höhe
Kugeln[i] = new Kugel(7, -20+i*110, -100);
}
}
function mousePressed() {
reset();
}
function Kugel(m,x,y) {
this.mass = m;
this.position = createVector(x,y);
this.velocity = createVector(0,0);
this.acceleration = createVector(0,0);
}
Kugel.prototype.applyForce = function(force) {
var f = p5.Vector.div(force,this.mass);
this.acceleration.add(f);
};
Kugel.prototype.update = function() {
// die Geschwindigkeit ändert sich entsprechend der Beschleunigung
this.velocity.add(this.acceleration);
// Die Position ändert sich durch Geschwindigkeit
this.position.add(this.velocity);
this.acceleration.mult(0);
};
Kugel.prototype.display = function() {
// große Kreise
stroke(0);
strokeWeight(0.5);
fill(255, 204, 0);
ellipse(this.position.x,this.position.y,this.mass*16,this.mass*16);
};
// Hochspringen
Kugel.prototype.checkEdges = function() {
if (this.position.y > (430 - this.mass*8)) {
// Geschwindigkeit dämpfen,wenn sie den Boden berühren
this.velocity.y *= random(-0.9,-0.5);
//der Höhe angepasst, ab welcher sie springen sollen
//mit welchem "Schwung" sie springen sollen, wenn Wert höher,
// kommen sie nicht mehr zum Stillstand
// Höhe der Leinwand
this.position.y = (430 - this.mass*8);
}
};