Hier das versprochene Beispiel vom heutigen Tag.
Category Archives: input
Textsuche
Da viele von euch in irgendeiner Weise Texte durchstöbern wollen, hier nochmal ein Beispiel, wie es gehen könnte.
Die Funktion “find” muss dabei nicht unbedingt verstanden werden, sondern kann ersteinmal so benutzt werden.
Im Beispiel seht ihr ausserdem nochmal wie man Buchstabe für Buchstabe über den Text geht (so wie wir es bei der Ursonate benutzt hatten).
Wie immer bei Fragen: fragen!
hier der Download
Look Here – OpenProcessing
das wollte ich euch nicht vorenthalten. (ungewollt?) lustig und sehr schöne idee!
Look Here – OpenProcessing
OpenProcessing
Für alle die noch ein bisschen Anlaufschwierigkeiten mit den Aufgaben und Projekten haben: Schaut euch mal OpenProcessing an
“What? A website to share Processing sketches??”
share your sketches with others
help and collaborate with the community
improve and polish your programming skills
follow classes around the world teaching processing
Hier findet ihr viele kleine und größere Processing-Programme von Leuten, die so wie ihr auch dabei sind Processing zu lernen. Zum Beispiel vom Programming Interactivity Kurs an der UCLA (inkl. einer ähnlichen Aufgabe – Stichwort: Kandinsky – wie sie die Kollegen aus CC2 kennen dürften)
Neue Video Tutorials
![]()
Vielleicht fürs Video-Pong von Karim interessant:
Im creativecoding.org wiki sind neue Tutorials zum Live-Video Input verfügbar. Besonders das Feststellen von Aktivität in unterschiedlichen Bildbereichen.
Collision Detection für Game Levels
Das ist für alle interessant, die planen ein Spiel mit einem Level zu bauen in dem es Gänge, Ecken, Fallen, etc. gibt.
Fragen können hier gestellt werden!
Download: Collision Map Example
int x; // our player's x-position
int y; // our player's y-position
int s; // our player's visual size
int half_size; // // half our player's visual size
int speed; // the speed at which we are moving
// our displayed level
PImage level;
// our collision map, basically a two-dimensional array (an array of arrays)
// the information of where we are able to go is encoded in the following way
// where '1' is 'true' and '0' is 'false'
/*
* 0 1 0 0 0 0 0
* 0 1 0 0 0 0 0
* 0 1 1 1 1 1 1 ---> a way! :)
* 0 1 0 0 0 0 0
* 0 1 0 0 0 0 0
*/
// this matrix will have the same dimension as our level image
boolean[][] collisionMap;
void setup() {
size(200, 200);
background(0);
// draw our player from the center
rectMode(CENTER);
// start in the center of the canvas
x = width/2;
y = height/2;
// size of 10, half_size will be 5
s = 10;
half_size = s / 2;
// moving 2 pixels each time we press a key
speed = 2;
// load our lovely level image
level = loadImage("level.gif");
// load our black & white pixel collision map image
PImage colMapImage = loadImage("collisionMap.gif");
// generate our collision map as an two-dimensional boolean array
collisionMap = new boolean[colMapImage.width][colMapImage.height];
// our collision map is encoded only in black & white pixels
// so we get them for comparison
color black = color(0);
color white = color(255);
// go through each row in our collision map image
for (int i = 0; i < colMapImage.width; i++) {
// go through each column in our collision map image
for (int j = 0; j < colMapImage.height; j++) {
// get the color value of the pixel at our current position
color c = colMapImage.get(i, j);
// if the pixel is black
if (c == black) {
// we can't go there
collisionMap[i][j] = false;
}
// if it is white
else if (c == white) {
// it's good to go
collisionMap[i][j] = true;
}
else {
// should happen ;)
println("Whoops! We shouldn't have colors other than black and white in our collision map!");
}
}
}
}
void draw() {
background(0);
// show our level
image(level, 0, 0);
// draw our player at it's current position
fill(255, 0, 0);
noStroke();
rect(x, y, 10, 10);
}
/*
* this is where we actually move
* the strategy is as follows:
* - pretend we would move in the planned direction
* (left, right, up or down)
* - then check if at this new position, all 4 corners
* of our rectangle would be within our allowed area
* - if that's the case: move
*/
void keyPressed() {
// would each corner of the next step be within our boundaries?
// default: no!
boolean up_left = false;
boolean up_right = false;
boolean down_right = false;
boolean down_left = false;
if (keyCode == LEFT) {
// check first if we are still within our canvas
if (x >= half_size + speed)
{
// check all four corners to see if they would be with the allowed area
up_left = collisionMap[x - speed - half_size][y - half_size];
up_right = collisionMap[x - speed + half_size][y - half_size];
down_right = collisionMap[x - speed + half_size][y + half_size];
down_left = collisionMap[x - speed - half_size][y + half_size];
// if that's the case for each corner
if (up_left && up_right && down_right && down_left) {
// move
x -= speed;
}
}
}
// this basically is repeated for all possible ways to go…
if (keyCode == RIGHT) {
if (x < = width - half_size - speed)
{
up_left = collisionMap[x + speed - half_size][y - half_size];
up_right = collisionMap[x + speed + half_size][y - half_size];
down_right = collisionMap[x + speed + half_size][y + half_size];
down_left = collisionMap[x + speed - half_size][y + half_size];
if (up_left && up_right && down_right && down_left) {
x += speed;
}
}
}
if (keyCode == UP) {
if (y >= half_size + speed)
{
up_left = collisionMap[x - half_size][y - speed - half_size];
up_right = collisionMap[x + half_size][y - speed - half_size];
down_right = collisionMap[x + half_size][y - speed + half_size];
down_left = collisionMap[x - half_size][y - speed + half_size];
if (up_left && up_right && down_right && down_left) {
y -= speed;
}
}
}
if (keyCode == DOWN) {
if (y < = height - half_size - speed)
{
up_left = collisionMap[x - half_size][y + speed - half_size];
up_right = collisionMap[x + half_size][y + speed - half_size];
down_right = collisionMap[x + half_size][y + speed + half_size];
down_left = collisionMap[x - half_size][y + speed + half_size];
if (up_left && up_right && down_right && down_left) {
y += speed;
}
}
}
}
Array/Schneeflocken Beispiel
// globable Arrays für die Ablage der Position
float xpos[] = new float[150];
float ypos[] = new float[150];
void setup () {
size(500, 500);
smooth ();
// Einmaliges Festlegen der x- und y-Position
for (int i=0; i < ypos.length; i++) {
xpos[i] = random (width);
ypos[i] = 0;
}
}
void draw () {
// Hintergrund leeren
background (0);
stroke(255);
// Führe die Schleife für jeden einzelnen
// Kreis aus, angegeben durch die Länge von 'xpos'
for (int i=0; i < ypos.length; i++) {
// Position modifiziere
ypos[i] = ypos[i] + 1 + i*.01;
// Zurücksetzen der Position auf den oberen
// Bildschirmrand wenn die Position größer als
// die Bildschrimhöhe ist
if (ypos[i] > height) {
ypos[i] = 0;
xpos[i] = random(width);
}
// Zeichnen der Schneelocke an die aktuelle Position
stroke(255, i*2);
line(xpos[i], ypos[i], xpos[i] + i*.1, ypos[i]);
line(xpos[i], ypos[i], xpos[i] - i*.1, ypos[i]);
line(xpos[i], ypos[i], xpos[i], ypos[i] + i*.1);
line(xpos[i], ypos[i], xpos[i], ypos[i] - i*.1);
line(xpos[i], ypos[i], xpos[i] + i*.05, ypos[i] + i*.05);
line(xpos[i], ypos[i], xpos[i] - i*.05, ypos[i] - i*.05);
line(xpos[i], ypos[i], xpos[i] - i*.05, ypos[i] + i*.05);
line(xpos[i], ypos[i], xpos[i] + i*.05, ypos[i] - i*.05);
}
}
Midi Visualisaton
The Clavilux 2000 is an interactive instrument for generative music visualization, which is able to generate a live visualization of any music played on a digital piano. The setting of the installation consists of three parts: A digital piano with 88 keys and midi output, a computer running a vvvv patch and a vertical projection above the keyboard.
For every note played on the keyboard a new visual element appears in form of a stripe, which follows in its dimensions, position and speed the way the particular key was stroke. Colours give the viewer and listener an impression of the harmonic relations: Each key has it’s own color scheme and “wrong” notes stand out in contrasting colors.
CC1 Animationsbeispiel von heute
boolean gehtRechts = true;
boolean gehtUnten = true;
float x = 100;
float y = 100;
float radius = 5;
void setup() {
size(480, 320);
smooth();
background(0);
}
void draw() {
background(0);
ellipse(x, y, radius*2, radius*2);
// größe des fensters: breite = width, höhe = height
if(x >= width - radius) {
gehtRechts = false;
}
if(x < radius) {
gehtRechts = true;
}
if(y >= height - radius) {
gehtUnten = false;
}
if(y < = radius) {
gehtUnten = true;
}
if(gehtRechts == true) {
x = x + mouseX*0.1;
}
else {
x = x - mouseX*0.1;
}
if(gehtUnten == true) {
y = y + mouseY*0.1;
}
else {
y = y - mouseY*0.1;
}
}
Perlin Noise Beispiel

Hier der Code des Noisebeispiels basierend auf Perlin Noise:
void setup() {
size (1024, 768);
background (255);
noStroke ();
fill (0);
smooth();
}
void draw() {
background(255);
for (int x=0; x < 200; x++) {
for (int y=0; y < 200; y++) {
ellipse (x * 5,
y * 5,
noise ((x + mouseX) * 0.05) * 10,
noise ((y + mouseY) * 0.05) * 10
);
}
}
}







