1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

くもん式の英語学習デバイス"E-Pencil"をハックする[2]

Last updated at Posted at 2020-01-17

実際にドットを配置して出力してみる

前回の続き。
1つの格子を64*64として、ドットの相対的な位置を以下のように定義した。

int data_pos[8][2] = {
     {18,18},	//0 左上
     {32,16},	//1 上
     {46,18},	//2 右上
     {16,32},	//3 左
     {48,32},	//4 右
     {18,46},	//5 左下
     {32,48},	//6 下
     {46,46},	//7 右下
};

これで3bitのデータを座標で表現出来るようになったので、
適当な3bitのデータ配列を用意して、9個の格子に格納してみる。

int data[9] = {0,1,2,3,4,5,6,7,0};
POINT DotPos[9];
for(int i=0; i<9; i++){
	int x = 64 * (i%3) + data_pos[data[i]][0];
	int y = 64 * (i/3) + data_pos[data[i]][1];
	DotPos[i].x = x;
	DotPos[i].y = y;
}

※ちゃんと実装するときには作った配列の外側を指定しないように注意する。

で、実際にドットを描くときには、64x64の相対位置から
実際に描きたい大きさのキャンバスに描画する。
今回はWin32APIのHDCを使ったので、円を描く関数Ellipseを使って、

	double scale = 2.5;
	int r = 7;
	for (int i = 0; i<9; i++) {
		int left   = (int)((DotPos[i].x - r) * scale);
		int top    = (int)((DotPos[i].y - r) * scale);
		int right  = (int)((DotPos[i].x + r) * scale);
		int bottom = (int)((DotPos[i].y + r) * scale);
		::Ellipse(hDC, left, top, right, bottom);
	}

のようにすれば、6464の格子に対して半径7の円を描くイメージになるが、
実際には2.5倍の160
160ピクセルに半径17.5(intにキャストされるので17)の円が描かれる。

キードットや格子ドットも描画するとこんな感じになる。
image.png

これで3*3の格子データが画像に出来るので、
これをx方向に7回、y方向に5回繰り返すことでオリジナルに近いドット画像が作れた。

image.png

簡易的にドットパターンジェネレーターを作ったので、
任意の9桁の整数(27bitコード)からドットパターンを生成できる。

印刷してみる

さて実際に印刷してみたわけだが…。
image.png

うーん、ドットが潰れてしまった。E-Pencilも反応なし。
この画像が約10.0mm * 7.0mmなので、相当細かいのは間違いないのだが、プリンターの限界なのだろうか?
しかしプリンターの公称スペックでは9600DPIで出せるはずなので、
プリンタに出力する側のソフトの問題かもしれない。

もう少し印刷環境を整えてから再チャレンジが必要と思われるので、
続きはまた今度ということに。なかなか進まない。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?