※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : keim_at_Si's [diff(162)]

FORKED
  1. // forked from keim_at_Si's ((♪))
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     import flash.geom.*;
  9.     
  10.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  11.     public class main extends Sprite {
  12.         private var module:TinySiOPM=new TinySiOPM(), sound:Sound=new Sound(), channel:SoundChannel;
  13.         private var bshc:Array = ["80642053042","0006001","31221110110"];
  14.         private var tone:Array = [[72,4,0,20,-4],  [500,4,3,2,0],      [0,2,3,3,0]];
  15.         private var auto:Array = [0x501,0x1101,0x1211,0x16d1,0x1252,0x6609,0xc514,0x6a01,0xd414,0xa4a4,0xa444,0x5249];
  16.         private var pong:Array = [57,60,62,64,67,69];
  17.         private var screen:Bitmap = new Bitmap(new BitmapData(465465true0));
  18.         private var balls:Array = [];
  19.         private var pointer:int, frame:int, frameCounter:int, note:int, bound:int, autoNum:int, wave:int, beat:int;
  20.         private var shadow:DropShadowFilter = new DropShadowFilter(8,45,0,0.5,6,6);
  21.         private var shape:Shape=new Shape(), mat:Matrix=new Matrix(), pos:Number, scl:Number;
  22.         private var apButton:SimpleButton, tfNormal:TextField;
  23.         public function main() {
  24.             function tf(t:String, c:uint=0x808080, x:int=0, y:int=0) : TextField {
  25.                 var tf:TextField=new TextField(); tf.htmlText=t; tf.textColor=c; tf.height=24; tf.x=x; tf.y=y; return tf;
  26.             }
  27.             function sb(t:String, f:Function, x:int, y:int) : SimpleButton {
  28.                 var over:TextField = tf("<u><b>"+t+"</b></u>", 0xf08080);
  29.                 var button:SimpleButton = new SimpleButton(tf("<u>"+t+"</u>"), over, over, over); button.x=x; button.y=y;
  30.                 button.addEventListener("mouseDown", f); return button;
  31.             }
  32.             sound.addEventListener('sampleData', _onStream);
  33.             stage.addEventListener("enterFrame", _onEnterFrame);
  34.             stage.addEventListener("mouseDown",  function(e:Event):void{ note=1; _switchAutoPlay(false); });
  35.             tfNormal=tf("クリックでえんそう",0x808080, 18016);
  36.             apButton=sb("ぜんじどうえんそう",function(e:Event):void{_switchAutoPlay(true);e.stopPropagation();},180,16);
  37.             addChild(apButton); apButton.visible = false;
  38.             addChild(tfNormal);
  39.             addChild(sb("おとかえる",function(e:Event):void{if(++wave==12)wave=0; e.stopPropagation();}, 32,  16));
  40.             addChild(sb("はやくする",function(e:Event):void{if(--frame==1)frame=5;e.stopPropagation();}, 38016));
  41.             addChild(screen);
  42.             pointer=0; frame=3; frameCounter=0; note=0; bound=0; autoNum=1; wave=2; pos=500; scl=1; beat=0;
  43.             shape.graphics.lineStyle(300.5);
  44.             shape.graphics.drawPath(Vector.<int>([1,2,1,2,1,2,1,2,1,2,1,2]), 
  45.                 Vector.<Number>([-500,-40,500,-40,-500,-20,500,-20,-500,0,500,0,-500,20,500,20,-500,40,500,40,0,-40,0,40]));
  46.             ball.createShape();
  47.             channel = sound.play();
  48.         }
  49.         private function _onEnterFrame(event:Event) : void {
  50.             var bd:BitmapData = screen.bitmapData;
  51.             if (note > 1) {
  52.                 var x:int = (autoNum) ? Math.random()*200+132 : mouseX,
  53.                     y:int = (autoNum) ? Math.random()*100+132 : mouseY;
  54.                 balls.push(new ball(x, y, note-2function(p:int, v:Number):void
  55.                     var iv:int = int(v*48);
  56.                     if ((bound & 63) < iv) bound = (p<<6) | iv;
  57.                 }));
  58.                 note = 0;
  59.             }
  60.             scl+=(1-scl)*0.5; pos-=6-frame; if (pos<0) pos+=500;
  61.             mat.identity(); mat.scale(scl,scl); mat.translate(pos, 160);
  62.             bd.fillRect(bd.rect, 0x00ffffff);
  63.             bd.draw(shape, mat);
  64.             balls = balls.filter(function(b:*,i:int,a:Array):Boolean { return b.render(bd); });
  65.             bd.applyFilter(bd, bd.rect, bd.rect.topLeft, shadow);
  66.         }
  67.         private function _onStream(e:SampleDataEvent) : void {
  68.             if (++frameCounter >= frame) {
  69.                 for (var i:int=0; i<3; i++) {
  70.                     var v:int = parseInt(bshc[i].charAt(pointer), 16);
  71.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  72.                 }
  73.                 if (autoNum) {
  74.                     if ((auto[autoNum-1]>>pointer) & 1) note = 1;
  75.                     if (pointer == 15) autoNum = int(Math.random()*12)+1;
  76.                 }
  77.                 if (note == 1) { 
  78.                     var p:int = int(Math.random()*6);
  79.                     module.noteOn((pong[p]+(beat>>7))<<4,64,wave,8);
  80.                     note = p+2;
  81.                 }
  82.                 if (bound > 0) {
  83.                     module.noteOn((pong[bound>>6]+(beat>>7))<<4,bound&63,wave,8);
  84.                     bound = 0;
  85.                 }
  86.                 pointer = (pointer + 1) & 15;
  87.                 if ((pointer & 3)==2) { scl=1.4; beat++; }
  88.                 frameCounter = 0;
  89.             }
  90.             module.buffer(e.data);
  91.         }
  92.         private function _switchAutoPlay(ap:Boolean) : void {
  93.             if (ap == Boolean(autoNum)) return;
  94.             if (ap) { apButton.visible=false; tfNormal.visible=true;  autoNum=1; } 
  95.             else    { apButton.visible=true;  tfNormal.visible=false; autoNum=0; } 
  96.         }
  97.     }
  98. }
  99. import flash.events.*;
  100. import flash.display.*;
  101. import flash.geom.*;
  102. class ball {
  103.     static private var color:Vector.<uint> = Vector.<uint>([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0,0xe040e0]);
  104.     static private var _s:Shape = new Shape(), _m:Matrix = new Matrix(), _c:ColorTransform = new ColorTransform();
  105.     private var p:Point, v:Point, alpha:Number, pitch:int, bound:Function, bounded:Boolean, len:Number, dlen:Number;
  106.     function ball(x:int, y:int, pit:int, f:Function) {
  107.         p=new Point(x, y); v=new Point(Math.random()*8-4-(x-232)*0.016, Math.random()*-6-6);
  108.         alpha=1; pitch=pit; bound=f; bounded=true; len=Math.random()*0.2+0.6; dlen=0;
  109.     }
  110.     public function render(bd:BitmapData) : Boolean {
  111.         p.x+=v.x; p.y+=v.y; v.y+=1; alpha-=0.0078125; len+=dlen; dlen+=(1-len)*0.3-dlen*0.1
  112.         if (v.y>0 && bounded && p.y+v.y*8>400) { bound(pitch, alpha); bounded=false; }
  113.         else if (p.y>450) { p.y=900-p.y; v.y=-v.y*0.7; bounded=true; len=0.7; }
  114.         if (p.x<0 || p.x>495 || alpha<0.01return false;
  115.         _m.identity(); _m.scale(1, len); _m.translate(p.x, p.y);
  116.         _c.alphaMultiplier = alpha;
  117.         _c.redOffset = color[pitch] >> 16;
  118.         _c.greenOffset = (color[pitch] >> 8) & 255;
  119.         _c.blueOffset = color[pitch] & 255;
  120.         bd.draw(_s, _m, _c);
  121.         return true;
  122.     }
  123.     static public function createShape() : void {
  124.         _s.graphics.clear();
  125.         _s.graphics.lineStyle(30);
  126.         _s.graphics.beginFill(0);
  127.         _s.graphics.drawCircle(0010);
  128.         _s.graphics.endFill();
  129.         _s.graphics.drawPath(Vector.<int>([1,2,2,2,2,2]),Vector.<Number>([10,0,10,-50,15,-38,20,-32,20,-25,17,-17]));
  130.     }
  131. }
  132. import flash.utils.ByteArray;
  133. class TinySiOPM {
  134.     private var _t:Note, _o:Vector.<Number>, _s:int;
  135.     private var _p:Vector.<int> = new Vector.<int>(2048true);         // pitchTable[128*16]
  136.     private var _l:Vector.<Number> = new Vector.<Number>(6144true);   // logTable[12*256*2]
  137.     function TinySiOPM(bufferSize:int=2048) {
  138.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  139.         for (i=0, p=0; i<192; i++, p+=0.00520833333)                    // pitch table
  140.             for(v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192) _p[j] = int(v);
  141.         for (i=0; i<32; i++) _p[i] = (i+1)<<6;                          // pitch=0-31 for white noize
  142.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125)               // log table
  143.             for(v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256) _l[j+1] = -(_l[j] = v);
  144.         for (i=3328; i<6144; i++) _l[i] = 0;
  145.         var famtri:Array = [0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8,-8,-7,-6,-5,-4,-3,-2,-1];
  146.         for (t=Note.table(10), i=0, p=0; i<1024; i++, p+=0.00613592315) t[i] = _log(Math.sin(p)); // sin=0
  147.         for (t=Note.table(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) t[i] = _log(p);        // saw=1
  148.         for (t=Note.table(5),  i=0; i<32; i++) t[i] = _log(famtri[i]*0.0625);                     // famtri=2
  149.         for (t=Note.table(15), i=0; i<32768; i++) t[i] = _log(Math.random()-0.5);                 // wnoize=3
  150.         for (i=0; i<8; i++) for (t=Note.table(4), j=0; j<16; j++) t[j] = (j<=i) ? 192 : 193;      // pulse=4-11
  151.         _s=bufferSize; _t=new Note(); _o=new Vector.<Number>(_s, true); for(i=0; i<_s; i++) _o[i]=0;
  152.     }
  153.     private function _log(n:Number) : int {
  154.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  155.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  156.     }
  157.     public function buffer(data:ByteArray) : void {
  158.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  159.         for (imax=1024; imax<=_s; imax+=1024for (n=_t.next; n!=_t; n=n.step())
  160.                 for (dph=_p[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++)
  161.                     { lout=n.wave[n.ph>>n.shift]+n.gain; _o[i]+=_l[lout]; }
  162.         for (i=0; i<_s; i++) { data.writeFloat(_o[i]); data.writeFloat(_o[i]); _o[i]=0; }
  163.     }
  164.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : Note { 
  165.         return Note.alloc().reset(pitch, _log(velocity*0.0078125), tone, (decay<<2), sweep).into(_t); 
  166.     }
  167. }
  168. class Note {
  169.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, wave:Vector.<int>, shift:int
  170.     static private var _w:Array=[], _s:Array=[], _fl:Note = new Note();
  171.     function Note() { prev = next = this; }
  172.     public function free() : Note { var r:Note=prev; r.next=next; next.prev=r; into(_fl); return r; }
  173.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  174.     public function step() : Note { gain+=decay; pitch+=sweep; pitch&=2047return (gain>3328)?(free().next):next; }
  175.     public function reset(p:int, g:int, t:int, d:int, s:int) : Note 
  176.     { ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; wave=_w[t]; shift=_s[t]; return this; }
  177.     static public function table(b:int) : Vector.<int>
  178.     { var t:Vector.<int>=new Vector.<int>(1<<b, true); _w.push(t); _s.push(26-b); return t; }
  179.     static public function alloc() : Note 
  180.     { if (_fl.prev==_fl) { return new Note(); } var r:Note=_fl.prev; _fl.prev=r.prev; _fl.prev.next=_fl; return r; }
  181. }
noswf
  1. // forked from keim_at_Si's ((♪))
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     import flash.geom.*;
  9.     
  10.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  11.     public class main extends Sprite {
  12.         private var module:TinySiOPM=new TinySiOPM(), sound:Sound=new Sound(), channel:SoundChannel;
  13.         private var bshc:Array = ["8060004205300042","0000620000006001","3121001121110110"];
  14.         private var tone:Array = [[672,4,0,20,-48],  [4,4,3,24,0],      [31,2,3,36,0]];
  15.         private var auto:Array = [0x5001,0x1101,0x1211,0x16d1,0x1252,0x6609,0xc514,0x6a01,0xd414,0xa4a4,0xa444,0x5249];
  16.         private var pong:Array = [57,60,62,64,67,69];
  17.         private var screen:Bitmap = new Bitmap(new BitmapData(465465true0));
  18.         private var balls:Array = [];
  19.         private var pointer:int, frame:int, frameCounter:int, note:int, bound:int, autoNum:int, wave:int, beat:int;
  20.         private var shadow:DropShadowFilter = new DropShadowFilter(8,45,0,0.5,6,6);
  21.         private var shape:Shape=new Shape(), mat:Matrix=new Matrix(), pos:Number, scl:Number;
  22.         private var apButton:SimpleButton, tfNormal:TextField;
  23.         public function main() {
  24.             function tf(t:String, c:uint=0x808080, x:int=0, y:int=0) : TextField {
  25.                 var tf:TextField=new TextField(); tf.htmlText=t; tf.textColor=c; tf.height=24; tf.x=x; tf.y=y; return tf;
  26.             }
  27.             function sb(t:String, f:Function, x:int, y:int) : SimpleButton {
  28.                 var over:TextField = tf("<u><b>"+t+"</b></u>", 0xf08080);
  29.                 var button:SimpleButton = new SimpleButton(tf("<u>"+t+"</u>"), over, over, over); button.x=x; button.y=y;
  30.                 button.addEventListener("mouseDown", f); return button;
  31.             }
  32.             sound.addEventListener('sampleData', _onStream);
  33.             stage.addEventListener("enterFrame", _onEnterFrame);
  34.             stage.addEventListener("mouseDown",  function(e:Event):void{ note=1; _switchAutoPlay(false); });
  35.             tfNormal=tf("切换二",0x808080, 18016);
  36.             apButton=sb("点击切换",function(e:Event):void{_switchAutoPlay(true);e.stopPropagation();},180,16);
  37.             addChild(apButton); apButton.visible = false;
  38.             addChild(tfNormal);
  39.             addChild(sb("切换",function(e:Event):void{if(++wave==12)wave=0; e.stopPropagation();}, 32,  16));
  40.             addChild(sb("切换",function(e:Event):void{if(--frame==1)frame=5;e.stopPropagation();}, 38016));
  41.             addChild(screen);
  42.             pointer=0; frame=3; frameCounter=0; note=0; bound=0; autoNum=1; wave=2; pos=500; scl=1; beat=0;
  43.             shape.graphics.lineStyle(300.5);
  44.             shape.graphics.drawPath(Vector.<int>([1,2,1,2,1,2,1,2,1,2,1,2]), 
  45.                 Vector.<Number>([-500,-40,500,-40,-500,-20,500,-20,-500,0,500,0,-500,20,500,20,-500,40,500,40,0,-40,0,40]));
  46.             ball.createShape();
  47.             channel = sound.play();
  48.         }
  49.         private function _onEnterFrame(event:Event) : void {
  50.             var bd:BitmapData = screen.bitmapData;
  51.             if (note > 1) {
  52.                 var x:int = (autoNum) ? Math.random()*200+132 : mouseX,
  53.                     y:int = (autoNum) ? Math.random()*100+132 : mouseY;
  54.                 balls.push(new ball(x, y, note-2function(p:int, v:Number):void
  55.                     var iv:int = int(v*48);
  56.                     if ((bound & 63) < iv) bound = (p<<6) | iv;
  57.                 }));
  58.                 note = 0;
  59.             }
  60.             scl+=(1-scl)*0.5; pos-=6-frame; if (pos<0) pos+=500;
  61.             mat.identity(); mat.scale(scl,scl); mat.translate(pos, 160);
  62.             bd.fillRect(bd.rect, 0x00ffffff);
  63.             bd.draw(shape, mat);
  64.             balls = balls.filter(function(b:*,i:int,a:Array):Boolean { return b.render(bd); });
  65.             bd.applyFilter(bd, bd.rect, bd.rect.topLeft, shadow);
  66.         }
  67.         private function _onStream(e:SampleDataEvent) : void {
  68.             if (++frameCounter >= frame) {
  69.                 for (var i:int=0; i<3; i++) {
  70.                     var v:int = parseInt(bshc[i].charAt(pointer), 16);
  71.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  72.                 }
  73.                 if (autoNum) {
  74.                     if ((auto[autoNum-1]>>pointer) & 1) note = 1;
  75.                     if (pointer == 15) autoNum = int(Math.random()*12)+1;
  76.                 }
  77.                 if (note == 1) { 
  78.                     var p:int = int(Math.random()*6);
  79.                     module.noteOn((pong[p]+(beat>>7))<<4,64,wave,8);
  80.                     note = p+2;
  81.                 }
  82.                 if (bound > 0) {
  83.                     module.noteOn((pong[bound>>6]+(beat>>7))<<4,bound&63,wave,8);
  84.                     bound = 0;
  85.                 }
  86.                 pointer = (pointer + 1) & 15;
  87.                 if ((pointer & 3)==2) { scl=1.4; beat++; }
  88.                 frameCounter = 0;
  89.             }
  90.             module.buffer(e.data);
  91.         }
  92.         private function _switchAutoPlay(ap:Boolean) : void {
  93.             if (ap == Boolean(autoNum)) return;
  94.             if (ap) { apButton.visible=false; tfNormal.visible=true;  autoNum=1; } 
  95.             else    { apButton.visible=true;  tfNormal.visible=false; autoNum=0; } 
  96.         }
  97.     }
  98. }
  99. import flash.events.*;
  100. import flash.display.*;
  101. import flash.geom.*;
  102. class ball {
  103.     static private var color:Vector.<uint> = Vector.<uint>([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0,0xe040e0]);
  104.     static private var _s:Shape = new Shape(), _m:Matrix = new Matrix(), _c:ColorTransform = new ColorTransform();
  105.     private var p:Point, v:Point, alpha:Number, pitch:int, bound:Function, bounded:Boolean, len:Number, dlen:Number;
  106.     function ball(x:int, y:int, pit:int, f:Function) {
  107.         p=new Point(x, y); v=new Point(Math.random()*8-4-(x-232)*0.016, Math.random()*-6-6);
  108.         alpha=1; pitch=pit; bound=f; bounded=true; len=Math.random()*0.2+0.6; dlen=0;
  109.     }
  110.     public function render(bd:BitmapData) : Boolean {
  111.         p.x+=v.x; p.y+=v.y; v.y+=1; alpha-=0.0078125; len+=dlen; dlen+=(1-len)*0.3-dlen*0.1
  112.         if (v.y>0 && bounded && p.y+v.y*8>400) { bound(pitch, alpha); bounded=false; }
  113.         else if (p.y>450) { p.y=900-p.y; v.y=-v.y*0.7; bounded=true; len=0.7; }
  114.         if (p.x<0 || p.x>495 || alpha<0.01return false;
  115.         _m.identity(); _m.scale(1, len); _m.translate(p.x, p.y);
  116.         _c.alphaMultiplier = alpha;
  117.         _c.redOffset = color[pitch] >> 16;
  118.         _c.greenOffset = (color[pitch] >> 8) & 255;
  119.         _c.blueOffset = color[pitch] & 255;
  120.         bd.draw(_s, _m, _c);
  121.         return true;
  122.     }
  123.     static public function createShape() : void {
  124.         _s.graphics.clear();
  125.         _s.graphics.lineStyle(30);
  126.         _s.graphics.beginFill(0);
  127.         _s.graphics.drawCircle(0010);
  128.         _s.graphics.endFill();
  129.         _s.graphics.drawPath(Vector.<int>([1,2,2,2,2,2]),Vector.<Number>([10,0,10,-50,15,-38,20,-32,20,-25,17,-17]));
  130.     }
  131. }
  132. import flash.utils.ByteArray;
  133. class TinySiOPM {
  134.     private var _t:Note, _o:Vector.<Number>, _s:int;
  135.     private var _p:Vector.<int> = new Vector.<int>(2048true);         // pitchTable[128*16]
  136.     private var _l:Vector.<Number> = new Vector.<Number>(6144true);   // logTable[12*256*2]
  137.     function TinySiOPM(bufferSize:int=2048) {
  138.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  139.         for (i=0, p=0; i<192; i++, p+=0.00520833333)                    // pitch table
  140.             for(v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192) _p[j] = int(v);
  141.         for (i=0; i<32; i++) _p[i] = (i+1)<<6;                          // pitch=0-31 for white noize
  142.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125)               // log table
  143.             for(v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256) _l[j+1] = -(_l[j] = v);
  144.         for (i=3328; i<6144; i++) _l[i] = 0;
  145.         var famtri:Array = [0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8,-8,-7,-6,-5,-4,-3,-2,-1];
  146.         for (t=Note.table(10), i=0, p=0; i<1024; i++, p+=0.00613592315) t[i] = _log(Math.sin(p)); // sin=0
  147.         for (t=Note.table(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) t[i] = _log(p);        // saw=1
  148.         for (t=Note.table(5),  i=0; i<32; i++) t[i] = _log(famtri[i]*0.0625);                     // famtri=2
  149.         for (t=Note.table(15), i=0; i<32768; i++) t[i] = _log(Math.random()-0.5);                 // wnoize=3
  150.         for (i=0; i<8; i++) for (t=Note.table(4), j=0; j<16; j++) t[j] = (j<=i) ? 192 : 193;      // pulse=4-11
  151.         _s=bufferSize; _t=new Note(); _o=new Vector.<Number>(_s, true); for(i=0; i<_s; i++) _o[i]=0;
  152.     }
  153.     private function _log(n:Number) : int {
  154.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  155.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  156.     }
  157.     public function buffer(data:ByteArray) : void {
  158.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  159.         for (imax=1024; imax<=_s; imax+=1024for (n=_t.next; n!=_t; n=n.step())
  160.                 for (dph=_p[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++)
  161.                     { lout=n.wave[n.ph>>n.shift]+n.gain; _o[i]+=_l[lout]; }
  162.         for (i=0; i<_s; i++) { data.writeFloat(_o[i]); data.writeFloat(_o[i]); _o[i]=0; }
  163.     }
  164.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : Note { 
  165.         return Note.alloc().reset(pitch, _log(velocity*0.0078125), tone, (decay<<2), sweep).into(_t); 
  166.     }
  167. }
  168. class Note {
  169.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, wave:Vector.<int>, shift:int
  170.     static private var _w:Array=[], _s:Array=[], _fl:Note = new Note();
  171.     function Note() { prev = next = this; }
  172.     public function free() : Note { var r:Note=prev; r.next=next; next.prev=r; into(_fl); return r; }
  173.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  174.     public function step() : Note { gain+=decay; pitch+=sweep; pitch&=2047return (gain>3328)?(free().next):next; }
  175.     public function reset(p:int, g:int, t:int, d:int, s:int) : Note 
  176.     { ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; wave=_w[t]; shift=_s[t]; return this; }
  177.     static public function table(b:int) : Vector.<int>
  178.     { var t:Vector.<int>=new Vector.<int>(1<<b, true); _w.push(t); _s.push(26-b); return t; }
  179.     static public function alloc() : Note 
  180.     { if (_fl.prev==_fl) { return new Note(); } var r:Note=_fl.prev; _fl.prev=r.prev; _fl.prev.next=_fl; return r; }
  181. }
noswf
  1. // forked from keim_at_Si's ((♪))
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     import flash.geom.*;
  9.     
  10.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  11.     public class main extends Sprite {
  12.         private var module:TinySiOPM=new TinySiOPM(), sound:Sound=new Sound(), channel:SoundChannel;
  13.         private var bshc:Array = ["8060004205300042","0000620000006001","3121001121110110"];
  14.         private var tone:Array = [[672,4,0,20,-48],  [4,4,3,24,0],      [31,2,3,36,0]];
  15.         private var auto:Array = [0x5001,0x1101,0x1211,0x16d1,0x1252,0x6609,0xc514,0x6a01,0xd414,0xa4a4,0xa444,0x5249];
  16.         private var pong:Array = [57,60,62,64,67,69];
  17.         private var screen:Bitmap = new Bitmap(new BitmapData(465465true0));
  18.         private var balls:Array = [];
  19.         private var pointer:int, frame:int, frameCounter:int, note:int, bound:int, autoNum:int, wave:int, beat:int;
  20.         private var shadow:DropShadowFilter = new DropShadowFilter(8,45,0,0.5,6,6);
  21.         private var shape:Shape=new Shape(), mat:Matrix=new Matrix(), pos:Number, scl:Number;
  22.         private var apButton:SimpleButton, tfNormal:TextField;
  23.         public function main() {
  24.             function tf(t:String, c:uint=0x808080, x:int=0, y:int=0) : TextField {
  25.                 var tf:TextField=new TextField(); tf.htmlText=t; tf.textColor=c; tf.height=24; tf.x=x; tf.y=y; return tf;
  26.             }
  27.             function sb(t:String, f:Function, x:int, y:int) : SimpleButton {
  28.                 var over:TextField = tf("<u><b>"+t+"</b></u>", 0xf08080);
  29.                 var button:SimpleButton = new SimpleButton(tf("<u>"+t+"</u>"), over, over, over); button.x=x; button.y=y;
  30.                 button.addEventListener("mouseDown", f); return button;
  31.             }
  32.             sound.addEventListener('sampleData', _onStream);
  33.             stage.addEventListener("enterFrame", _onEnterFrame);
  34.             stage.addEventListener("mouseDown",  function(e:Event):void{ note=1; _switchAutoPlay(false); });
  35.             tfNormal=tf("クリックでえんそう",0x808080, 18016);
  36.             apButton=sb("ぜんじどうえんそう",function(e:Event):void{_switchAutoPlay(true);e.stopPropagation();},180,16);
  37.             addChild(apButton); apButton.visible = false;
  38.             addChild(tfNormal);
  39.             addChild(sb("おとかえる",function(e:Event):void{if(++wave==12)wave=0; e.stopPropagation();}, 32,  16));
  40.             addChild(sb("はやくする",function(e:Event):void{if(--frame==1)frame=5;e.stopPropagation();}, 38016));
  41.             addChild(screen);
  42.             pointer=0; frame=3; frameCounter=0; note=0; bound=0; autoNum=1; wave=2; pos=500; scl=1; beat=0;
  43.             shape.graphics.lineStyle(300.5);
  44.             shape.graphics.drawPath(Vector.<int>([1,2,1,2,1,2,1,2,1,2,1,2]), 
  45.                 Vector.<Number>([-500,-40,500,-40,-500,-20,500,-20,-500,0,500,0,-500,20,500,20,-500,40,500,40,0,-40,0,40]));
  46.             ball.createShape();
  47.             channel = sound.play();
  48.         }
  49.         private function _onEnterFrame(event:Event) : void {
  50.             var bd:BitmapData = screen.bitmapData;
  51.             if (note > 1) {
  52.                 var x:int = (autoNum) ? Math.random()*200+132 : mouseX,
  53.                     y:int = (autoNum) ? Math.random()*100+132 : mouseY;
  54.                 balls.push(new ball(x, y, note-2function(p:int, v:Number):void
  55.                     var iv:int = int(v*48);
  56.                     if ((bound & 63) < iv) bound = (p<<6) | iv;
  57.                 }));
  58.                 note = 0;
  59.             }
  60.             scl+=(1-scl)*0.5; pos-=6-frame; if (pos<0) pos+=500;
  61.             mat.identity(); mat.scale(scl,scl); mat.translate(pos, 160);
  62.             bd.fillRect(bd.rect, 0x00ffffff);
  63.             bd.draw(shape, mat);
  64.             balls = balls.filter(function(b:*,i:int,a:Array):Boolean { return b.render(bd); });
  65.             bd.applyFilter(bd, bd.rect, bd.rect.topLeft, shadow);
  66.         }
  67.         private function _onStream(e:SampleDataEvent) : void {
  68.             if (++frameCounter >= frame) {
  69.                 for (var i:int=0; i<3; i++) {
  70.                     var v:int = parseInt(bshc[i].charAt(pointer), 16);
  71.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  72.                 }
  73.                 if (autoNum) {
  74.                     if ((auto[autoNum-1]>>pointer) & 1) note = 1;
  75.                     if (pointer == 15) autoNum = int(Math.random()*12)+1;
  76.                 }
  77.                 if (note == 1) { 
  78.                     var p:int = int(Math.random()*6);
  79.                     module.noteOn((pong[p]+(beat>>7))<<4,23,wave,8);
  80.                     note = p+2;
  81.                 }
  82.                 if (bound > 0) {
  83.                     module.noteOn((pong[bound>>6]+(beat>>7))<<4,bound&63,wave,8);
  84.                     bound = 0;
  85.                 }
  86.                 pointer = (pointer + 1) & 15;
  87.                 if ((pointer & 3)==2) { scl=1.4; beat++; }
  88.                 frameCounter = 0;
  89.             }
  90.             module.buffer(e.data);
  91.         }
  92.         private function _switchAutoPlay(ap:Boolean) : void {
  93.             if (ap == Boolean(autoNum)) return;
  94.             if (ap) { apButton.visible=false; tfNormal.visible=true;  autoNum=1; } 
  95.             else    { apButton.visible=true;  tfNormal.visible=false; autoNum=0; } 
  96.         }
  97.     }
  98. }
  99. import flash.events.*;
  100. import flash.display.*;
  101. import flash.geom.*;
  102. class ball {
  103.     static private var color:Vector.<uint> = Vector.<uint>([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0,0xe040e0]);
  104.     static private var _s:Shape = new Shape(), _m:Matrix = new Matrix(), _c:ColorTransform = new ColorTransform();
  105.     private var p:Point, v:Point, alpha:Number, pitch:int, bound:Function, bounded:Boolean, len:Number, dlen:Number;
  106.     function ball(x:int, y:int, pit:int, f:Function) {
  107.         p=new Point(x, y); v=new Point(Math.random()*8-4-(x-232)*0.016, Math.random()*-6-6);
  108.         alpha=1; pitch=pit; bound=f; bounded=true; len=Math.random()*0.2+0.6; dlen=0;
  109.     }
  110.     public function render(bd:BitmapData) : Boolean {
  111.         p.x+=v.x; p.y+=v.y; v.y+=1; alpha-=0.0078125; len+=dlen; dlen+=(1-len)*0.3-dlen*0.1
  112.         if (v.y>0 && bounded && p.y+v.y*8>400) { bound(pitch, alpha); bounded=false; }
  113.         else if (p.y>450) { p.y=900-p.y; v.y=-v.y*0.7; bounded=true; len=0.7; }
  114.         if (p.x<0 || p.x>495 || alpha<0.01return false;
  115.         _m.identity(); _m.scale(1, len); _m.translate(p.x, p.y);
  116.         _c.alphaMultiplier = alpha;
  117.         _c.redOffset = color[pitch] >> 16;
  118.         _c.greenOffset = (color[pitch] >> 8) & 255;
  119.         _c.blueOffset = color[pitch] & 255;
  120.         bd.draw(_s, _m, _c);
  121.         return true;
  122.     }
  123.     static public function createShape() : void {
  124.         _s.graphics.clear();
  125.         _s.graphics.lineStyle(30);
  126.         _s.graphics.beginFill(0);
  127.         _s.graphics.drawCircle(0010);
  128.         _s.graphics.endFill();
  129.         _s.graphics.drawPath(Vector.<int>([1,2,2,2,2,2]),Vector.<Number>([10,0,10,-50,15,-38,20,-32,20,-25,17,-17]));
  130.     }
  131. }
  132. import flash.utils.ByteArray;
  133. class TinySiOPM {
  134.     private var _t:Note, _o:Vector.<Number>, _s:int;
  135.     private var _p:Vector.<int> = new Vector.<int>(2048true);         // pitchTable[128*16]
  136.     private var _l:Vector.<Number> = new Vector.<Number>(6144true);   // logTable[12*256*2]
  137.     function TinySiOPM(bufferSize:int=2048) {
  138.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  139.         for (i=0, p=0; i<192; i++, p+=0.00520833333)                    // pitch table
  140.             for(v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192) _p[j] = int(v);
  141.         for (i=0; i<32; i++) _p[i] = (i+1)<<6;                          // pitch=0-31 for white noize
  142.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125)               // log table
  143.             for(v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256) _l[j+1] = -(_l[j] = v);
  144.         for (i=3328; i<6144; i++) _l[i] = 0;
  145.         var famtri:Array = [0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8,-8,-7,-6,-5,-4,-3,-2,-1];
  146.         for (t=Note.table(10), i=0, p=0; i<1024; i++, p+=0.00613592315) t[i] = _log(Math.sin(p)); // sin=0
  147.         for (t=Note.table(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) t[i] = _log(p);        // saw=1
  148.         for (t=Note.table(5),  i=0; i<32; i++) t[i] = _log(famtri[i]*0.0625);                     // famtri=2
  149.         for (t=Note.table(15), i=0; i<32768; i++) t[i] = _log(Math.random()-0.5);                 // wnoize=3
  150.         for (i=0; i<8; i++) for (t=Note.table(4), j=0; j<16; j++) t[j] = (j<=i) ? 192 : 193;      // pulse=4-11
  151.         _s=bufferSize; _t=new Note(); _o=new Vector.<Number>(_s, true); for(i=0; i<_s; i++) _o[i]=0;
  152.     }
  153.     private function _log(n:Number) : int {
  154.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  155.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  156.     }
  157.     public function buffer(data:ByteArray) : void {
  158.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  159.         for (imax=1024; imax<=_s; imax+=1024for (n=_t.next; n!=_t; n=n.step())
  160.                 for (dph=_p[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++)
  161.                     { lout=n.wave[n.ph>>n.shift]+n.gain; _o[i]+=_l[lout]; }
  162.         for (i=0; i<_s; i++) { data.writeFloat(_o[i]); data.writeFloat(_o[i]); _o[i]=0; }
  163.     }
  164.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : Note { 
  165.         return Note.alloc().reset(pitch, _log(velocity*0.0078125), tone, (decay<<2), sweep).into(_t); 
  166.     }
  167. }
  168. class Note {
  169.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, wave:Vector.<int>, shift:int
  170.     static private var _w:Array=[], _s:Array=[], _fl:Note = new Note();
  171.     function Note() { prev = next = this; }
  172.     public function free() : Note { var r:Note=prev; r.next=next; next.prev=r; into(_fl); return r; }
  173.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  174.     public function step() : Note { gain+=decay; pitch+=sweep; pitch&=2047return (gain>3328)?(free().next):next; }
  175.     public function reset(p:int, g:int, t:int, d:int, s:int) : Note 
  176.     { ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; wave=_w[t]; shift=_s[t]; return this; }
  177.     static public function table(b:int) : Vector.<int>
  178.     { var t:Vector.<int>=new Vector.<int>(1<<b, true); _w.push(t); _s.push(26-b); return t; }
  179.     static public function alloc() : Note 
  180.     { if (_fl.prev==_fl) { return new Note(); } var r:Note=_fl.prev; _fl.prev=r.prev; _fl.prev.next=_fl; return r; }
  181. }
noswf
  1. // forked from keim_at_Si's ((♪))
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     import flash.geom.*;
  9.     
  10.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  11.     public class main extends Sprite {
  12.         private var module:TinySiOPM=new TinySiOPM(), sound:Sound=new Sound(), channel:SoundChannel;
  13.         private var bshc:Array = ["8060004205300042","0000620000006001","3121001121110110"];
  14.         private var tone:Array = [[672,4,0,20,-48],  [4,4,3,24,0],      [31,2,3,36,0]];
  15.         private var auto:Array = [0x5001,0x1101,0x1211,0x16d1,0x1252,0x6609,0xc514,0x6a01,0xd414,0xa4a4,0xa444,0x5249];
  16.         private var pong:Array = [57,60,62,64,67,69];
  17.         private var screen:Bitmap = new Bitmap(new BitmapData(465465true0));
  18.         private var balls:Array = [];
  19.         private var pointer:int, frame:int, frameCounter:int, note:int, bound:int, autoNum:int, wave:int, beat:int;
  20.         private var shadow:DropShadowFilter = new DropShadowFilter(8,45,0,0.5,6,6);
  21.         private var shape:Shape=new Shape(), mat:Matrix=new Matrix(), pos:Number, scl:Number;
  22.         private var apButton:SimpleButton, tfNormal:TextField;
  23.         public function main() {
  24.             function tf(t:String, c:uint=0x808080, x:int=0, y:int=0) : TextField {
  25.                 var tf:TextField=new TextField(); tf.htmlText=t; tf.textColor=c; tf.height=24; tf.x=x; tf.y=y; return tf;
  26.             }
  27.             function sb(t:String, f:Function, x:int, y:int) : SimpleButton {
  28.                 var over:TextField = tf("<u><b>"+t+"</b></u>", 0xf08080);
  29.                 var button:SimpleButton = new SimpleButton(tf("<u>"+t+"</u>"), over, over, over); button.x=x; button.y=y;
  30.                 button.addEventListener("mouseDown", f); return button;
  31.             }
  32.             sound.addEventListener('sampleData', _onStream);
  33.             stage.addEventListener("enterFrame", _onEnterFrame);
  34.             stage.addEventListener("mouseDown",  function(e:Event):void{ note=1; _switchAutoPlay(false); });
  35.             tfNormal=tf("クリックでえんそう",0x808080, 18016);
  36.             apButton=sb("ぜんじどうえんそう",function(e:Event):void{_switchAutoPlay(true);e.stopPropagation();},180,16);
  37.             addChild(apButton); apButton.visible = false;
  38.             addChild(tfNormal);
  39.             addChild(sb("おとかえる",function(e:Event):void{if(++wave==12)wave=0; e.stopPropagation();}, 32,  16));
  40.             addChild(sb("はやくする",function(e:Event):void{if(--frame==1)frame=5;e.stopPropagation();}, 38016));
  41.             addChild(screen);
  42.             pointer=0; frame=3; frameCounter=0; note=0; bound=0; autoNum=1; wave=2; pos=500; scl=1; beat=0;
  43.             shape.graphics.lineStyle(300.5);
  44.             shape.graphics.drawPath(Vector.<int>([1,2,1,2,1,2,1,2,1,2,1,2]), 
  45.                 Vector.<Number>([-500,-40,500,-40,-500,-20,500,-20,-500,0,500,0,-500,20,500,20,-500,40,500,40,0,-40,0,40]));
  46.             ball.createShape();
  47.             channel = sound.play();
  48.         }
  49.         private function _onEnterFrame(event:Event) : void {
  50.             var bd:BitmapData = screen.bitmapData;
  51.             if (note > 1) {
  52.                 var x:int = (autoNum) ? Math.random()*200+132 : mouseX,
  53.                     y:int = (autoNum) ? Math.random()*100+132 : mouseY;
  54.                 balls.push(new ball(x, y, note-2function(p:int, v:Number):void
  55.                     var iv:int = int(v*48);
  56.                     if ((bound & 63) < iv) bound = (p<<6) | iv;
  57.                 }));
  58.                 note = 0;
  59.             }
  60.             scl+=(1-scl)*0.5; pos-=6-frame; if (pos<0) pos+=500;
  61.             mat.identity(); mat.scale(scl,scl); mat.translate(pos, 160);
  62.             bd.fillRect(bd.rect, 0x00ffffff);
  63.             bd.draw(shape, mat);
  64.             balls = balls.filter(function(b:*,i:int,a:Array):Boolean { return b.render(bd); });
  65.             bd.applyFilter(bd, bd.rect, bd.rect.topLeft, shadow);
  66.         }
  67.         private function _onStream(e:SampleDataEvent) : void {
  68.             if (++frameCounter >= frame) {
  69.                 for (var i:int=0; i<3; i++) {
  70.                     var v:int = parseInt(bshc[i].charAt(pointer), 16);
  71.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  72.                 }
  73.                 if (autoNum) {
  74.                     if ((auto[autoNum-1]>>pointer) & 1) note = 1;
  75.                     if (pointer == 15) autoNum = int(Math.random()*12)+1;
  76.                 }
  77.                 if (note == 1) { 
  78.                     var p:int = 99;
  79.                     // velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) 
  80.                     module.noteOn((pong[p]+(beat>>7))<<4,64,wave,8);
  81.                     note = p+2;
  82.                 }
  83.                 if (bound > 0) {
  84.                     module.noteOn((pong[bound>>6]+(beat>>7))<<4,bound&63,wave,8);
  85.                     bound = 0;
  86.                 }
  87.                 pointer = (pointer + 1) & 15;
  88.                 if ((pointer & 3)==2) { scl=1.4; beat++; }
  89.                 frameCounter = 0;
  90.             }
  91.             module.buffer(e.data);
  92.         }
  93.         private function _switchAutoPlay(ap:Boolean) : void {
  94.             if (ap == Boolean(autoNum)) return;
  95.             if (ap) { apButton.visible=false; tfNormal.visible=true;  autoNum=1; } 
  96.             else    { apButton.visible=true;  tfNormal.visible=false; autoNum=0; } 
  97.         }
  98.     }
  99. }
  100. import flash.events.*;
  101. import flash.display.*;
  102. import flash.geom.*;
  103. class ball {
  104.     static private var color:Vector.<uint> = Vector.<uint>([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0,0xe040e0]);
  105.     static private var _s:Shape = new Shape(), _m:Matrix = new Matrix(), _c:ColorTransform = new ColorTransform();
  106.     private var p:Point, v:Point, alpha:Number, pitch:int, bound:Function, bounded:Boolean, len:Number, dlen:Number;
  107.     function ball(x:int, y:int, pit:int, f:Function) {
  108.         p=new Point(x, y); v=new Point(Math.random()*8-4-(x-232)*0.016, Math.random()*-6-6);
  109.         alpha=1; pitch=pit; bound=f; bounded=true; len=Math.random()*0.2+0.6; dlen=0;
  110.     }
  111.     public function render(bd:BitmapData) : Boolean {
  112.         p.x+=v.x; p.y+=v.y; v.y+=1; alpha-=0.0078125; len+=dlen; dlen+=(1-len)*0.3-dlen*0.1
  113.         if (v.y>0 && bounded && p.y+v.y*8>400) { bound(pitch, alpha); bounded=false; }
  114.         else if (p.y>450) { p.y=900-p.y; v.y=-v.y*0.7; bounded=true; len=0.7; }
  115.         if (p.x<0 || p.x>495 || alpha<0.01return false;
  116.         _m.identity(); _m.scale(1, len); _m.translate(p.x, p.y);
  117.         _c.alphaMultiplier = alpha;
  118.         _c.redOffset = color[pitch] >> 16;
  119.         _c.greenOffset = (color[pitch] >> 8) & 255;
  120.         _c.blueOffset = color[pitch] & 255;
  121.         bd.draw(_s, _m, _c);
  122.         return true;
  123.     }
  124.     static public function createShape() : void {
  125.         _s.graphics.clear();
  126.         _s.graphics.lineStyle(30);
  127.         _s.graphics.beginFill(0);
  128.         _s.graphics.drawCircle(0010);
  129.         _s.graphics.endFill();
  130.         _s.graphics.drawPath(Vector.<int>([1,2,2,2,2,2]),Vector.<Number>([10,0,10,-50,15,-38,20,-32,20,-25,17,-17]));
  131.     }
  132. }
  133. import flash.utils.ByteArray;
  134. class TinySiOPM {
  135.     private var _t:Note, _o:Vector.<Number>, _s:int;
  136.     private var _p:Vector.<int> = new Vector.<int>(2048true);         // pitchTable[128*16]
  137.     private var _l:Vector.<Number> = new Vector.<Number>(6144true);   // logTable[12*256*2]
  138.     function TinySiOPM(bufferSize:int=2048) {
  139.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  140.         for (i=0, p=0; i<192; i++, p+=0.00520833333)                    // pitch table
  141.             for(v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192) _p[j] = int(v);
  142.         for (i=0; i<Math.random()*80; i++) _p[i] = (i+1)<<6;                          // pitch=0-31 for white noize
  143.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125)               // log table
  144.             for(v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256) _l[j+1] = -(_l[j] = v);
  145.         for (i=3328; i<6144; i++) _l[i] = 0;
  146.         var famtri:Array = [0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8,-8,-7,-6,-5,-4,-3,-2,-1];
  147.         for (t=Note.table(10), i=0, p=0; i<1024; i++, p+=0.00613592315) t[i] = _log(Math.sin(p)); // sin=0
  148.         for (t=Note.table(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) t[i] = _log(p);        // saw=1
  149.         for (t=Note.table(5),  i=0; i<32; i++) t[i] = _log(famtri[i]*0.0625);                     // famtri=2
  150.         for (t=Note.table(15), i=0; i<32768; i++) t[i] = _log(Math.random()-0.5);                 // wnoize=3
  151.         for (i=0; i<8; i++) for (t=Note.table(4), j=0; j<16; j++) t[j] = (j<=i) ? 192 : 193;      // pulse=4-11
  152.         _s=bufferSize; _t=new Note(); _o=new Vector.<Number>(_s, true); for(i=0; i<_s; i++) _o[i]=0;
  153.     }
  154.     private function _log(n:Number) : int {
  155.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  156.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  157.     }
  158.     public function buffer(data:ByteArray) : void {
  159.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  160.         for (imax=1024; imax<=_s; imax+=1024for (n=_t.next; n!=_t; n=n.step())
  161.                 for (dph=_p[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++)
  162.                     { lout=n.wave[n.ph>>n.shift]+n.gain; _o[i]+=_l[lout]; }
  163.         for (i=0; i<_s; i++) { data.writeFloat(_o[i]); data.writeFloat(_o[i]); _o[i]=0; }
  164.     }
  165.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : Note { 
  166.         return Note.alloc().reset(pitch, _log(velocity*0.0078125), tone, (decay<<2), sweep).into(_t); 
  167.     }
  168. }
  169. class Note {
  170.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, wave:Vector.<int>, shift:int
  171.     static private var _w:Array=[], _s:Array=[], _fl:Note = new Note();
  172.     function Note() { prev = next = this; }
  173.     public function free() : Note { var r:Note=prev; r.next=next; next.prev=r; into(_fl); return r; }
  174.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  175.     public function step() : Note { gain+=decay; pitch+=sweep; pitch&=2047return (gain>3328)?(free().next):next; }
  176.     public function reset(p:int, g:int, t:int, d:int, s:int) : Note 
  177.     { ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; wave=_w[t]; shift=_s[t]; return this; }
  178.     static public function table(b:int) : Vector.<int>
  179.     { var t:Vector.<int>=new Vector.<int>(1<<b, true); _w.push(t); _s.push(26-b); return t; }
  180.     static public function alloc() : Note 
  181.     { if (_fl.prev==_fl) { return new Note(); } var r:Note=_fl.prev; _fl.prev=r.prev; _fl.prev.next=_fl; return r; }
  182. }
noswf
  1. // forked from keim_at_Si's ((♪))
  2. package {
  3.     import flash.display.*;
  4.     import flash.events.*;
  5.     import flash.filters.*;
  6.     import flash.media.*;
  7.     import flash.text.*;
  8.     import flash.geom.*;
  9.     
  10.     [SWF(width="465", height="465", backgroundColor="#ffffff", frameRate=30)]
  11.     public class main extends Sprite {
  12.         private var module:TinySiOPM=new TinySiOPM(), sound:Sound=new Sound(), channel:SoundChannel;
  13.         private var bshc:Array = ["8060004205300042","0000620000006001","3121001121110110"];
  14.         private var tone:Array = [[672,4,0,20,-48],  [4,4,3,24,0],      [31,2,3,36,0]];
  15.         private var auto:Array = [0x5001,0x1101,0x1211,0x16d1,0x1252,0x6609,0xc514,0x6a01,0xd414,0xa4a4,0xa444,0x5249];
  16.         private var pong:Array = [57,60,62,64,67,69];
  17.         private var screen:Bitmap = new Bitmap(new BitmapData(465465true0));
  18.         private var balls:Array = [];
  19.         private var pointer:int, frame:int, frameCounter:int, note:int, bound:int, autoNum:int, wave:int, beat:int;
  20.         private var shadow:DropShadowFilter = new DropShadowFilter(8,45,0,0.5,6,6);
  21.         private var shape:Shape=new Shape(), mat:Matrix=new Matrix(), pos:Number, scl:Number;
  22.         private var apButton:SimpleButton, tfNormal:TextField;
  23.         public function main() {
  24.             function tf(t:String, c:uint=0x808080, x:int=0, y:int=0) : TextField {
  25.                 var tf:TextField=new TextField(); tf.htmlText=t; tf.textColor=c; tf.height=24; tf.x=x; tf.y=y; return tf;
  26.             }
  27.             function sb(t:String, f:Function, x:int, y:int) : SimpleButton {
  28.                 var over:TextField = tf("<u><b>"+t+"</b></u>", 0xf08080);
  29.                 var button:SimpleButton = new SimpleButton(tf("<u>"+t+"</u>"), over, over, over); button.x=x; button.y=y;
  30.                 button.addEventListener("mouseDown", f); return button;
  31.             }
  32.             sound.addEventListener('sampleData', _onStream);
  33.             stage.addEventListener("enterFrame", _onEnterFrame);
  34.             stage.addEventListener("mouseDown",  function(e:Event):void{ note=1; _switchAutoPlay(false); });
  35.             tfNormal=tf("クリックでえんそう",0x808080, 18016);
  36.             apButton=sb("ぜんじどうえんそう",function(e:Event):void{_switchAutoPlay(true);e.stopPropagation();},180,16);
  37.             addChild(apButton); apButton.visible = false;
  38.             addChild(tfNormal);
  39.             addChild(sb("おとかえる",function(e:Event):void{if(++wave==12)wave=0; e.stopPropagation();}, 32,  16));
  40.             addChild(sb("はやくする",function(e:Event):void{if(--frame==1)frame=5;e.stopPropagation();}, 38016));
  41.             addChild(screen);
  42.             pointer=0; frame=3; frameCounter=0; note=0; bound=0; autoNum=1; wave=2; pos=500; scl=1; beat=0;
  43.             shape.graphics.lineStyle(300.5);
  44.             shape.graphics.drawPath(Vector.<int>([1,2,1,2,1,2,1,2,1,2,1,2]), 
  45.                 Vector.<Number>([-500,-40,500,-40,-500,-20,500,-20,-500,0,500,0,-500,20,500,20,-500,40,500,40,0,-40,0,40]));
  46.             ball.createShape();
  47.             channel = sound.play();
  48.         }
  49.         private function _onEnterFrame(event:Event) : void {
  50.             var bd:BitmapData = screen.bitmapData;
  51.             if (note > 1) {
  52.                 var x:int = (autoNum) ? Math.random()*200+132 : mouseX,
  53.                     y:int = (autoNum) ? Math.random()*100+132 : mouseY;
  54.                 balls.push(new ball(x, y, note-2function(p:int, v:Number):void
  55.                     var iv:int = int(v*48);
  56.                     if ((bound & 63) < iv) bound = (p<<6) | iv;
  57.                 }));
  58.                 note = 0;
  59.             }
  60.             scl+=(1-scl)*0.5; pos-=6-frame; if (pos<0) pos+=500;
  61.             mat.identity(); mat.scale(scl,scl); mat.translate(pos, 160);
  62.             bd.fillRect(bd.rect, 0x00ffffff);
  63.             bd.draw(shape, mat);
  64.             balls = balls.filter(function(b:*,i:int,a:Array):Boolean { return b.render(bd); });
  65.             bd.applyFilter(bd, bd.rect, bd.rect.topLeft, shadow);
  66.         }
  67.         private function _onStream(e:SampleDataEvent) : void {
  68.             if (++frameCounter >= frame) {
  69.                 for (var i:int=0; i<3; i++) {
  70.                     var v:int = parseInt(bshc[i].charAt(pointer), 16);
  71.                     if (v) { module.noteOn(tone[i][0], v<<tone[i][1], tone[i][2], tone[i][3], tone[i][4]); }
  72.                 }
  73.                 if (autoNum) {
  74.                     if ((auto[autoNum-1]>>pointer) & 1) note = 1;
  75.                     if (pointer == 15) autoNum = int(Math.random()*12)+1;
  76.                 }
  77.                 if (note == 1) { 
  78.                     var p:int = int(Math.random()*6);
  79.                     module.noteOn((pong[p]+(beat>>7))<<4,64,wave,8);
  80.                     note = p+2;
  81.                 }
  82.                 if (bound > 0) {
  83.                     module.noteOn((pong[bound>>6]+(beat>>7))<<4,bound&63,wave,8);
  84.                     bound = 0;
  85.                 }
  86.                 pointer = (pointer + 1) & 15;
  87.                 if ((pointer & 3)==2) { scl=1.4; beat++; }
  88.                 frameCounter = 0;
  89.             }
  90.             module.buffer(e.data);
  91.         }
  92.         private function _switchAutoPlay(ap:Boolean) : void {
  93.             if (ap == Boolean(autoNum)) return;
  94.             if (ap) { apButton.visible=false; tfNormal.visible=true;  autoNum=1; } 
  95.             else    { apButton.visible=true;  tfNormal.visible=false; autoNum=0; } 
  96.         }
  97.     }
  98. }
  99. import flash.events.*;
  100. import flash.display.*;
  101. import flash.geom.*;
  102. class ball {
  103.     static private var color:Vector.<uint> = Vector.<uint>([0xf08080,0xe0e040,0x80f080,0x40e0e0,0x8080f0,0xe040e0]);
  104.     static private var _s:Shape = new Shape(), _m:Matrix = new Matrix(), _c:ColorTransform = new ColorTransform();
  105.     private var p:Point, v:Point, alpha:Number, pitch:int, bound:Function, bounded:Boolean, len:Number, dlen:Number;
  106.     function ball(x:int, y:int, pit:int, f:Function) {
  107.         p=new Point(x, y); v=new Point(Math.random()*8-4-(x-232)*0.016, Math.random()*-6-6);
  108.         alpha=1; pitch=pit; bound=f; bounded=true; len=Math.random()*0.2+0.6; dlen=0;
  109.     }
  110.     public function render(bd:BitmapData) : Boolean {
  111.         p.x+=v.x; p.y+=v.y; v.y+=1; alpha-=0.0078125; len+=dlen; dlen+=(1-len)*0.3-dlen*0.1
  112.         if (v.y>0 && bounded && p.y+v.y*8>400) { bound(pitch, alpha); bounded=false; }
  113.         else if (p.y>450) { p.y=900-p.y; v.y=-v.y*0.7; bounded=true; len=0.7; }
  114.         if (p.x<0 || p.x>495 || alpha<0.01return false;
  115.         _m.identity(); _m.scale(1, len); _m.translate(p.x, p.y);
  116.         _c.alphaMultiplier = alpha;
  117.         _c.redOffset = color[pitch] >> 16;
  118.         _c.greenOffset = (color[pitch] >> 8) & 255;
  119.         _c.blueOffset = color[pitch] & 255;
  120.         bd.draw(_s, _m, _c);
  121.         return true;
  122.     }
  123.     static public function createShape() : void {
  124.         _s.graphics.clear();
  125.         _s.graphics.lineStyle(30);
  126.         _s.graphics.beginFill(0);
  127.         _s.graphics.drawCircle(0010);
  128.         _s.graphics.endFill();
  129.         _s.graphics.drawPath(Vector.<int>([1,2,2,2,2,2]),Vector.<Number>([10,0,10,-50,15,-38,20,-32,20,-25,17,-17]));
  130.     }
  131. }
  132. import flash.utils.ByteArray;
  133. class TinySiOPM {
  134.     private var _t:Note, _o:Vector.<Number>, _s:int;
  135.     private var _p:Vector.<int> = new Vector.<int>(2048true);         // pitchTable[128*16]
  136.     private var _l:Vector.<Number> = new Vector.<Number>(6144true);   // logTable[12*256*2]
  137.     function TinySiOPM(bufferSize:int=2048) {
  138.         var i:int, j:int, p:Number, v:Number, t:Vector.<int>;
  139.         for (i=0, p=0; i<192; i++, p+=0.00520833333)                    // pitch table
  140.             for(v=Math.pow(2, p)*12441.464342886, j=i; j<2048; v*=2, j+=192) _p[j] = int(v);
  141.         for (i=0; i<32; i++) _p[i] = (i+1)<<6;                          // pitch=0-31 for white noize
  142.         for (i=0, p=0.0078125; i<256; i+=2, p+=0.0078125)               // log table
  143.             for(v=Math.pow(213-p)*0.0001220703125, j=i; j<3328; v*=0.5, j+=256) _l[j+1] = -(_l[j] = v);
  144.         for (i=3328; i<6144; i++) _l[i] = 0;
  145.         var famtri:Array = [0,1,2,3,4,5,6,7,7,6,5,4,3,2,1,0,-1,-2,-3,-4,-5,-6,-7,-8,-8,-7,-6,-5,-4,-3,-2,-1];
  146.         for (t=Note.table(10), i=0, p=0; i<1024; i++, p+=0.00613592315) t[i] = _log(Math.sin(p)); // sin=0
  147.         for (t=Note.table(10), i=0, p=0.75; i<1024; i++, p-=0.00146484375) t[i] = _log(p);        // saw=1
  148.         for (t=Note.table(5),  i=0; i<32; i++) t[i] = _log(famtri[i]*0.0625);                     // famtri=2
  149.         for (t=Note.table(15), i=0; i<32768; i++) t[i] = _log(Math.random()-0.5);                 // wnoize=3
  150.         for (i=0; i<8; i++) for (t=Note.table(4), j=0; j<16; j++) t[j] = (j<=i) ? 192 : 193;      // pulse=4-11
  151.         _s=bufferSize; _t=new Note(); _o=new Vector.<Number>(_s, true); for(i=0; i<_s; i++) _o[i]=0;
  152.     }
  153.     private function _log(n:Number) : int {
  154.         return (n<0) ? ((n<-0.00390625) ? (((int(Math.log(-n) * -184.66496523 + 0.5) + 1) << 1) + 1) : 2047)
  155.                      : ((n> 0.00390625) ? (( int(Math.log( n) * -184.66496523 + 0.5) + 1) << 1)      : 2046);
  156.     }
  157.     public function buffer(data:ByteArray) : void {
  158.         var n:Note, rep:int, i:int, imax:int, dph:int, lout:int, v:int;
  159.         for (imax=1024; imax<=_s; imax+=1024for (n=_t.next; n!=_t; n=n.step())
  160.                 for (dph=_p[n.pitch], i=imax-1024; i<imax; n.ph=(n.ph+dph)&0x3ffffff, i++)
  161.                     { lout=n.wave[n.ph>>n.shift]+n.gain; _o[i]+=_l[lout]; }
  162.         for (i=0; i<_s; i++) { data.writeFloat(_o[i]); data.writeFloat(_o[i]); _o[i]=0; }
  163.     }
  164.     public function noteOn(pitch:int, velocity:int=64, tone:int=0, decay:int=4, sweep:int=0) : Note { 
  165.         return Note.alloc().reset(pitch, _log(velocity*0.0078125), tone, (decay<<2), sweep).into(_t); 
  166.     }
  167. }
  168. class Note {
  169.     public var prev:Note, next:Note, ph:int, pitch:int, gain:int, sweep:int, decay:int, wave:Vector.<int>, shift:int
  170.     static private var _w:Array=[], _s:Array=[], _fl:Note = new Note();
  171.     function Note() { prev = next = this; }
  172.     public function free() : Note { var r:Note=prev; r.next=next; next.prev=r; into(_fl); return r; }
  173.     public function into(n:Note) : Note { prev=n.prev; next=n; prev.next=this; next.prev=thisreturn this; }
  174.     public function step() : Note { gain+=decay; pitch+=sweep; pitch&=2047return (gain>3328)?(free().next):next; }
  175.     public function reset(p:int, g:int, t:int, d:int, s:int) : Note 
  176.     { ph=0; pitch=p; gain=g; sweep=s; decay=d<<1; wave=_w[t]; shift=_s[t]; return this; }
  177.     static public function table(b:int) : Vector.<int>
  178.     { var t:Vector.<int>=new Vector.<int>(1<<b, true); _w.push(t); _s.push(26-b); return t; }
  179.     static public function alloc() : Note 
  180.     { if (_fl.prev==_fl) { return new Note(); } var r:Note=_fl.prev; _fl.prev=r.prev; _fl.prev.next=_fl; return r; }
  181. }
noswf
Get Adobe Flash Player