No.01 多角形とプログラムの制御

多角形を描くプログラムを作成しながら、プログラムの制御構造(順次処理、繰返処理、分岐処理)について説明します。

動画と同じものを自分のパソコンで試すには下記の「多角形とプログラムの制御構造のデータ.zip」をダウンロードしてください。

また「広々のびのびデジタル広場」ツールは「無料版ダウンロード」ページからダウンロードしてください。

多角形を描くプログラムも下記の載せておきます。



ダウンロード
多角形とプログラムの制御構造.zip
zip ( 圧縮 ) ファイル 17.2 KB

  1. 順次処理
  2. float wKakudo;
  3. float wKakudoTsuika;
  4. int   wSleepJikan;
  5. //三角形を描く
  6. KisekiNashiSettei();
  7. SetNewLocation(200, 400);
  8. KisekiColorSettei(System.Drawing.Color.Red);
  9. KisekiHabaSettei(2);
  10. KisekiAriSettei();
  11. wKakudo = 0;
  12. wKakudoTsuika = 360 / 3;
  13. wSleepJikan = 500;
  14. Thread.Sleep(wSleepJikan);
  15. wKakudo = wKakudo + wKakudoTsuika;
  16. MoveControl(100, wKakudo);
  17. Thread.Sleep(wSleepJikan);
  18. wKakudo = wKakudo + wKakudoTsuika;
  19. MoveControl(100, wKakudo);
  20. Thread.Sleep(wSleepJikan);
  21. wKakudo = wKakudo + wKakudoTsuika;
  22. MoveControl(100, wKakudo);
  23. KisekiNashiSettei();
  24. //四角形を描く
  25. KisekiNashiSettei();
  26. SetNewLocation(400, 400);
  27. KisekiColorSettei(System.Drawing.Color.Green);
  28. KisekiHabaSettei(4);
  29. KisekiAriSettei();
  30. wKakudo = 0;
  31. wKakudoTsuika = 360 / 4;
  32. wSleepJikan = 500;
  33. Thread.Sleep(wSleepJikan);
  34. wKakudo = wKakudo + wKakudoTsuika;
  35. MoveControl(100, wKakudo);
  36. Thread.Sleep(wSleepJikan);
  37. wKakudo = wKakudo + wKakudoTsuika;
  38. MoveControl(100, wKakudo);
  39. Thread.Sleep(wSleepJikan);
  40. wKakudo = wKakudo + wKakudoTsuika;
  41. MoveControl(100, wKakudo);
  42. Thread.Sleep(wSleepJikan);
  43. wKakudo = wKakudo + wKakudoTsuika;
  44. MoveControl(100, wKakudo);
  45. KisekiNashiSettei();
  46. //五角形を描く
  47. KisekiNashiSettei();
  48. SetNewLocation(650, 400);
  49. KisekiColorSettei(System.Drawing.Color.Blue);
  50. KisekiHabaSettei(6);
  51. KisekiAriSettei();
  52. wKakudo = 0;
  53. wKakudoTsuika = 360 / 5;
  54. wSleepJikan = 500;
  55. Thread.Sleep(wSleepJikan);
  56. wKakudo = wKakudo + wKakudoTsuika;
  57. MoveControl(100, wKakudo);
  58. Thread.Sleep(wSleepJikan);
  59. wKakudo = wKakudo + wKakudoTsuika;
  60. MoveControl(100, wKakudo);
  61. Thread.Sleep(wSleepJikan);
  62. wKakudo = wKakudo + wKakudoTsuika;
  63. MoveControl(100, wKakudo);
  64. Thread.Sleep(wSleepJikan);
  65. wKakudo = wKakudo + wKakudoTsuika;
  66. MoveControl(100, wKakudo);
  67. Thread.Sleep(wSleepJikan);
  68. wKakudo = wKakudo + wKakudoTsuika;
  69. MoveControl(100, wKakudo);
  70. KisekiNashiSettei();
  71. //六角形を描く
  72. KisekiNashiSettei();
  73. SetNewLocation(900, 400);
  74. KisekiColorSettei(System.Drawing.Color.Brown);
  75. KisekiHabaSettei(8);
  76. KisekiAriSettei();
  77. wKakudo = 0;
  78. wKakudoTsuika = 360 / 6;
  79. wSleepJikan = 500;
  80. Thread.Sleep(wSleepJikan);
  81. wKakudo = wKakudo + wKakudoTsuika;
  82. MoveControl(100, wKakudo);
  83. Thread.Sleep(wSleepJikan);
  84. wKakudo = wKakudo + wKakudoTsuika;
  85. MoveControl(100, wKakudo);
  86. Thread.Sleep(wSleepJikan);
  87. wKakudo = wKakudo + wKakudoTsuika;
  88. MoveControl(100, wKakudo);
  89. Thread.Sleep(wSleepJikan);
  90. wKakudo = wKakudo + wKakudoTsuika;
  91. MoveControl(100, wKakudo);
  92. Thread.Sleep(wSleepJikan);
  93. wKakudo = wKakudo + wKakudoTsuika;
  94. MoveControl(100, wKakudo);
  95. Thread.Sleep(wSleepJikan);
  96. wKakudo = wKakudo + wKakudoTsuika;
  97. MoveControl(100, wKakudo);
  98. KisekiNashiSettei();
  99. //七角形を描く
  100. KisekiNashiSettei();
  101. SetNewLocation(1200, 400);
  102. KisekiColorSettei(System.Drawing.Color.Gray);
  103. KisekiHabaSettei(10);
  104. KisekiAriSettei();
  105. wKakudo = 0;
  106. wKakudoTsuika = 360 / 7;
  107. wSleepJikan = 500;
  108. Thread.Sleep(wSleepJikan);
  109. wKakudo = wKakudo + wKakudoTsuika;
  110. MoveControl(100, wKakudo);
  111. Thread.Sleep(wSleepJikan);
  112. wKakudo = wKakudo + wKakudoTsuika;
  113. MoveControl(100, wKakudo);
  114. Thread.Sleep(wSleepJikan);
  115. wKakudo = wKakudo + wKakudoTsuika;
  116. MoveControl(100, wKakudo);
  117. Thread.Sleep(wSleepJikan);
  118. wKakudo = wKakudo + wKakudoTsuika;
  119. MoveControl(100, wKakudo);
  120. Thread.Sleep(wSleepJikan);
  121. wKakudo = wKakudo + wKakudoTsuika;
  122. MoveControl(100, wKakudo);
  123. Thread.Sleep(wSleepJikan);
  124. wKakudo = wKakudo + wKakudoTsuika;
  125. MoveControl(100, wKakudo);
  126. Thread.Sleep(wSleepJikan);
  127. wKakudo = wKakudo + wKakudoTsuika;
  128. MoveControl(100, wKakudo);
  129. KisekiNashiSettei();
  130. //三十六角形を描く
  131. KisekiNashiSettei();
  132. SetNewLocation(2000, 1000);
  133. KisekiColorSettei(System.Drawing.Color.Gold);
  134. KisekiHabaSettei(20);
  135. KisekiAriSettei();
  136. wKakudo = 0;
  137. wKakudoTsuika = 360 / 36;
  138. wSleepJikan = 0;
  139. Thread.Sleep(wSleepJikan);
  140. wKakudo = wKakudo + wKakudoTsuika;
  141. MoveControl(100, wKakudo);
  142. Thread.Sleep(wSleepJikan);
  143. wKakudo = wKakudo + wKakudoTsuika;
  144. MoveControl(100, wKakudo);
  145. Thread.Sleep(wSleepJikan);
  146. wKakudo = wKakudo + wKakudoTsuika;
  147. MoveControl(100, wKakudo);
  148. Thread.Sleep(wSleepJikan);
  149. wKakudo = wKakudo + wKakudoTsuika;
  150. MoveControl(100, wKakudo);
  151. Thread.Sleep(wSleepJikan);
  152. wKakudo = wKakudo + wKakudoTsuika;
  153. MoveControl(100, wKakudo);
  154. Thread.Sleep(wSleepJikan);
  155. wKakudo = wKakudo + wKakudoTsuika;
  156. MoveControl(100, wKakudo);
  157. Thread.Sleep(wSleepJikan);
  158. wKakudo = wKakudo + wKakudoTsuika;
  159. MoveControl(100, wKakudo);
  160. Thread.Sleep(wSleepJikan);
  161. wKakudo = wKakudo + wKakudoTsuika;
  162. MoveControl(100, wKakudo);
  163. Thread.Sleep(wSleepJikan);
  164. wKakudo = wKakudo + wKakudoTsuika;
  165. MoveControl(100, wKakudo);
  166. Thread.Sleep(wSleepJikan);
  167. wKakudo = wKakudo + wKakudoTsuika;
  168. MoveControl(100, wKakudo);
  169. Thread.Sleep(wSleepJikan);
  170. wKakudo = wKakudo + wKakudoTsuika;
  171. MoveControl(100, wKakudo);
  172. Thread.Sleep(wSleepJikan);
  173. wKakudo = wKakudo + wKakudoTsuika;
  174. MoveControl(100, wKakudo);
  175. Thread.Sleep(wSleepJikan);
  176. wKakudo = wKakudo + wKakudoTsuika;
  177. MoveControl(100, wKakudo);
  178. Thread.Sleep(wSleepJikan);
  179. wKakudo = wKakudo + wKakudoTsuika;
  180. MoveControl(100, wKakudo);
  181. Thread.Sleep(wSleepJikan);
  182. wKakudo = wKakudo + wKakudoTsuika;
  183. MoveControl(100, wKakudo);
  184. Thread.Sleep(wSleepJikan);
  185. wKakudo = wKakudo + wKakudoTsuika;
  186. MoveControl(100, wKakudo);
  187. Thread.Sleep(wSleepJikan);
  188. wKakudo = wKakudo + wKakudoTsuika;
  189. MoveControl(100, wKakudo);
  190. Thread.Sleep(wSleepJikan);
  191. wKakudo = wKakudo + wKakudoTsuika;
  192. MoveControl(100, wKakudo);
  193. Thread.Sleep(wSleepJikan);
  194. wKakudo = wKakudo + wKakudoTsuika;
  195. MoveControl(100, wKakudo);
  196. Thread.Sleep(wSleepJikan);
  197. wKakudo = wKakudo + wKakudoTsuika;
  198. MoveControl(100, wKakudo);
  199. Thread.Sleep(wSleepJikan);
  200. wKakudo = wKakudo + wKakudoTsuika;
  201. MoveControl(100, wKakudo);
  202. Thread.Sleep(wSleepJikan);
  203. wKakudo = wKakudo + wKakudoTsuika;
  204. MoveControl(100, wKakudo);
  205. Thread.Sleep(wSleepJikan);
  206. wKakudo = wKakudo + wKakudoTsuika;
  207. MoveControl(100, wKakudo);
  208. Thread.Sleep(wSleepJikan);
  209. wKakudo = wKakudo + wKakudoTsuika;
  210. MoveControl(100, wKakudo);
  211. Thread.Sleep(wSleepJikan);
  212. wKakudo = wKakudo + wKakudoTsuika;
  213. MoveControl(100, wKakudo);
  214. Thread.Sleep(wSleepJikan);
  215. wKakudo = wKakudo + wKakudoTsuika;
  216. MoveControl(100, wKakudo);
  217. Thread.Sleep(wSleepJikan);
  218. wKakudo = wKakudo + wKakudoTsuika;
  219. MoveControl(100, wKakudo);
  220. Thread.Sleep(wSleepJikan);
  221. wKakudo = wKakudo + wKakudoTsuika;
  222. MoveControl(100, wKakudo);
  223. Thread.Sleep(wSleepJikan);
  224. wKakudo = wKakudo + wKakudoTsuika;
  225. MoveControl(100, wKakudo);
  226. Thread.Sleep(wSleepJikan);
  227. wKakudo = wKakudo + wKakudoTsuika;
  228. MoveControl(100, wKakudo);
  229. Thread.Sleep(wSleepJikan);
  230. wKakudo = wKakudo + wKakudoTsuika;
  231. MoveControl(100, wKakudo);
  232. Thread.Sleep(wSleepJikan);
  233. wKakudo = wKakudo + wKakudoTsuika;
  234. MoveControl(100, wKakudo);
  235. Thread.Sleep(wSleepJikan);
  236. wKakudo = wKakudo + wKakudoTsuika;
  237. MoveControl(100, wKakudo);
  238. Thread.Sleep(wSleepJikan);
  239. wKakudo = wKakudo + wKakudoTsuika;
  240. MoveControl(100, wKakudo);
  241. Thread.Sleep(wSleepJikan);
  242. wKakudo = wKakudo + wKakudoTsuika;
  243. MoveControl(100, wKakudo);
  244. Thread.Sleep(wSleepJikan);
  245. wKakudo = wKakudo + wKakudoTsuika;
  246. MoveControl(100, wKakudo);
  247. KisekiNashiSettei();
  248. SetNewLocation(200, 100);

  1. 繰返処理
  2. float wKakudo;
  3. float wKakudoTsuika;
  4. int   wSleepJikan;
  5. //三角形を描く
  6. KisekiNashiSettei();
  7. SetNewLocation(200, 600);
  8. KisekiColorSettei(System.Drawing.Color.Red);
  9. KisekiHabaSettei(2);
  10. KisekiAriSettei();
  11. wKakudo = 0;
  12. wKakudoTsuika = 360 / 3;
  13. wSleepJikan = 500;    
  14. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 3; wKurikaeshiSuu++)
  15. {
  16.     Thread.Sleep(wSleepJikan);
  17.     wKakudo = wKakudo + wKakudoTsuika;
  18.     MoveControl(100, wKakudo);
  19. }
  20. KisekiNashiSettei();
  21. //四角形を描く
  22. KisekiNashiSettei();
  23. SetNewLocation(400, 600);
  24. KisekiColorSettei(System.Drawing.Color.Green);
  25. KisekiHabaSettei(4);
  26. KisekiAriSettei();
  27. wKakudo = 0;
  28. wKakudoTsuika = 360 / 4;
  29. wSleepJikan = 500;    
  30. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 4; wKurikaeshiSuu++)
  31. {
  32.     Thread.Sleep(wSleepJikan);
  33.     wKakudo = wKakudo + wKakudoTsuika;
  34.     MoveControl(100, wKakudo);
  35. }
  36. KisekiNashiSettei();
  37. //五角形を描く
  38. KisekiNashiSettei();
  39. SetNewLocation(650, 600);
  40. KisekiColorSettei(System.Drawing.Color.Blue);
  41. KisekiHabaSettei(6);
  42. KisekiAriSettei();
  43. wKakudo = 0;
  44. wKakudoTsuika = 360 / 5;
  45. wSleepJikan = 500;    
  46. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 5; wKurikaeshiSuu++)
  47. {
  48.     Thread.Sleep(wSleepJikan);
  49.     wKakudo = wKakudo + wKakudoTsuika;
  50.     MoveControl(100, wKakudo);
  51. }
  52. KisekiNashiSettei();
  53. //六角形を描く
  54. KisekiNashiSettei();
  55. SetNewLocation(900, 600);
  56. KisekiColorSettei(System.Drawing.Color.Brown);
  57. KisekiHabaSettei(8);
  58. KisekiAriSettei();
  59. wKakudo = 0;
  60. wKakudoTsuika = 360 / 6;
  61. wSleepJikan = 500;    
  62. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 6; wKurikaeshiSuu++)
  63. {
  64.     Thread.Sleep(wSleepJikan);
  65.     wKakudo = wKakudo + wKakudoTsuika;
  66.     MoveControl(100, wKakudo);
  67. }
  68. KisekiNashiSettei();
  69. //七角形を描く
  70. KisekiNashiSettei();
  71. SetNewLocation(1200, 600);
  72. KisekiColorSettei(System.Drawing.Color.Gray);
  73. KisekiHabaSettei(10);
  74. KisekiAriSettei();
  75. wKakudo = 0;
  76. wKakudoTsuika = 360 / 7;
  77. wSleepJikan = 500;    
  78. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 7; wKurikaeshiSuu++)
  79. {
  80.     Thread.Sleep(wSleepJikan);
  81.     wKakudo = wKakudo + wKakudoTsuika;
  82.     MoveControl(100, wKakudo);
  83. }
  84. KisekiNashiSettei();
  85. //三十六角形を描く
  86. KisekiNashiSettei();
  87. SetNewLocation(2000, 1200);
  88. KisekiColorSettei(System.Drawing.Color.Gold);
  89. KisekiHabaSettei(20);
  90. KisekiAriSettei();
  91. wKakudo = 0;
  92. wKakudoTsuika = 360 / 36;
  93. wSleepJikan = 0;    
  94. for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < 36; wKurikaeshiSuu++)
  95. {
  96.     Thread.Sleep(wSleepJikan);
  97.     wKakudo = wKakudo + wKakudoTsuika;
  98.     MoveControl(100, wKakudo);
  99. }
  100. KisekiNashiSettei();
  101. SetNewLocation(400, 100);

  1. 分岐処理
  2. float wKakudo;
  3. float wKakudoTsuika;
  4. int   wSleepJikan;
  5. //多角形を描く
  6. for (int wNankakkei = 0; wNankakkei < 100; wNankakkei++)
  7. {
  8.     if ((wNankakkei >= 3 && wNankakkei <= 7) ||
  9.         wNankakkei == 36                       )
  10.     {
  11.         KisekiNashiSettei();
  12.         if (wNankakkei == 3)
  13.         {
  14.             SetNewLocation(200, 800);
  15.             KisekiColorSettei(System.Drawing.Color.Red);
  16.             KisekiHabaSettei(2);
  17.             wSleepJikan = 500;    
  18.         }
  19.         if (wNankakkei == 4)
  20.         {
  21.             SetNewLocation(400, 800);
  22.             KisekiColorSettei(System.Drawing.Color.Green);
  23.             KisekiHabaSettei(4);
  24.             wSleepJikan = 500;    
  25.         }
  26.         if (wNankakkei == 5)
  27.         {
  28.             SetNewLocation(650, 800);
  29.             KisekiColorSettei(System.Drawing.Color.Blue);
  30.             KisekiHabaSettei(6);
  31.             wSleepJikan = 500;    
  32.         }
  33.         if (wNankakkei == 6)
  34.         {
  35.             SetNewLocation(900, 800);
  36.             KisekiColorSettei(System.Drawing.Color.Brown);
  37.             KisekiHabaSettei(8);
  38.             wSleepJikan = 500;    
  39.        }    
  40.         if (wNankakkei == 7)
  41.         {
  42.             SetNewLocation(1200, 800);
  43.             KisekiColorSettei(System.Drawing.Color.Gray);
  44.             KisekiHabaSettei(10);
  45.             wSleepJikan = 500;    
  46.         }        
  47.         if (wNankakkei == 36)
  48.         {
  49.             SetNewLocation(2000, 1400);
  50.             KisekiColorSettei(System.Drawing.Color.Gold);
  51.             KisekiHabaSettei(20);
  52.             wSleepJikan = 0;    
  53.         }       
  54.     }
  55.     else
  56.     {
  57.         continue;
  58.     }        
  59.      
  60.     KisekiAriSettei();
  61.     wKakudo = 0;
  62.     wKakudoTsuika = 360 / wNankakkei;
  63.     for (int wKurikaeshiSuu = 0; wKurikaeshiSuu < wNankakkei; wKurikaeshiSuu++)
  64.     {
  65.         Thread.Sleep(wSleepJikan);
  66.         wKakudo = wKakudo + wKakudoTsuika;
  67.         MoveControl(100, wKakudo);
  68.     }
  69.     KisekiNashiSettei();
  70. }
  71. SetNewLocation(600, 100);