.# adapté de http://zoneflash.net vincent crublé .flash bbox=400x450 filename=laser.swf fps=12 background=#556677 .action: var r=_root ; with ( r ) { _focusrect = false; // fscommand('allowscale',false); // fscommand('fullscreen',false); var n=30,largeur=400,hauteur=400,marge=50,rayon=10; var xmin=marge + rayon, ymin=marge+rayon, xmax=largeur-marge-rayon, ymax=hauteur-marge-rayon, largeur2=largeur-2 * marge, hauteur2=hauteur-2 * marge, tolerance=100, coefficient=0.1, max=0; var bmp=new BitmapData(largeur2, hauteur2,true,0); createEmptyMovieClip('holder',0); holder._x=marge; holder._y=marge; holder.attachBitmap(bmp, 0); filtre =new BlurFilter(10,10,1); matrice=new Matrix(); matrice.translate(-marge, -marge); rectangle=new Rectangle(0,0,largeur2,hauteur2); point =new Point(0,0); tirage=function (vmin, vmax) { return vmin + (vmax - vmin) * Math.random(); }; placerLesPointsSurUnCercle=function () { var v2=0; while (v2 < n - 1) { var v3=this['dot' + v2]; var v4=v2 * 2 * Math.PI / (n - 1); v3._x=200 + 130 * Math.cos(v4); v3._y=200 + 130 * Math.sin(v4); ++v2; } this['dot'+(n-1)]._x=200; this['dot'+(n-1)]._y=200; }; var cercle_btn=new button; cercle_btn.border=true; var hasard_btn=createEmptyMovieClip('hasard_btn',1); cercle_btn.onPress=function () { r.placerLesPointsSurUnCercle(); max=0; }; placerLesPointsAuHasard=function () { var v2=0; while (v2 < n) { var v3=this['dot' + v2]; v3._x=r.tirage(xmin, xmax); v3._y=r.tirage(ymin, ymax); max=0; ++v2; } }; hasard_btn.onPress=function () { r.placerLesPointsAuHasard(); }; var i=0; while (i < n) { var dot=createEmptyMovieClip('dot' + i, i + 1); dot.lineStyle(5, '0xFFFFFF', 100); dot.moveTo(0, 0); dot.lineTo(0.3, 0); dot._width=5; dot._height=5; dot._x=tirage(xmin, xmax); dot._y=tirage(ymin, ymax); ++i; } var texte=createTextField(1,1,10,300,150,30); var mydot=createEmptyMovieClip('mydot', n + 2); mydot.lineStyle(3, '0xFF0000', 100); mydot.moveTo(0, 0); mydot.lineTo(0.3, 0); mydot._width=6; mydot._height=6; var lignes=createEmptyMovieClip('lignes', n + 1); onEnterFrame=function () { var v15=0; var v16=r._ymouse; if (v16 > marge + hauteur2) v16=200; var v18=r._xmouse - mydot._x; var v17=v16 - mydot._y; mydot._x += coefficient * v18; mydot._y += coefficient * v17; lignes.clear(); lignes.lineStyle(5,'0x00FFFF',50); var v10=0; while (v10 < n) { var v6=v10 + 1; while (v6 < n) { var v2=this['dot'+v10]; var v3=this['dot'+v6]; var v5=v3._x - v2._x; var v4=v3._y - v2._y; var v8=mydot._x - v2._x; var v7=mydot._y - v2._y; var v14=Math.abs(v5 * v7 - v4 * v8) <= tolerance; if (v14) { var v12=v5 * v5 + v4 * v4; var v11=v5 * v8 + v4 * v7; var v9=v11 / v12; var v13=v9 >= 0 && v9 <= 1; if (v13) { ++v15; lignes.moveTo(v2._x, v2._y); lignes.lineTo(v3._x, v3._y); } } ++v6; } ++v10; } if (v15 > max) max=v15; bmp.draw(lignes, r.matrice); bmp.applyFilter(bmp, r.rectangle,r.point,r.filtre); texte.text=v15+'/'+max; }; } .end .end