- 追加された行はこの色です。
- 削除された行はこの色です。
[[2005/C2/どみ]]
*文字を書くロボット [#mefc2a60]
*書道ロボット [#mefc2a60]
#define TURN_TIME 148/90°曲がる時間
sub go_fwd() {/前に進む
#define TURN_TIME 148 //90°曲がる時間
sub go_fwd() { //前進
OnFwd(OUT_A+OUT_C);
}
sub go_rev() {
sub go_rev() { //後進
OnRev(OUT_A+OUT_C);
}
sub turn_right() {
sub turn_right() { //右回転
OnFwd(OUT_A);
OnRev(OUT_C);
}
sub turn_left() { //左回転
OnFwd(OUT_C);
OnRev(OUT_A);
}
sub stop_ac() { //停止
Off(OUT_A+OUT_C);
Wait(50);
}
sub pen_down() { //ペンを下げる
OnFwd(OUT_B);
Wait(18);
Off(OUT_B);
Wait(50);
}
sub pen_up() { //ペンを上げる
OnRev(OUT_B);
Wait(10);
Off(OUT_B);
Wait(50);
}
task main() {
pen_down(); //1画目
OnFwd(OUT_A);
Wait(120);
stop_ac();
pen_up();
go_fwd();
Wait(40);
stop_ac();
turn_left();
Wait(140);
stop_ac();
go_rev();
Wait(80);
stop_ac();
pen_down(); //2画目
go_fwd();
Wait(100);
stop_ac();
pen_up();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(60);
stop_ac();
pen_down(); //3画目
go_fwd();
Wait(45);
stop_ac();
pen_up();
go_fwd();
Wait(25);
stop_ac();
turn_left();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(75);
stop_ac();
pen_down(); //4画目(1)
go_fwd();
Wait(55);
stop_ac();
pen_up();
go_fwd();
Wait(75);
stop_ac();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(75);
stop_ac();
pen_down(); //4画目(2)
go_fwd();
Wait(45);
stop_ac();
pen_up();
go_fwd();
Wait(70);
stop_ac();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(20);
stop_ac();
pen_down(); //5画目
go_rev();
Wait(55);
stop_ac();
pen_up();
}
sub turn_left() {
OnFwd(OUT_C);
OnRev(OUT_A);
}
「右」と書きます。「口」の部分を合わせるのに苦労。結構微妙なものが出来た気がする。あと、動作ごとにいちいち止まる必要もなかったかな。
sub stop_ac() {
Off(OUT_A+OUT_C);
Wait(50);
}
コメントをどうぞ
-ほんとプログラムって難しいよね。でも初めから全てをプログラミングするより一つの動作を完璧にしてから積み上げるようにしてプログラミングするとうまくいくよ -- [[ジブリ大好き]] &new{2005-11-11 (金) 19:12:08};
-コメント文は / でなくて // で始めてください。サブルーチンよりも関数を使ったほうが便利だったかな? -- [[松本(教員)]] &new{2005-11-11 (金) 22:56:52};
-コメント文修正しました。Linuxは文字入力がやりづらくて… -- [[どみ]] &new{2005-11-21 (月) 15:00:45};
-工夫したところ、感想なども書いて自己評価してみましょう。 -- [[かとりーぬ(TA)]] &new{2005-11-25 (金) 19:32:34};
sub pen_down() {
OnFwd(OUT_B);
Wait(18);
Off(OUT_B);
Wait(50);
}
#comment
sub pen_up() {
OnRev(OUT_B);
Wait(10);
Off(OUT_B);
Wait(50);
}
task main() {
//1
pen_down();
OnFwd(OUT_A);
Wait(120);
stop_ac();
pen_up();
go_fwd();
Wait(40);
stop_ac();
turn_left();
Wait(140);
stop_ac();
go_rev();
Wait(80);
stop_ac();
//2
pen_down();
go_fwd();
Wait(100);
stop_ac();
pen_up();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(60);
stop_ac();
//3
pen_down();
go_fwd();
Wait(45);
stop_ac();
pen_up();
go_fwd();
Wait(25);
stop_ac();
turn_left();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(75);
stop_ac();
//4-1
pen_down();
go_fwd();
Wait(55);
stop_ac();
pen_up();
go_fwd();
Wait(75);
stop_ac();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(75);
stop_ac();
//4-2
pen_down();
go_fwd();
Wait(45);
stop_ac();
pen_up();
go_fwd();
Wait(70);
stop_ac();
turn_right();
Wait(TURN_TIME);
stop_ac();
go_rev();
Wait(20);
stop_ac();
//5
pen_down();
go_rev();
Wait(55);
stop_ac();
pen_up();
}