Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: C#  |  size: 2.80 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         void Start ()
  2.         {
  3.                 // add light
  4.                 GameObject lightGameObject = new GameObject("The Light");
  5.                 lightGameObject.transform.position = new Vector3(0, 20, 0);
  6.                
  7.                 lightGameObject.AddComponent<Light>();
  8.                 lightGameObject.light.color = Color.white;
  9.                 lightGameObject.light.intensity = 500.0f;
  10.                
  11.                 // setup camera
  12.                 Camera.main.transform.position = new Vector3( 0, 10, -10 );
  13.                 Camera.main.transform.LookAt( new Vector3( 0, 0, 0 ) );
  14.                 //Camera.main.transform.up = new Vector3( 0, 1, 0 ); // y is up, z is depth
  15.                
  16. //              for( int i=0; i < 12; i++ )
  17. //                      shepard[ i ] = new G2a_Shepard( i, transform );
  18.                
  19.                 F1_MicStreamer S = F1_MicStreamer.Singleton;
  20.                
  21.                 // notify streamer to fire our callback when floats in from mic
  22.                 S.floatsInDelegate += new F1_MicStreamer.MicCallbackDelegate( FloatsFromMic );
  23.                
  24.                 GameObject spheres = new GameObject( "Spheres" );
  25.                 spheres.transform.parent = transform;
  26.                
  27.                 ringBuffers = new F4a_RingBuf_1[ numNotes ];
  28.                
  29.                 for( int noteIndex = 0; noteIndex < numNotes; noteIndex++ )
  30.                 {
  31.                         int midiNote = midiNote_lowest + noteIndex;
  32.                        
  33.                         int toneme = ( 120 + midiNote - midiNote_C1 ) % 12;
  34.                        
  35.                         float pow = (float)( midiNote - 69 ) / 12.0f;
  36.                        
  37.                         float freq = freq_A4_Midi69 * Mathf.Pow( 2.0f, pow );
  38.                        
  39.                         //print( "MidiNote: " + midiNote + ", Freq: " + freq + ", pow:" + pow + " " );
  40.                        
  41.                         string sName = "Note_" + noteIndex;
  42.                        
  43.                         ringBuffers[ noteIndex ] = F4a_RingBuf_1.CreateNew( sName, freq, transform );
  44.                        
  45.                         GameObject capsule = GameObject.CreatePrimitive( PrimitiveType.Capsule );
  46.                         {
  47.                                 // C1 is MIDI 24
  48.                                
  49.                                 float rMax = 5.0f, rMin = 1.5f;
  50.                                
  51.                                 float t = (float)noteIndex / (float)( numNotes - 1 );
  52.                                 float _radius = Mathf.Lerp( rMax, rMin, Mathf.Sqrt( t ) );
  53.                                 float _theta = Mathf.PI / 2.0f - 2.0f * Mathf.PI * ( (float)toneme / 12.0f );
  54.                                 float _size = Mathf.Lerp( rMax / 5.0f, rMin / 8.0f, Mathf.Sqrt( t ) );
  55.                                
  56.                                 Vector3 btnCenter = _radius * new Vector3( Mathf.Sin ( _theta ),  0.0f,  Mathf.Cos ( _theta )  );
  57.                                
  58.                                 capsule.transform.parent = spheres.transform;
  59.                                 capsule.transform.position = btnCenter;
  60.                                 capsule.transform.localScale = new Vector3( _size, _size, _size );
  61.                        
  62.                                 int[,] rgb =
  63.                                 {
  64.                                         { 250, 10, 0 },
  65.                                         { 245, 70, 0 },
  66.                                         { 200, 120, 20 },
  67.                                         { 225, 210, 0 },
  68.                                        
  69.                                         { 120, 170, 0 },
  70.                                         { 40, 180, 60 },
  71.                                         { 0, 135, 90 },
  72.                                         { 0, 180, 180 },
  73.                                        
  74.                                         { 45, 80, 205 },
  75.                                         { 130, 25, 200},
  76.                                         { 200, 30, 110 },
  77.                                         { 230, 0, 65 },
  78.                                 };
  79.                                
  80.                                 float _r = (float)rgb[toneme,0] / 255.0f;
  81.                                 float _g = (float)rgb[toneme,1] / 255.0f;
  82.                                 float _b = (float)rgb[toneme,2] / 255.0f;
  83.                                
  84.                                 Color _C = new Color( _r, _g, _b, 1.0f );
  85.                                
  86.                                 capsule.transform.renderer.material.SetColor( "_Color", _C );
  87.                         }material
  88.                         sphere[ noteIndex ] = capsule;
  89.                 }
  90.         }