Projekt:2020/Processing Arrays: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 171: Zeile 171:
{{Lösung:Start|Hauptprogramm}}
{{Lösung:Start|Hauptprogramm}}
<syntaxhighlight lang="Java" line="1">
<syntaxhighlight lang="Java" line="1">
Ballon[] ballons = new Ballon[10];
class Ballon {
Spitze[] spitzen = new Spitze[60];


void setup() {
private float x, y, speed, size;
size(600, 600);
 
// Spitzen erstellen
public Ballon() {
for( int i = 0; i < spitzen.length; i++ ) {
x = random(10, width-10);
spitzen[i] = new Spitze(i*10);
y = height-10;
speed = random(20, 40)/10;
size = random(20, 30);
}
}


// Ballons erstellen
public void draw() {
for( int i = 0; i < ballons.length; i++ ) {
noStroke();
ballons[i] = new Ballon();
fill(color(23, 235, 98));
ellipse(x, y, size*.7, size);
}
}
}


void draw() {
public void update() {
  background(34, 28, 196);
y -= speed;
}


// Spitzen zeichnen
public float getY() {
for( int i = 0; i < spitzen.length; i++ ) {
return y;
spitzen[i].draw();
}
}


// Ballons zeichnen und aktualisieren
for( int i = 0; i < ballons.length; i++ ) {
ballons[i].draw();
ballons[i].update();
if( ballons[i].getY() < 20 ) {
ballons[i] = new Ballon();
}
}
}
}
</syntaxhighlight>
</syntaxhighlight>
{{Lösung:End}}
{{Lösung:End}}
8.581

Bearbeitungen