2009-08-12から1日間の記事一覧

circleの範囲を最適化

バッファ上で円を塗りつぶすとき、 (0...buf.y).each do |i| (0...buf.x).each do |j| if (y - i)**2 + (x -j)**2 < r**2 then buf.buf[i][j] = color end end end とやっていたけど、明らかにチェックする意味がないところまで調べているので、 upper = (y …

structって何だ

以下のコードがいかにも冗長。 if test.within_circle(x, y, i, j, r) > 0 then old = buf.buf[i][j].r buf.buf[i][j].r = (color.r * fore) + (old * back) old = buf.buf[i][j].g buf.buf[i][j].g = (color.g * fore) + (old * back) old = buf.buf[i][j].…

Cの速さにがっくり来た

Rubyで書いたグラフィックバッファ処理と同じものをCで書き直してみた。 #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct { int height; int width; int **raw; } buf; buf *init_buf (int width, int height) { buf *b; int i, j; b = (buf *)malloc(sizeof(</time.h></stdlib.h></stdio.h>…