30. November 2011
Mittels eines Beschleunigungssensors (MMA 7455 Accelerometer) soll in Processing eine Figur oder Form erstellt werden, welche auf Gestik reagiert. Bilder 1-5: Werte des Sensors als Liniengrafik in Processing visualisiert. Bilder 6-8: Werte in 3D-Formen umgewandelt. Bilder 9-14: Extrudiertes Matterhorn. Mittels eines Codes der Processing-Library habe ich Bilder in 3D-Werte umgewandelt und konnte diese dann über den Beschleunigungssensor steuern.//Extrude Matterhorn PushMatrix import processing.serial.*; Serial myPort; int xVal, yVal, zVal; int xPosition = 0; float xRotation, yRotation; PImage extrude; int[][] values; float angle = 0; void setup() { background(0); size(800, 800, P3D); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); extrude = loadImage("matterhorn.jpg"); extrude.loadPixels(); values = new int[extrude.width][extrude.height]; for (int y = 0; y < extrude.height; y++) { for (int x = 0; x < extrude.width; x++) { color pixel = extrude.get(x, y); values[x][y] = int(brightness(pixel)); } } } void draw() { background(255); translate(width/2, height/2); pushMatrix(); translate(30,30,30); float xValCorrected = float(xVal)/64; float yValCorrected = float(yVal)/64; float zValCorrected = float(zVal)/64; popMatrix(); // float xRotation = atan((xValCorrected)/(sqrt(sq(yValCorrected)+sq(zValCorrected)))); // float yRotation = atan((yValCorrected)/(sqrt(sq(xValCorrected)+sq(zValCorrected)))); if (zValCorrected>0) { xRotation = radians(map(xVal, -64, 64, 0, 180)); yRotation = radians(map(yVal, -64, 64, 180, 0)); } else { xRotation = radians(map(xVal, -64, 64, 180, 0)); yRotation = radians(map(yVal, -64, 64, 0, 180)); } rotateX(xRotation); rotateY(yRotation); for (int y = 0; y < extrude.height; y++) { for (int x = 0; x < extrude.width; x++) { stroke(values[x][y]); point(x, y, -values[x][y]); } } println(xVal+"\t"+yVal+"\t"+zVal); } void serialEvent(Serial myPort) { if (myPort.available() > 0) { String completeString = myPort.readStringUntil(10); if (completeString != null) { trim(completeString); String seperateValues[] = split(completeString, ","); xVal = int(seperateValues[0]); yVal = int(seperateValues[1]); zVal = int(seperateValues[2]); } } }Passwort Film: MMA7455 (Film ist leider Hochformat...)