多角形を描くプログラムを作成しながら、プログラムの制御構造(順次処理、繰返処理、分岐処理)について説明します。
動画と同じものを自分のパソコンで試すには下記の「多角形とプログラムの制御構造のデータ.zip」をダウンロードしてください。
また「広々のびのびデジタル広場」ツールは「無料版ダウンロード」ページからダウンロードしてください。
多角形を描くプログラムも下記の載せておきます。
- 順次処理
- float wKakudo;
- float wKakudoTsuika;
- int wSleepJikan;
- //三角形を描く
- KisekiNashiSettei();
- SetNewLocation(200, 400);
- KisekiColorSettei(System.Drawing.Color.Red);
- KisekiHabaSettei(2);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 3;
- wSleepJikan = 500;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- //四角形を描く
- KisekiNashiSettei();
- SetNewLocation(400, 400);
- KisekiColorSettei(System.Drawing.Color.Green);
- KisekiHabaSettei(4);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 4;
- wSleepJikan = 500;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- //五角形を描く
- KisekiNashiSettei();
- SetNewLocation(650, 400);
- KisekiColorSettei(System.Drawing.Color.Blue);
- KisekiHabaSettei(6);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 5;
- wSleepJikan = 500;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- //六角形を描く
- KisekiNashiSettei();
- SetNewLocation(900, 400);
- KisekiColorSettei(System.Drawing.Color.Brown);
- KisekiHabaSettei(8);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 6;
- wSleepJikan = 500;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- //七角形を描く
- KisekiNashiSettei();
- SetNewLocation(1200, 400);
- KisekiColorSettei(System.Drawing.Color.Gray);
- KisekiHabaSettei(10);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 7;
- wSleepJikan = 500;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- //三十六角形を描く
- KisekiNashiSettei();
- SetNewLocation(2000, 1000);
- KisekiColorSettei(System.Drawing.Color.Gold);
- KisekiHabaSettei(20);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 36;
- wSleepJikan = 0;
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- KisekiNashiSettei();
- SetNewLocation(200, 100);
- 繰返処理
- float wKakudo;
- float wKakudoTsuika;
- int wSleepJikan;
- //三角形を描く
- KisekiNashiSettei();
- SetNewLocation(200, 600);
- KisekiColorSettei(System.Drawing.Color.Red);
- KisekiHabaSettei(2);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 3;
- wSleepJikan = 500;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 3; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- //四角形を描く
- KisekiNashiSettei();
- SetNewLocation(400, 600);
- KisekiColorSettei(System.Drawing.Color.Green);
- KisekiHabaSettei(4);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 4;
- wSleepJikan = 500;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 4; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- //五角形を描く
- KisekiNashiSettei();
- SetNewLocation(650, 600);
- KisekiColorSettei(System.Drawing.Color.Blue);
- KisekiHabaSettei(6);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 5;
- wSleepJikan = 500;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 5; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- //六角形を描く
- KisekiNashiSettei();
- SetNewLocation(900, 600);
- KisekiColorSettei(System.Drawing.Color.Brown);
- KisekiHabaSettei(8);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 6;
- wSleepJikan = 500;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 6; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- //七角形を描く
- KisekiNashiSettei();
- SetNewLocation(1200, 600);
- KisekiColorSettei(System.Drawing.Color.Gray);
- KisekiHabaSettei(10);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 7;
- wSleepJikan = 500;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 7; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- //三十六角形を描く
- KisekiNashiSettei();
- SetNewLocation(2000, 1200);
- KisekiColorSettei(System.Drawing.Color.Gold);
- KisekiHabaSettei(20);
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / 36;
- wSleepJikan = 0;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 36; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- SetNewLocation(400, 100);
- 分岐処理
- float wKakudo;
- float wKakudoTsuika;
- int wSleepJikan;
- //多角形を描く
- for (int wNankakkei = 0; wNankakkei < 100; wNankakkei++)
- {
- if ((wNankakkei >= 3 && wNankakkei <= 7) ||
- wNankakkei == 36 )
- {
- KisekiNashiSettei();
- if (wNankakkei == 3)
- {
- SetNewLocation(200, 800);
- KisekiColorSettei(System.Drawing.Color.Red);
- KisekiHabaSettei(2);
- wSleepJikan = 500;
- }
- if (wNankakkei == 4)
- {
- SetNewLocation(400, 800);
- KisekiColorSettei(System.Drawing.Color.Green);
- KisekiHabaSettei(4);
- wSleepJikan = 500;
- }
- if (wNankakkei == 5)
- {
- SetNewLocation(650, 800);
- KisekiColorSettei(System.Drawing.Color.Blue);
- KisekiHabaSettei(6);
- wSleepJikan = 500;
- }
- if (wNankakkei == 6)
- {
- SetNewLocation(900, 800);
- KisekiColorSettei(System.Drawing.Color.Brown);
- KisekiHabaSettei(8);
- wSleepJikan = 500;
- }
- if (wNankakkei == 7)
- {
- SetNewLocation(1200, 800);
- KisekiColorSettei(System.Drawing.Color.Gray);
- KisekiHabaSettei(10);
- wSleepJikan = 500;
- }
- if (wNankakkei == 36)
- {
- SetNewLocation(2000, 1400);
- KisekiColorSettei(System.Drawing.Color.Gold);
- KisekiHabaSettei(20);
- wSleepJikan = 0;
- }
- }
- else
- {
- continue;
- }
- KisekiAriSettei();
- wKakudo = 0;
- wKakudoTsuika = 360 / wNankakkei;
- for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < wNankakkei; wKurikaeshiSuu++)
- {
- Thread.Sleep(wSleepJikan);
- wKakudo = wKakudo + wKakudoTsuika;
- MoveControl(100, wKakudo);
- }
- KisekiNashiSettei();
- }
- SetNewLocation(600, 100);