
Untitled
By: a guest on
Aug 11th, 2012 | syntax:
C# | size: 2.80 KB | hits: 17 | expires: Never
void Start ()
{
// add light
GameObject lightGameObject = new GameObject("The Light");
lightGameObject.transform.position = new Vector3(0, 20, 0);
lightGameObject.AddComponent<Light>();
lightGameObject.light.color = Color.white;
lightGameObject.light.intensity = 500.0f;
// setup camera
Camera.main.transform.position = new Vector3( 0, 10, -10 );
Camera.main.transform.LookAt( new Vector3( 0, 0, 0 ) );
//Camera.main.transform.up = new Vector3( 0, 1, 0 ); // y is up, z is depth
// for( int i=0; i < 12; i++ )
// shepard[ i ] = new G2a_Shepard( i, transform );
F1_MicStreamer S = F1_MicStreamer.Singleton;
// notify streamer to fire our callback when floats in from mic
S.floatsInDelegate += new F1_MicStreamer.MicCallbackDelegate( FloatsFromMic );
GameObject spheres = new GameObject( "Spheres" );
spheres.transform.parent = transform;
ringBuffers = new F4a_RingBuf_1[ numNotes ];
for( int noteIndex = 0; noteIndex < numNotes; noteIndex++ )
{
int midiNote = midiNote_lowest + noteIndex;
int toneme = ( 120 + midiNote - midiNote_C1 ) % 12;
float pow = (float)( midiNote - 69 ) / 12.0f;
float freq = freq_A4_Midi69 * Mathf.Pow( 2.0f, pow );
//print( "MidiNote: " + midiNote + ", Freq: " + freq + ", pow:" + pow + " " );
string sName = "Note_" + noteIndex;
ringBuffers[ noteIndex ] = F4a_RingBuf_1.CreateNew( sName, freq, transform );
GameObject capsule = GameObject.CreatePrimitive( PrimitiveType.Capsule );
{
// C1 is MIDI 24
float rMax = 5.0f, rMin = 1.5f;
float t = (float)noteIndex / (float)( numNotes - 1 );
float _radius = Mathf.Lerp( rMax, rMin, Mathf.Sqrt( t ) );
float _theta = Mathf.PI / 2.0f - 2.0f * Mathf.PI * ( (float)toneme / 12.0f );
float _size = Mathf.Lerp( rMax / 5.0f, rMin / 8.0f, Mathf.Sqrt( t ) );
Vector3 btnCenter = _radius * new Vector3( Mathf.Sin ( _theta ), 0.0f, Mathf.Cos ( _theta ) );
capsule.transform.parent = spheres.transform;
capsule.transform.position = btnCenter;
capsule.transform.localScale = new Vector3( _size, _size, _size );
int[,] rgb =
{
{ 250, 10, 0 },
{ 245, 70, 0 },
{ 200, 120, 20 },
{ 225, 210, 0 },
{ 120, 170, 0 },
{ 40, 180, 60 },
{ 0, 135, 90 },
{ 0, 180, 180 },
{ 45, 80, 205 },
{ 130, 25, 200},
{ 200, 30, 110 },
{ 230, 0, 65 },
};
float _r = (float)rgb[toneme,0] / 255.0f;
float _g = (float)rgb[toneme,1] / 255.0f;
float _b = (float)rgb[toneme,2] / 255.0f;
Color _C = new Color( _r, _g, _b, 1.0f );
capsule.transform.renderer.material.SetColor( "_Color", _C );
}material
sphere[ noteIndex ] = capsule;
}
}