Monthly Archives: December 2009

Ein Array mit minim?

0
Filed under cc2, sprechstunde

Hallo an alle,

ich bin einiges durchgegangen an Lösungswegen..

Alle Dateien gleichzeitig zu laden ist zwar o.k. das muß aber doch einfacher gehen!

hier mal mein Salat:

—————————————————————————————————————–

// Start import

import ddf.minim.*;

Minim minim;

// beim aktivieren des Array gibt es eine Fehlermeldung Null Pointer Exception
//AudioPlayer track[];

AudioPlayer track21;
AudioPlayer track22;

//… obwohl ich meine 16 loops zusammen habe  wird hier nur ein Teil dargestellt
// Felder 2-1 ist 21 geht bis 2-8- ist feld 28 und dann nochmal 3-1 geht bis 3-8 entspricht 38

AudioPlayer track38;

int loopcount = 10000;

void setup()
{
size(512, 200, P3D);
background(0);
minim = new Minim(this);

/*
// Array-Automatisierung.. durchlauf der einzelnen Files
for (int j = 1; j < 9; j++) {
for (int i = 2; i < 4; i++) {
println(“loop_”+(i*10+j)+”.MP3″);
track[i*10+j] = minim.loadFile(“loop_”+(i*10+j)+”.MP3″, 1024);
}
}
*/

track21 = minim.loadFile(“loop_21.MP3″, 2048);
track22 = minim.loadFile(“loop_22.MP3″, 2048);
track23 = minim.loadFile(“loop_23.MP3″, 2048);
track24 = minim.loadFile(“loop_24.MP3″, 2048);

}

void draw()
{

}

void keyPressed()
{

//  Start aller Dateien hier funktioniert die Automatisierung och nicht
if ( key == ‘#’)
{

for (int j = 1; j < 9; j++) {
for (int i = 2; i < 4; i++) {

String testvar = “track”+(i*10+j);
println(testvar);
testvar.loop(loopcount);
}
}

/*
track21.loop(loopcount);
track22.loop(loopcount);
track23.loop(loopcount);

//… hier nur wieder ein Teil dargestellt

*/

}
}

void stop()

{// die einzelnen Tracks stopen kann ich mir sparen..
minim.stop();
super.stop();
}

————————————————————————————————————————————————–

gerne kann ich alles auch per Mail schicken.. an…?…

oder Ihr könnt euch die 2 Pakete runterladen..

www.evolutionderelemente.de/audio_test.rar

www.evolutionderelemente.de/feld_var3.rar

Vielen Dank für die Mithilfe

Gruß Rases

Collision Detection für Game Levels

1
Filed under cc1, input

Bildschirmfoto 2009-12-18 um 18.25.54

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

0
Filed under cc1, input

Bild 12

// 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

0
Filed under cc2, input, tipps

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.

Link

CC1 Präsentation der Endprojektideen

0
Filed under cc1, organisation

Hallo an alle!

Wie letzte Woche bereits angekündigt finden Freitag die Präsentationen der Ideen für’s Endprojekt statt. Dazu sollte jeder von euch/jede Gruppe eine Beamer-Präsentation vorbereiten, die kurz den bisherigen Stand des Konzeptes anhand visueller Skizzen/Entwürfe vorstellt. Diese können abfotografierte Zeichnungen oder in Illustrator/Photoshop erstellte Entwürfe sein. Wichtig dabei ist: Die Idee sollte so kurz und klar wie möglich kommuniziert werden (2-5 Minuten). Anwesenheit ist Pflicht!

Die Präsentation kann als PDF, JPEGs, Powerpoint oder Keynote angelegt werden. Fragen könnt ihr hier als Kommentar stellen.
Wir freuen uns auf eure Ideen + bis Freitag.