code:p5js:carnovsky
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
code:p5js:carnovsky [2025/03/21 13:08] – created Felix Hardmood Beck | code:p5js:carnovsky [2025/03/21 13:29] (current) – Felix Hardmood Beck | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== RGB-Collage mit zufälligem Farb- und Ebenenwechsel ===== | ||
+ | |||
< | < | ||
< | < | ||
Line 7: | Line 9: | ||
< | < | ||
- | let imgR, imgG, imgB; | + | let images = []; |
- | let layerColors; | + | let imageOrder = []; |
+ | let colors = []; | ||
function preload() { | function preload() { | ||
- | | + | |
- | imgR = loadImage(' | + | |
- | | + | |
- | | + | |
} | } | ||
Line 23: | Line 25: | ||
noLoop(); | noLoop(); | ||
- | | + | |
- | | + | |
- | [255, 0, 0], // imgR | + | |
- | [0, 255, 0], // imgG | + | |
- | [0, 0, 255] // imgB | + | |
- | ]; | + | |
} | } | ||
Line 35: | Line 33: | ||
translate(width / 2, height / 2); | translate(width / 2, height / 2); | ||
- | | + | |
- | image(imgR, 0, 0); | + | let imgIndex = imageOrder[i]; |
- | + | let col = colors[imgIndex]; | |
- | tint(...layerColors[1], 180); | + | tint(col[0], col[1], col[2], 170); |
- | | + | image(images[imgIndex], 0, 0, width, height); |
- | + | } | |
- | | + | |
- | image(imgB, 0, 0); | + | |
} | } | ||
function mousePressed() { | function mousePressed() { | ||
- | | + | |
- | | + | |
redraw(); | 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], | ||
+ | } | ||
+ | } | ||
+ | </ |
/var/www/vhosts/ct-lab.info/wiki.ct-lab.info/data/attic/code/p5js/carnovsky.1742562507.txt.gz · Last modified: 2025/03/21 13:08 by Felix Hardmood Beck