// chua simulation // built by James N. Sears with Processing // import pitaru.sonia_v2_9.*; int magnitude = 2400; float startX = .5f; float startY = .25f; float startZ = .125f; float x = startX; float y = startY; float z = startZ; float lastX = 0; float lastY = 0; float lastZ = 0; float maxX = 0.1f; float maxNegX = -0.1f; float dt = .02f; float startScale = 100.0f; float scale = startScale; float alpha = 15.6f; float k = 1f; float beta = 28.58f; float gamma = 0f; float a = -1.14286f; float b = -0.714286f; int streamSize = 1024; // holds the streamSize value for the liveOutput.data[] array. float[] soundX = new float[streamSize]; // Start the LiveOutput engine with a streamSize of 512 frames, and a streamBuffer twice the size. // Use the LiveOutputEvent(){} to update the LiveOutput.data[] array with Sine wave information. // The Y value of the mouse will determine the Sine wave's frequency. // Draw the current sound data on the stage. public void setup() { size(800,800); background(0); Sonia.start(this,44100); // Start Sonia at a lower sampling-rate for better performance. LiveOutput.start(streamSize,streamSize*16); // Start LiveOutput with a buffer. LiveOutput.startStream(); // Start the liveOutput stream, and activate the liveOutputEvent(){} } public void mousePressed(){ x = startX; y = startY; z = startZ; scale = startScale; maxX = 0.1f; maxNegX = -0.1f; } public void mouseMoved() { beta = 8.58f + mouseY / 10f; alpha = 5.6f + mouseX / 10f; } public void draw() { fill(0,75); rect(0,0,width,height); for(int counter = 0; counter < 1024; counter++) { iterate(); soundX[counter] = x / max(maxX,abs(maxNegX)); if(abs(x*scale) > width/2) { scale = width / (2.5f*x); } if(abs(y*scale) > height/2) { scale = height / (2.5f*y); } stroke(30,255,160,115); fill(50,200,50); strokeWeight(2); line((width/2) + (scale * x),(height/2) + (scale * y),(width/2) + (scale * lastX),(height/2) + (scale * lastY)); //ellipse((width/2) + (scale * x),(height/2) + (scale * y),5,5); } println(x); //println(x); } public void iterate() { lastX = x; lastY = y; lastZ = z; x = lastX + dt * (k * alpha * (lastY - lastX - f())); y = lastY + dt * (k * lastX - lastY + lastZ); z = lastZ + dt * (k * (-beta * lastY - gamma * lastZ)); if(x > maxX) { maxX = x; } if(x < maxNegX) { maxNegX = x; } } public float f() { float retval = 0f; retval = (b * x) + (.5f * (a - b) * (abs(x+1) - abs(x-1))); return retval; } // This event is automatically called when the system requests new data for the stream. void liveOutputEvent(){ // Populate the LiveOutput.data[] data array with a sine-wave. for(int i = 0; i < LiveOutput.data.length; i++){ float oneCycle = TWO_PI/streamSize; int freq = (height - mouseY)/10; float sinData = (freq*2) * oneCycle * i; // LiveOutput.data[i] = sin(sinData); LiveOutput.data[i] = soundX[i]; } } public void stop(){ Sonia.stop(); super.stop(); } /*void loop(){ background(0); stroke(255); // Draw the current sample information in the LiveOutput.data[] stream array. for(int i = 0; i < LiveOutput.data.length-1; i++){ line(i,height/2 - LiveOutput.data[i]*30,i+1,height/2 - LiveOutput.data[i+1]*30); } } */