extras:codikon:p5js:carnovsky
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| extras:codikon:p5js:carnovsky [2025/07/06 07:34] – removed - external edit (Unknown date) 127.0.0.1 | extras:codikon:p5js:carnovsky [2025/07/06 07:34] (current) – ↷ Page moved from codikon:p5js:carnovsky to extras:codikon:p5js:carnovsky Felix Hardmood Beck | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== RGB-Collage mit zufälligem Farb- und Ebenenwechsel ===== | ||
| + | < | ||
| + | < | ||
| + | <script src=" | ||
| + | </ | ||
| + | < | ||
| + | <div id=" | ||
| + | |||
| + | < | ||
| + | let images = []; | ||
| + | let imageOrder = []; | ||
| + | let colors = []; | ||
| + | |||
| + | function preload() { | ||
| + | images[0] = loadImage(' | ||
| + | images[1] = loadImage(' | ||
| + | images[2] = loadImage(' | ||
| + | } | ||
| + | |||
| + | function setup() { | ||
| + | let canvas = createCanvas(800, | ||
| + | canvas.parent(" | ||
| + | imageMode(CENTER); | ||
| + | noLoop(); | ||
| + | |||
| + | assignRandomColors(); | ||
| + | shuffleImageOrder(); | ||
| + | } | ||
| + | |||
| + | function draw() { | ||
| + | background(0); | ||
| + | translate(width / 2, height / 2); | ||
| + | |||
| + | for (let i = 0; i < 3; i++) { | ||
| + | let imgIndex = imageOrder[i]; | ||
| + | let col = colors[imgIndex]; | ||
| + | tint(col[0], | ||
| + | image(images[imgIndex], | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function mousePressed() { | ||
| + | assignRandomColors(); | ||
| + | shuffleImageOrder(); | ||
| + | redraw(); | ||
| + | } | ||
| + | |||
| + | function assignRandomColors() { | ||
| + | colors = []; | ||
| + | for (let i = 0; i < 3; i++) { | ||
| + | let rand = int(random(3)); | ||
| + | if (rand === 0) { | ||
| + | colors.push([255, | ||
| + | } else if (rand === 1) { | ||
| + | colors.push([0, | ||
| + | } else { | ||
| + | colors.push([0, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function shuffleImageOrder() { | ||
| + | imageOrder = [0, 1, 2]; | ||
| + | for (let i = imageOrder.length - 1; i > 0; i--) { | ||
| + | let j = floor(random(i + 1)); | ||
| + | [imageOrder[i], | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Der folgende p5.js-Sketch erweitert das Prinzip der RGB-Collagen, | ||
| + | |||
| + | ===== Funktionsweise im Detail ===== | ||
| + | |||
| + | * Drei Bilder werden aus dem Web geladen und zentral überlagert dargestellt. | ||
| + | * Jedes Bild erhält bei jedem Klick **zufällig** eine der drei RGB-Farben (Rot, Grün oder Blau). | ||
| + | * Die Reihenfolge, | ||
| + | * Durch `tint()` werden die Bilder mit halbtransparenter Farbe überlagert, | ||
| + | |||
| + | ===== Interaktive Komponente ===== | ||
| + | |||
| + | Mit jedem Mausklick auf die Zeichenfläche verändert sich sowohl die Farbe als auch die Sichtbarkeit der Bilder. Dieses Verhalten imitiert das Prinzip von Farbfiltern, | ||
| + | |||
| + | ===== Ziel und ästhetisches Prinzip ===== | ||
| + | |||
| + | Der Sketch demonstriert, | ||
| + | |||
| + | ===== Beispiel p5.js Code ===== | ||
| + | |||
| + | < | ||
| + | let images = []; | ||
| + | let imageOrder = []; | ||
| + | let colors = []; | ||
| + | |||
| + | function preload() { | ||
| + | images[0] = loadImage(' | ||
| + | let imageOrder = []; | ||
| + | let colors = []; | ||
| + | |||
| + | function preload() { | ||
| + | // CORS-kompatible Bilder von picsum.photos | ||
| + | images[0] = loadImage(' | ||
| + | images[1] = loadImage(' | ||
| + | images[2] = loadImage(' | ||
| + | } | ||
| + | |||
| + | function setup() { | ||
| + | createCanvas(800, | ||
| + | imageMode(CENTER); | ||
| + | noLoop(); | ||
| + | |||
| + | assignRandomColors(); | ||
| + | shuffleImageOrder(); | ||
| + | } | ||
| + | |||
| + | function draw() { | ||
| + | background(0); | ||
| + | translate(width / 2, height / 2); | ||
| + | |||
| + | for (let i = 0; i < 3; i++) { | ||
| + | let imgIndex = imageOrder[i]; | ||
| + | let col = colors[imgIndex]; | ||
| + | tint(col[0], | ||
| + | image(images[imgIndex], | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function mousePressed() { | ||
| + | assignRandomColors(); | ||
| + | shuffleImageOrder(); | ||
| + | redraw(); | ||
| + | } | ||
| + | |||
| + | function assignRandomColors() { | ||
| + | colors = []; | ||
| + | |||
| + | for (let i = 0; i < 3; i++) { | ||
| + | let rand = int(random(3)); | ||
| + | if (rand === 0) { | ||
| + | colors.push([255, | ||
| + | } else if (rand === 1) { | ||
| + | colors.push([0, | ||
| + | } else { | ||
| + | colors.push([0, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function shuffleImageOrder() { | ||
| + | imageOrder = [0, 1, 2]; | ||
| + | for (let i = imageOrder.length - 1; i > 0; i--) { | ||
| + | let j = floor(random(i + 1)); | ||
| + | [imageOrder[i], | ||
| + | } | ||
| + | } | ||
| + | </ | ||
