<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yukun&#039;s Blog &#187; C language</title>
	<atom:link href="http://www.yukun.info/blog/tag/c-language/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yukun.info</link>
	<description>難しいことは分かりやすく、簡単なことは面白く紹介</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:33:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>OpenGL: ポリゴンで円の描画</title>
		<link>http://www.yukun.info/blog/2008/06/opengl-circle.html</link>
		<comments>http://www.yukun.info/blog/2008/06/opengl-circle.html#comments</comments>
		<pubDate>Thu, 19 Jun 2008 15:00:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C language]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.yukun.info/trump/19700101/%e3%83%9d%e3%83%aa%e3%82%b4%e3%83%b3%e3%81%a7%e5%86%86%e3%81%ae%e6%8f%8f%e7%94%bb</guid>
		<description><![CDATA[円周上の座標(x, y)×n個を計算しその点を結ぶことによって描画します。nを分割数とすると、nに比例して円は滑らかになります。 実行結果 分割数: 15(ちょっとカクカクしてる) 分割数: 100 コード // Ope &#8230; <a href="http://www.yukun.info/blog/2008/06/opengl-circle.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/06/opengl-circle.html">OpenGL: ポリゴンで円の描画</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>円周上の座標(x, y)×n個を計算しその点を結ぶことによって描画します。nを分割数とすると、nに比例して円は滑らかになります。</p>
<h3>実行結果</h3>
<ul>
<li>分割数: 15(ちょっとカクカクしてる)</li>
</ul>
<p><a href="http://www.yukun.info/wp-content/uploads/circleP15.gif"><img src="http://www.yukun.info/wp-content/uploads/circleP15.gif" alt="OpenGL: ポリゴンで円の描画(分割数:15)" title="circleP15" width="416" height="437" class="size-full wp-image-1519" /></a><br />
</p>
<ul>
<li>分割数: 100</li>
</ul>
<p><a href="http://www.yukun.info/wp-content/uploads/circleP100.gif"><img src="http://www.yukun.info/wp-content/uploads/circleP100.gif" alt="OpenGL: ポリゴンで円の描画(分割数:100)" title="circleP100" width="416" height="437" class="size-full wp-image-1520" /></a></p>
<h3>コード</h3>
<pre>
// OpenGLで円の描画
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;gl/glut.h&gt;
#include &lt;gl/gl.h&gt;
#include &lt;math.h&gt;

#define M_PI 3.14159265358979 // 円周率
#define PART 100 // 分割数

void display(void)
{
  int i, n = PART;
  float x, y, r = 0.5;
  double rate;

  glClear(GL_COLOR_BUFFER_BIT); // ウィンドウの背景をglClearColor()で指定された色で塗りつぶす
  glColor3f(1.0, 1.0, 1.0); // 描画物体に白色を設定
  glBegin(GL_POLYGON); // ポリゴンの描画
  // 円を描画
  for (i = 0; i &lt; n; i++) {
    // 座標を計算
    rate = (double)i / n;
    x = r * cos(2.0 * M_PI * rate);
    y = r * sin(2.0 * M_PI * rate);
    glVertex3f(x, y, 0.0); // 頂点座標を指定
  }
  glEnd(); // ポリゴンの描画終了
  glFlush(); // OpenGLのコマンドを強制的に実行(描画終了)
}

void init(char *name)
{
  int width = 400, height = 400; // ウィンドウサイズ
  int w_window = glutGet(GLUT_SCREEN_WIDTH), h_window = glutGet(GLUT_SCREEN_HEIGHT); // デスクトップのサイズ
  int w_mid = (w_window-width)/2, h_mid = (h_window-height)/2; // デスクトップの中央座標

  glutInitWindowPosition(w_mid, h_mid);
  glutInitWindowSize(width, height);
  glutInitDisplayMode(GLUT_RGBA); // 色の指定にRGBAモードを使用
  glutCreateWindow(name);
  glClearColor(0.0, 0.0, 0.0, 1.0); // ウィンドウの背景色の指定
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); // 座標系を設定(平行投影)
}

int main(int argc, char **argv)
{
  glutInit(&amp;argc, argv); // glutの初期化
  init(argv[0]);
  glutDisplayFunc(display); // ディスプレイコールバック関数の指定
  glutMainLoop(); // イベント待ちループ
  return 0;
}
</pre>
<p>そういえば、リアルタイム処理などではポリゴンの数を抑えることで処理速度を稼いでましたね。</p>
<p>参考サイト: <a href="http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#5.2" title="GLUTによる「手抜き」OpenGL入門" target="_blank">GLUTによる「手抜き」OpenGL入門</a></p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html" rel="bookmark" title="2008年1月3日">X Window System 上での描画色の変更</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/decimal-to-binary.html" rel="bookmark" title="2008年1月13日">10進数を2進数に変換表示するC言語プログラム</a></li>
<li><a href="http://www.yukun.info/blog/2009/02/java-swing-jcomponent-drawing-line.html" rel="bookmark" title="2009年2月21日">Java, Swing: JComponentのGraphicsオブジェクトを用いて直線を描画</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-button.html" rel="bookmark" title="2008年10月14日">AS3でお絵かきFlashを作る (2)ボタン作成 &#8211; Flexコンポーネントの導入</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/actionscript-paint-flash-flex-draw-tool.html" rel="bookmark" title="2008年10月19日">AS3でお絵かきFlashを作る (3)図形描画と配置選択ツールの追加</a></li>
</ul>
<p><!-- Similar Posts took 6.973 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/06/opengl-circle.html">OpenGL: ポリゴンで円の描画</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/06/opengl-circle.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>3種類の括弧の対応をチェックするC言語プログラム</title>
		<link>http://www.yukun.info/blog/2008/02/check-syntax.html</link>
		<comments>http://www.yukun.info/blog/2008/02/check-syntax.html#comments</comments>
		<pubDate>Mon, 11 Feb 2008 14:44:09 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C language]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.yukun.info/trump/20080211/3%e7%a8%ae%e9%a1%9e%e3%81%ae%e6%8b%ac%e5%bc%a7%e3%81%ae%e5%af%be%e5%bf%9c%e3%82%92%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%81%99%e3%82%8bc%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0</guid>
		<description><![CDATA[先日勉強会でこの辺のテーマを取り上げたので、字句解析や構文解析(の一部)とスタックの復習も兼ねて作成(required for 1h+)。 実装のポイント 閉じ括弧の有無の判定は、ファイルの終端が読み終わった後。 開き括 &#8230; <a href="http://www.yukun.info/blog/2008/02/check-syntax.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/02/check-syntax.html">3種類の括弧の対応をチェックするC言語プログラム</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>先日勉強会でこの辺のテーマを取り上げたので、字句解析や構文解析(の一部)とスタックの復習も兼ねて作成(required for 1h+)。</p>
<h3>実装のポイント</h3>
<ul>
<li>閉じ括弧の有無の判定は、ファイルの終端が読み終わった後。</li>
<li>開き括弧の判定は、閉じ括弧を読み込んだ際に行い、スタックの最上位に対応する開き括弧があるか否かで。</li>
<li>入れ子の(または再帰的な)構造で、どの深さにスレッドがいるか調べるにはスタックを用いる。</li>
</ul>
<h3>ソースコード(C言語) valid_pare.c</h3>
<pre>
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

const int MAXSIZE = 128; // スタックサイズ(静的)
// スタックするデータ構造(Cell)
typedef struct brackets Brackets;
struct brackets {
  int kind; // 括弧の種類
  int line; // 位置：行
  int pos; // 位置：列
};
Brackets stack[128];
int pnt;

Brackets pop(void)
{
  if (pnt &lt; = 0) {
    printf(&quot;error:stack empty.\n&quot;);
    exit(1);
  }
  pnt--;
  return stack[pnt];
}
void push(Brackets b)
{
  if (pnt &gt;= MAXSIZE) {
    printf(&quot;error:stack fullness.\n&quot;);
    exit(1);
  }
  stack[pnt] = b;
  pnt++;
}
// stackが空(1)か否(0)か
int empty(void)
{
  return (pnt == 0) ? 1 : 0;
}
// スタックの最上位の文字種を返す
int peek()
{
  return stack[pnt-1].kind;
}
// 括弧の判別
int kind(int ch)
{
  int code;
  switch (ch) {
  case &#039;(&#039;:
    code = 1;
    break;
  case &#039;)&#039;:
    code = 2;
    break;
  case &#039;{&#039;:
    code = 3;
    break;
  case &#039;}&#039;:
    code = 4;
    break;
  case &#039;[&#039;:
    code = 5;
    break;
  case &#039;]&#039;:
    code = 6;
    break;
  default:
    code = 0; // 括弧以外の文字
    break;
  }
  return code;
}

int main()
{
  int ch;
  FILE *fp;
  char fname[64]; // ファイル名
  int k; // 文字の種類
  int line = 1, pos = 0;
  Brackets kakko, temp;

  pnt = 0; // スタックポインタ(GV)の初期化
  printf(&quot;Filename:&quot;);
  scanf(&quot;%62s&quot;, fname);
  if ((fp = fopen(fname, &quot;r&quot;)) == NULL) {
    printf(&quot;\aCan&#039;t be opened.\n&quot;);
    exit(1);
  }
  //printf(&quot;%d行目\n&quot;, line);
  // ファイルから一文字ずつ読む
  while ((ch = fgetc(fp)) != EOF) {
    //putchar(ch);
    if (ch == &#039;\n&#039;) {
      line++; pos=0;
      //printf(&quot;%d行目\n&quot;, line);
      continue;
    }
    pos++;
    //printf(&quot;%d&quot;, pos);
    k = kind(ch);
    if (k &gt; 0) { // 文字が括弧の場合
      if (k % 2) { // 開き括弧の場合
        kakko.kind = k;
        kakko.line = line;
        kakko.pos  = pos;
        push(kakko);
      } else if (!empty() &amp;&amp; (k == peek()+1)) {
        temp = pop(); // 対応する閉じ括弧があった
      } else {
        printf(&quot;対応する開き括弧がない&quot;);
        printf(&quot;(%d行目の%d文字目)。\n&quot;, line, pos);
      }
    }
  }
  puts(&quot;テキスト終端&quot;);
  fclose(fp);
  if (!empty()) {
    printf(&quot;対応する閉じ括弧がない。\n&quot;);
    while (!empty()) {
      temp = pop();
      printf(&quot;%d行目の%d文字目。\n&quot;, temp.line, temp.pos);
    }
  }
  return 0;
}
</pre>
<h3>使用したText</h3>
<pre>(1+2)
ac)c
((3+6)ge))
(([y)
ij])(k
{5/3}</pre>
<h3>実行結果</h3>
<pre>
D:\parentheses>gcc valid_pare.c
D:\parentheses>a.exe
Filename:pare.txt
対応する開き括弧がない(2行目の3文字目)。
対応する開き括弧がない(3行目の10文字目)。
対応する開き括弧がない(4行目の5文字目)。
テキスト終端
対応する閉じ括弧がない。
5行目の5文字目。
4行目の1文字目。
D:\parentheses>
</pre>
<h3>改良するなら</h3>
<ul>
<li>関数を他のファイルに分けて、main側でインクルードする。</li>
<li>スタック領域を動的に割り当てる。(Brackets *)emalloc(sizeof(Brackets))かな。</li>
<li>スタック配列を伸縮性のある構造・操作関数で実装する。</li>
<li>結果の表示をコンパイラのエラー出力っぽくする。該当箇所に「^」をマーク。</li>
<li>他の言語で実装してみる(OOPを用いて等等)。</li>
<li>字句・構文解析のオープンソースを参考にする。</li>
</ul>
<p>こういった小さなものを作りつつ、OOPのパターンに基づいて拡張性を考慮する今日この頃。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/01/decimal-to-binary.html" rel="bookmark" title="2008年1月13日">10進数を2進数に変換表示するC言語プログラム</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/ruby-string-index.html" rel="bookmark" title="2008年1月5日">Rubyで文字列から日本語文字をインデックス指定する</a></li>
<li><a href="http://www.yukun.info/blog/2009/03/note-of-the-day-2009-03-22.html" rel="bookmark" title="2009年3月22日">Note of the Day &#8211; 2009-03-22</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/python-list2.html" rel="bookmark" title="2008年6月12日">Python: リストの要素の追加と削除、取出し &#8211; append()、extend()、pop()、remove()メソッド</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html" rel="bookmark" title="2008年1月3日">X Window System 上での描画色の変更</a></li>
</ul>
<p><!-- Similar Posts took 8.531 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/02/check-syntax.html">3種類の括弧の対応をチェックするC言語プログラム</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/02/check-syntax.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10進数を2進数に変換表示するC言語プログラム</title>
		<link>http://www.yukun.info/blog/2008/01/decimal-to-binary.html</link>
		<comments>http://www.yukun.info/blog/2008/01/decimal-to-binary.html#comments</comments>
		<pubDate>Sat, 12 Jan 2008 15:00:00 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C language]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Number]]></category>

		<guid isPermaLink="false">http://www.yukun.info/trump/19700101/10%e9%80%b2%e6%95%b0%e3%82%922%e9%80%b2%e6%95%b0%e3%81%ab%e5%a4%89%e6%8f%9b%e8%a1%a8%e7%a4%ba%e3%81%99%e3%82%8bc%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0</guid>
		<description><![CDATA[ソースコード // filename: dtob.c // convert decimal to binary #include &#60;stdio.h&#62; const int BitSize = sizeof(in &#8230; <a href="http://www.yukun.info/blog/2008/01/decimal-to-binary.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/01/decimal-to-binary.html">10進数を2進数に変換表示するC言語プログラム</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<h3>ソースコード</h3>
<pre>
// filename: dtob.c
// convert decimal to binary
#include &lt;stdio.h&gt;

const int BitSize = sizeof(int) * 8; // 整数型のビットサイズを算出
void dtob(int x) {
  int bit = 1, i;
  char c[BitSize];

  for (i = 0; i &lt; BitSize; i++) {
    if (x &amp; bit)
      c[i] = &#039;1&#039;;
    else
      c[i] = &#039;0&#039;;
    bit &lt;&lt;= 1;
  }
  // 計算結果の表示
  printf(&quot;2進数: &quot;);
  for ( i = BitSize - 1; i &gt;= 0; i-- ) {
      putchar(c[i]);
  }
  printf(&quot;\n&quot;);
}

int main()
{
  int x = 0;
  do {
  printf(&quot;10進数を2進数に変換します(0で終了)\n&quot;);
  printf(&quot;xの値: &quot;);
  scanf(&quot;%d&quot;, &amp;x);
  dtob(x);
  } while (x != 0);
  return 0;
}
</pre>
<h3>実行結果</h3>
<pre>[yu@localhost cpp]# gcc dtob.c
[yu@localhost cpp]# ./a.out
10進数を2進数に変換します(0で終了)
xの値: 5
2進数: 00000000000000000000000000000101
10進数を2進数に変換します(0で終了)
xの値: 8
2進数: 00000000000000000000000000001000
10進数を2進数に変換します(0で終了)
xの値: 100
2進数: 00000000000000000000000001100100
10進数を2進数に変換します(0で終了)
xの値: 256
2進数: 00000000000000000000000100000000
10進数を2進数に変換します(0で終了)
xの値: 1984949894
2進数: 01110110010011111110111010000110
10進数を2進数に変換します(0で終了)
xの値: 0
2進数: 00000000000000000000000000000000
[yu@localhost cpp]# </pre>
<p>ビットが0か1の判断するループ順序を逆にして、配列末尾に&#8217;\0&#8242;を代入すれば、計算結果の表示は配列の文字列表示ですみます。そうすると「計算結果の表示」の際にforループを使う必要はないなぁ、と書き終わった今思いました(ぇー)。</p>
<h3>作成の経緯</h3>
<p>以前、拡張ハッシュ法の削除関数を実装している際に、キーをバケットに振り分ける際のアドレス算出の処理部分にデバッグプリントが欲しくて作ったものです。</p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/08/python-decimal-to-binary-conversion.html" rel="bookmark" title="2008年8月4日">Python: 10進数整数を2進数文字列に変換する関数</a></li>
<li><a href="http://www.yukun.info/blog/2008/02/check-syntax.html" rel="bookmark" title="2008年2月11日">3種類の括弧の対応をチェックするC言語プログラム</a></li>
<li><a href="http://www.yukun.info/blog/2008/06/opengl-circle.html" rel="bookmark" title="2008年6月20日">OpenGL: ポリゴンで円の描画</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html" rel="bookmark" title="2008年1月3日">X Window System 上での描画色の変更</a></li>
<li><a href="http://www.yukun.info/blog/2008/10/android-integer-to-binary-string.html" rel="bookmark" title="2008年10月29日">Android: 10進数→2進数変換アプリ</a></li>
</ul>
<p><!-- Similar Posts took 6.194 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/01/decimal-to-binary.html">10進数を2進数に変換表示するC言語プログラム</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/01/decimal-to-binary.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse+CDTを用いてプロジェクトを作成する際の注意点</title>
		<link>http://www.yukun.info/blog/2008/01/eclipse-cdt.html</link>
		<comments>http://www.yukun.info/blog/2008/01/eclipse-cdt.html#comments</comments>
		<pubDate>Thu, 10 Jan 2008 15:00:05 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[C language]]></category>
		<category><![CDATA[Setting]]></category>

		<guid isPermaLink="false">http://www.yukun.info/trump/20080111/eclipsecdt%e3%82%92%e7%94%a8%e3%81%84%e3%81%a6%e3%83%97%e3%83%ad%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b%e9%9a%9b%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9</guid>
		<description><![CDATA[以前、K-na TechNotes &#124; Homeのページを参考にWindowsでEclipse3.3とCDTをインストールしました。分かりやすく書かれており、とても参考になりました(謝々)。 たまたまK-na TechN &#8230; <a href="http://www.yukun.info/blog/2008/01/eclipse-cdt.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/01/eclipse-cdt.html">Eclipse+CDTを用いてプロジェクトを作成する際の注意点</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>以前、<a href="http://www.knatech.info/index.html" class="broken_link">K-na TechNotes | Home</a>のページを参考にWindowsでEclipse3.3とCDTをインストールしました。分かりやすく書かれており、とても参考になりました(謝々)。<br />
たまたま<a href="http://www.knatech.info/" class="broken_link">K-na TechNotes | CDT のトラブル対策</a>ページ下部にある</p>
<blockquote><p>＜実行＞を押しても、デバッグしても、必ず「アプリケーション・エラー 起動に失敗（バイナリ・ファイルがありません）」のメッセージが出ます。</p></blockquote>
<p>という件を見て、この症状の理由はProject typesの設定ミスではないかと推測しました。</p>
<p>解決方法は、まず上述のページを参照しながら、</p>
<ul>
<li>Cygwin か MinGWをインストール及びパスの設定をする</li>
<li>Eclipse(CDT)をインストールする</li>
<li>Eclipse上のバイナリパーサの設定等を行う(コンパイルで生成されるバイナリファイルをEclipseで認識させるため)</li>
</ul>
<p>ここまで出来れば使えるはず。<br />
早速プロジェクトを作成しましょう。</p>
<p>以下の画像はEclipse3.3ですが、Linuxパージョンである。だが、表示項目はWindowsのそれとほとんど変わりません。</p>
<h3>[ファイル]＞[新規]＞
<pre></pre>
<p>とクリック</h3>
<p><a href="http://www.yukun.info/wp-content/uploads/eclipseMakeProject.png"><img src="http://www.yukun.info/wp-content/uploads/eclipseMakeProject-e1273383845145.png" alt="Eclipse の C++ プロジェクト作成ウィザード画面" title="eclipseMakeProject" width="400" height="340" class="size-full wp-image-1551" /></a></p>
<p>以下の画面で適当なプロジェクト名を打ち込んだ後、Project typesを選択します。<span style="color:#CC0000;">ここで[実行可能]＞[Empty Project]を選択します</span>。Toochainの項目はLinux系なら[Linux GCC]であるし、上述の設定を行った場合のWindowsのToochainは[Cygwin GCC]を選択します。<br />
これで終了を押せば、問題なくコーディングでき、ビルド→実行となります。</p>
<h3>プロジェクトタイプ(Project types)の設定に注意</h3>
<p>ここで、[Makefile project]を選択した場合は、Makefileを作成しなければエラーになります。[static ライブラリー]を選択した場合はビルドしてもバイナリファイルは生成されないので注意です。</p>
<h3>雑感</h3>
<p>最近はC, C++, C#やJavaにしても統合開発環境があればコーディングやリーディングがしやすいです（ソースの規模にもよりますが）。これを使うことでの弊害も無いとは言えないですが、それはまた別の話で。<br />
<span style="color:#999999;">RubyやRails, PHPの開発ではどうなのかな。</span></p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/01/amateras-uml.html" rel="bookmark" title="2008年1月4日">JavaのソースコードからUMLのクラス図を作成</a></li>
<li><a href="http://www.yukun.info/blog/2010/04/setup-eclipse-64bit-android.html" rel="bookmark" title="2010年4月25日">Windows7 64bitにEclipseでAndroid開発環境をセットアップ</a></li>
<li><a href="http://www.yukun.info/blog/2009/02/netbeans-subversion-import-error.html" rel="bookmark" title="2009年2月12日">NetBeans から Subversion でコミットをする際のエラーの解決法の一例</a></li>
<li><a href="http://www.yukun.info/blog/2008/09/r-set-work-directory.html" rel="bookmark" title="2008年9月3日">Rで統計: 作業ディレクトリの設定と確認 &#8211; setwd()、getwd()関数</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/cygwin-cron.html" rel="bookmark" title="2008年1月8日">Cygwinでcronをインストール</a></li>
</ul>
<p><!-- Similar Posts took 10.889 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/01/eclipse-cdt.html">Eclipse+CDTを用いてプロジェクトを作成する際の注意点</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/01/eclipse-cdt.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>X Window System 上での描画色の変更</title>
		<link>http://www.yukun.info/blog/2008/01/x-window-system-color.html</link>
		<comments>http://www.yukun.info/blog/2008/01/x-window-system-color.html#comments</comments>
		<pubDate>Thu, 03 Jan 2008 13:52:48 +0000</pubDate>
		<dc:creator>yukun</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C language]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[X11]]></category>

		<guid isPermaLink="false">http://www.yukun.info/trump/20080103/x-window-system-%e4%b8%8a%e3%81%a7%e3%81%ae%e6%8f%8f%e7%94%bb%e8%89%b2%e3%81%ae%e5%a4%89%e6%9b%b4</guid>
		<description><![CDATA[先日X11/Xlib.h、X11/Xutil.hを用いてフラクタルを描画するプログラムを作成していた折、描画する図形を構成する線分の色を変えようと試みました。X Window Systemではあらかじめ定義されている色名 &#8230; <a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html">Continue reading <span class="meta-nav">&#8594;</span></a><p><a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html">X Window System 上での描画色の変更</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>先日X11/Xlib.h、X11/Xutil.hを用いてフラクタルを描画するプログラムを作成していた折、描画する図形を構成する線分の色を変えようと試みました。X Window Systemではあらかじめ定義されている色名があります。<br />
参考サイト：<a href="http://www.nobidome.org/pubdoc/Xrgb.html">X Window System X Window System rgb.txt sample</a><br />
しかし、今回は多くの色を扱うためRGB指定での描画色の変更を行います。まず、以下のような整数型のピクセル値を返す関数MyColorを作成します。</p>
<pre>
#include &lt;x11/Xlib.h&gt;
#include &lt;x11/Xutil.h&gt;

unsigned long MyColor(display, color)
     Display *display;
     char *color;
{
  Colormap cmap;
  XColor c0, c1;
  cmap = DefaultColormap(display, 0);
  XAllocNamedColor(display, cmap, color, &amp;c1, &amp;c0);
  return (c1.pixel);
}
</pre>
<p>引数colorに以下に示す書式に則ったRGB色を表す文字列を代入しピクセル値を得ます。</p>
<p><code>"rgb:<span style="color:#0000FF;">00/00/FF</span>"  (指定した色が青の場合)</code></p>
<p>ここで得られるピクセル値を<span style="color:#6666FF;">XSetForeground</span>関数に代入することでRGB値の指定による描画色の変更を行うことが出来ます。</p>
<p>RGB値指定が可能になることで表現できる色は飛躍的に増えますが、ソースプログラム中にいちいち値を指定した文字列を予め作成しておくのでは、少々非効率な面もあります。<br />
特にフラクタルのような再起関数を用いる場合、繰り返し回数は等比級数的に増す場合もあり、カラフルな図形の表現を行うには別の手法を試みる必要があります。<br />
そこで、上記のRGB値を指定する書式を自動生成する関数のプログラムを以下に示します。</p>
<pre>
#include &lt;stdio.h&gt;
#include &lt;string.h&gt; // for strdup()

// グローバル変数
char *comap[0x1000000]; // RGB形式のカラーマップ
int coindex = 0; // カラーマップ用パラメータ
int colimit = 0; // カラーマップの個数

// RGBカラーマップを生成
// iの可算度合は色のバラツキ度
void cremap()
{
  char str[16];
  int i, j;
  for(i=0, j=0; i&lt; =0xFFFFFF; i+=0x2888, j++) {
    sprintf(str, &quot;rgb:%02X/%02X/%02X&quot;,
      // i / 0xFFFF &amp; 0xFF, i / 0xFF &amp; 0xFF, i &amp; 0xFF); // チョイ非効率
      (i &gt;&gt; 16) &amp; 0xFF, (i &gt;&gt; 8) &amp; 0xFF, i &amp; 0xFF); // bit演算
    comap[j] = strdup(str);
    //puts(comap[i]);
    //printf(&quot;%d\n&quot;, i);
  }
  printf(&quot;%d\n&quot;, j);
  colimit = j; // 生成した色の数
  //exit(0);
}
</pre>
<p>sprintf関数を用いて書式を指定した文字列を生成することが出来ます。for ループのiの増分をi++に変更すれば0xFFFFFF色分のカラーマップを生成できます。ただし、このカラーマップの順序は少々とっぴで、パラメータj順に色を表示すると所所でカラージャンプがあるため、滑らかなグラデーションを生成したい場合はsprintfの引数の指定方法を変える必要があります。</p>
<p>最終的にはソースコード中で以下のように色を変更する一文を加えます。</p>
<p><code>XSetForeground(d,gc, MyColor(d, comap[lim(++coindex)]));</code></p>
<p>これによって生成されたフラクタル画像を下図に示します。左がイニシエータ、右がジェネレータ、中央が生成したフラクタル図形です。</p>
<p><a href="http://www.yukun.info/wp-content/uploads/fractal01s.png"><img src="http://www.yukun.info/wp-content/uploads/fractal01s-e1273384232231.png" alt="からふるフラクタル" title="fractal01s" width="400" height="205" class="size-full wp-image-1558" /></a></p>
<h4>関連すると思われる記事：</h4>
<ul class="similar-posts">
<li><a href="http://www.yukun.info/blog/2008/06/opengl-circle.html" rel="bookmark" title="2008年6月20日">OpenGL: ポリゴンで円の描画</a></li>
<li><a href="http://www.yukun.info/blog/2008/11/actionscript-flash-load-server-image-file.html" rel="bookmark" title="2008年11月21日">ActionScript: 画像ファイルをダウンロードして表示 &#8211; Loaderクラス</a></li>
<li><a href="http://www.yukun.info/blog/2008/01/eclipse-cdt.html" rel="bookmark" title="2008年1月11日">Eclipse+CDTを用いてプロジェクトを作成する際の注意点</a></li>
<li><a href="http://www.yukun.info/blog/2008/02/check-syntax.html" rel="bookmark" title="2008年2月11日">3種類の括弧の対応をチェックするC言語プログラム</a></li>
<li><a href="http://www.yukun.info/blog/2009/02/java-swing-jcomponent-drawing-line.html" rel="bookmark" title="2009年2月21日">Java, Swing: JComponentのGraphicsオブジェクトを用いて直線を描画</a></li>
</ul>
<p><!-- Similar Posts took 8.797 ms --></p>
<p><a href="http://www.yukun.info/blog/2008/01/x-window-system-color.html">X Window System 上での描画色の変更</a> is a post from: <a href="http://www.yukun.info">Yukun&#039;s Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yukun.info/blog/2008/01/x-window-system-color.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

