視覚的なコード品質分析

すべての人に良い一日を!



1つのGIFに触発されて、逆のアプリケーションを作成してコードの「マップ」を見るとどうなりますか?



まず、「正方形に非常に多くのピクセルを配置する」という問題を解決する必要があります。

二乗が常に可能であり、必ずしも必要ではないことは明らかです。 したがって、追加で長方形に配置できます。

129 = 11 * 12-3と言うアルゴリズムを見つけられなかったので、自分で作成することにしました。



ひどいコード
public static ImageSize Generate(uint PixelsCount, double MaximumDeltaPercent=1f, uint MaximumAbsoluteDelta=10, double MaximumAspectRatio=1.77) { //check if this is empty image if (PixelsCount==0) return new ImageSize(1,1); //check if this is a square double sqrt = Math.Truncate(Math.Sqrt(PixelsCount)); if (Math.Pow(sqrt, 2) == PixelsCount) return new ImageSize((ushort)sqrt, (ushort) sqrt); //  ,  AspectRatio - ,     .      . if (PixelsCount<=10) MaximumAspectRatio = double.MaxValue; double percentdelta = PixelsCount/(MaximumDeltaPercent*100); uint height = (ushort) Math.Truncate(Math.Sqrt(PixelsCount)); uint width = (ushort) (height+1); while (width/(height*1.0f)<MaximumAspectRatio) { ulong Result = width*height; if (Result==PixelsCount) { if (width<=ushort.MaxValue && height<=ushort.MaxValue) { return new ImageSize((ushort) width, (ushort) height); } } if (Result>PixelsCount) { if ((Result-PixelsCount)<=percentdelta || Result-PixelsCount<=MaximumAbsoluteDelta) { if (width <= ushort.MaxValue && height <= ushort.MaxValue) { return new ImageSize((ushort) width, (ushort) height); } } height--; continue; } if (Result < PixelsCount) { width++; } } throw new Exception(string.Format("     {0}    Aspect Ratio.   \n : PC:{0} MDP:{1} MAD:{2} MAR{3}",PixelsCount,MaximumDeltaPercent,MaximumAbsoluteDelta,MaximumAspectRatio)); }
      
      





その後、ストリームまたはファイルに美しい絵を描きます。



結果の写真の例:

私のミニプロジェクトの大きなファイルの一つ






コードは平均して均一な灰色で、緑色のスプラッシュがあります。 しかし、ストライプ。



Win8.1のExplorer.exe






実行可能ファイルは奇妙で、真ん中に黒いストライプがあります。 一般的に、これは明らかです。

最後に、アイコンのリソースが推測されます。



結果の写真の例:

LinuxカーネルのWorkqueue.c






コードは平均して均一にグレーで、青のスプラッシュがあります。 全体として、青みがかったように見えます。



一般的に、実験して、あなたのコードが均一に茶色にならないことを願っています!



アーカイブ内のソース

コンパイルされたプログラム

PS数値を余りのある積に変換するための美しいアルゴリズムを突然知った場合、それについて教えてください。



All Articles