Accelerometer

Accelerometer dragon

import android.hardware.*; Accelerometer accel; PShape dragon; int xStartR, yStartR; int points = 0; void setup() { accel = new Accelerometer(); frameRate(10); dragon = loadShape(“dragon.svg”); } void draw() { // set the background colour based on the 3 accelerometer values int r, g, b; r = (int) (accel.getX() + 10) * (255/20); g = (int) (accel.getY() + 10) * (255/20); b = (int) (accel.getZ() + 10) * (255/20); background(r,g,b); xStartR = (int) (accel.getX()+10)*(width/20); yStartR = (int) (accel.getY()+10)*(height/20); fill(100); noStroke(); //rect(xStartR-75, yStartR-75, 150, 150); shape(dragon,xStartR-75, yStartR-75, 150, 150); // display the accelerometer values on the screen using the text function fill(g,b,r); textSize(60); text(accel.getX(), 100, 100); text(accel.getY(), 100, 175); text(accel.getZ(), 100, 250); text(points, width-40,height-20); } void mousePressed(){ if (xStartR-75<mouseX && xStartR+75>mouseX && yStartR-75<mouseY && yStartR+75>mouseY){ ++points; } } public class Accelerometer implements SensorEventListener { private SensorManager sensorManager; private Sensor accelerometer; private float[] values; public Accelerometer() { sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); values = new float[3]; } public float[] getValues() { return values; } public float getX() { return values[0]; } public float getY() { return values[1]; } public float getZ() { return values[2]; } //SensorEventListener interace public void onSensorChanged(SensorEvent event) { values = event.values; } // SensorEventListener interace public void onAccuracyChanged(Sensor sensor, int accuracy) { } }

The best way to predict the future is to invent it (Alan Kay)