package com.eschere.usozo; import java.io.File; import java.io.IOException; import org.puredata.android.io.AudioParameters; import org.puredata.android.io.PdAudio; import org.puredata.core.PdBase; import org.puredata.core.utils.IoUtils; import android.util.Log; import processing.core.*; public class Usozo extends PApplet { Blune blune; Background back; Sound sound; private static final int SAMPLE_RATE = 44100; int inactiveThreshold = 300 + (int)random(-100, 100); int inactiveCounter; int randomPointInterval = (int)random(300, 500); float centerX, centerY; float usozoSpeed; boolean mouseInactive, mouseStarted = false; boolean renderText; int backgroundColor = color(100, 100, 120); String patch; public void setup() { noFill(); centerX = random(screenWidth/3, screenWidth/3 + screenWidth/3); centerY = random(screenHeight/3, screenHeight/3 + screenHeight/3); blune = new Blune(10, this); back = new Background(200, 3, 50, this); sound = new Sound(this); } public void draw() { if(!renderText) { usozoSpeed = blune.speed(); background(100 + usozoSpeed * 10, 100 + usozoSpeed * 10, 120 + usozoSpeed * 4); } back.drawBackground("shadow"); back.drawBackground("front"); if(mouseX != 0 && !mouseStarted) mouseStarted = true; mouseCount(); if(frameCount % randomPointInterval == 0 && mouseInactive) { centerX = random(screenWidth); centerY = random(screenHeight); } else if(!mouseInactive && mouseStarted) { centerX = mouseX; centerY = mouseY; } blune.update(centerX, centerY, mouseInactive); sound.sendData(centerX, centerY); } void mouseCount() { if(mouseX == pmouseX && mouseY == pmouseY) { if(inactiveCounter < inactiveThreshold) { inactiveCounter++; } else if(inactiveCounter == inactiveThreshold) { mouseInactive = true; } } else { inactiveCounter = 0; mouseInactive = false; } } static public void main(String args[]) { PApplet.main(new String[] { "Usozo" }); } @Override protected void onResume() { super.onResume(); int nOut = Math.min(AudioParameters.suggestOutputChannels(), 2); try { PdAudio.initAudio(SAMPLE_RATE, 0, nOut, 1, true); PdAudio.startAudio(this); } catch (IOException e) { Log.e(sound.TAG, e.toString()); } } @Override protected void onPause() { PdAudio.stopAudio(); super.onPause(); } @Override public void onDestroy() { sound.cleanup(); super.onDestroy(); } @Override public void finish() { sound.cleanup(); super.finish(); } }