ページへ戻る

+ Links

 印刷 

blike​/intro​/demos :: OSASK計画

osaskwiki:blike/intro/demos

blikeのデモ anchor.png

  • (by K, 2011.02.16)

  • blikeを使えば、これくらいのものがこれくらいの行数、これくらいのプログラムの難易度で作れますという例。配列とかポインタとかをできるだけ使わないようにしています。
    • でも配列は使っている例もあります。
  • もちろん他のもっと便利な言語を使えばこれより短くかけるかもしれませんが、C言語だけでここまでできるのは教えやすいのではないかと。しかも環境依存なしで。
Page Top

test002a (6行) anchor.png

http://osask.net/w/gate.php/test002a.jpg?way=attach&_noumb&refer=blike%2Fintro%2Fdemos&openfile=test002a.jpg

int x, y;
openWin(256, 256);
for (y = 0; y < 256; y++) {
    for (x = 0; x < 256; x++)
        setPix(x, y, rgb(x, y, 0));
}
Page Top

boxes00a (6行) anchor.png

http://osask.net/w/gate.php/boxes00a.jpg?way=attach&_noumb&refer=blike%2Fintro%2Fdemos&openfile=boxes00a.jpg

int i;
setCol(0x0000ff);
setBCol(0xc6c6c6);
openWin(160, 144);
for (i = 0; i <= 60; i += 3)
    drawRect(19 + i * 2, 139 - i * 2, 71 - i, 3 + i);
Page Top

bball00a (30行) anchor.png

http://osask.net/w/gate.php/bball00a.jpg?way=attach&_noumb&refer=blike%2Fintro%2Fdemos&openfile=bball00a.jpg

struct POINT {
    int x, y;
};
static struct POINT t[16] = {
    { 196, 100 }, { 187,  61 }, { 164,  29 }, { 129,   9 }, {  90,   5 },
    {  53,  17 }, {  23,  44 }, {   7,  81 }, {   7, 119 }, {  23, 156 },
    {  53, 183 }, {  90, 195 }, { 129, 191 }, { 164, 171 }, { 187, 139 },
    { 196, 100 }
};
static int c[8] = {
    0x000000, 0xff0000, 0x00ff00, 0xffff00,
    0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
};
int i, j, d;

openWin(200, 200);
setMode(BL_POR);
for (i = 0; i <= 14; i++) {
    for (j = i + 1; j <= 15; j++) {
        d = j - i; /* 2つの点の距離 */
        if (d >= 8) d = 15 - dis; /* 逆回りに数える */
        if (d != 0) {
            setCol(c[8 - d]);
            if (t[i].x <= t[j].x)
                drawLine(t[i].x, t[i].y, t[j].x, t[j].y);
            else
                drawLine(t[j].x, t[j].y, t[i].x, t[i].y);
        }
    }
}
  • 構造体を使わないでも書けますし、そのほうが行数は減りますが、読みにくくなるような気がするので、このままにしておきます。
Page Top

test005a (9行) anchor.png

http://osask.net/w/gate.php/test005a.jpg?way=attach&_noumb&refer=blike%2Fintro%2Fdemos&openfile=test005a.jpg

int x, y;
openWin(256, 256);
for (y = 0; y < 256; y++) {
    for (x = 0; x < 256; x++)
        setPix(x, y, rgb(x, y, 0));
}
locate(13, 8);
color(7, 0);
printf("hello");
  • このようにグラフィックの上に普通にprintfできます(重ねあわせが美しくはないですが)。今までのprintfの知識をむだにすることはありません。
    • ピクセル単位で表示位置を指定できて、大きさも指定できて、さらに重ねあわせが問題ない文字列描画関数drawStrもあります。
  • このようなテキストとグラフィックの混在を許すので、学習者がステップアップしやすくなっています。

  • いろいろ書きましたが、どれもBASICでは何十年も前からできたことばかりです。つまり昔当たり前にできたことをまたできるようにしただけのことです。

Last-modified: 2011-02-16 (水) 00:00:00 (JST) (111d) by lina