LoginSignup
0
0

More than 5 years have passed since last update.

JavaScript本に書いてあった簡単な図形描画をMathematicaで

Posted at

Mathematicaの記事にいきなりJavaScriptで恐縮です。

オブジェクト指向JavaScript」という本に

割り算の余りを計算する演算子を利用して、雪の結晶のような形状を作るサンプルを紹介します。

と以下のコードが掲載されていました。

dashed_grid.js
var res = '\n', i, j;
for(i = 1; i <= 7; i++) {
  for(j = 1; j < 15; j++) {
    res += (i * j) % 8 ? ' ' : '*';
  }
  res+= '\n';
}

実行すると以下のような文字列が出力されます。

"
       *      
   *   *   *  
       *      
 * * * * * * *
       *      
   *   *   *  
       *      
"

これを(canvasでもいいのですが)Mathematicaで描いてみました。

dashed_grid.nb
ArrayPlot[Table[Boole[Divisible[i j, 128]], {i, 1, 255}, {j, 1, 255}], PixelConstrained -> True, Frame -> False]

こんなです。
なんだか罫線に応用できそうですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0