code:p5js:gestaltrule_09
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
code:p5js:gestaltrule_09 [2025/03/20 09:05] – Felix Hardmood Beck | code:p5js:gestaltrule_09 [2025/03/20 09:23] (current) – Felix Hardmood Beck | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Im unteren Beispiel bewegt sich eine Gruppe von Kreisen synchron in eine gemeinsame Richtung. Unabhängig davon bewegen sich andere Kreise auf andere Art und Weise. Sich gleich bewegende Kreise werden als eine Einheit wahrgenommen. | ||
+ | |||
+ | |||
< | < | ||
< | < | ||
Line 12: | Line 15: | ||
function setup() { | function setup() { | ||
- | createCanvas(1280, 600).parent(" | + | createCanvas(960, 600).parent(" |
for (let i = 0; i < 6; i++) { | for (let i = 0; i < 6; i++) { | ||
group1.push(new MovingCircle(random(100, | group1.push(new MovingCircle(random(100, | ||
Line 61: | Line 64: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | let circles = []; | ||
+ | let group1 = []; | ||
+ | let group2 = []; | ||
+ | let speedX = 2; | ||
+ | let speedY = 1; | ||
+ | |||
+ | function setup() { | ||
+ | createCanvas(600, | ||
+ | | ||
+ | // Gruppe 1: Bewegt sich synchron (gemeinsames Schicksal) | ||
+ | for (let i = 0; i < 6; i++) { | ||
+ | group1.push(new MovingCircle(random(100, | ||
+ | } | ||
+ | | ||
+ | // Gruppe 2: Bewegt sich zufällig | ||
+ | for (let i = 0; i < 6; i++) { | ||
+ | group2.push(new MovingCircle(random(300, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function draw() { | ||
+ | background(240); | ||
+ | | ||
+ | // Zeichne und bewege die Gruppen | ||
+ | for (let c of group1) { | ||
+ | c.moveTogether(); | ||
+ | c.display(color(0, | ||
+ | } | ||
+ | | ||
+ | for (let c of group2) { | ||
+ | c.moveRandom(); | ||
+ | c.display(color(255, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class MovingCircle { | ||
+ | constructor(x, | ||
+ | this.x = x; | ||
+ | this.y = y; | ||
+ | this.grouped = grouped; | ||
+ | } | ||
+ | | ||
+ | moveTogether() { | ||
+ | this.x += speedX; | ||
+ | this.y += speedY; | ||
+ | if (this.x > width || this.y > height) { | ||
+ | this.x = random(100, 300); | ||
+ | this.y = random(100, 300); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | moveRandom() { | ||
+ | this.x += random(-2, 2); | ||
+ | this.y += random(-2, 2); | ||
+ | } | ||
+ | | ||
+ | display(col) { | ||
+ | fill(col); | ||
+ | noStroke(); | ||
+ | ellipse(this.x, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ |
/var/www/vhosts/ct-lab.info/wiki.ct-lab.info/data/attic/code/p5js/gestaltrule_09.1742461522.txt.gz · Last modified: 2025/03/20 09:05 by Felix Hardmood Beck