自宅で始めるScratchで簡単に説明しましたが、さらに詳しいことを学んで頂きたいので、Scratchの連載を開始します。
前回は、調べるブロックの説明を行いました。
今回は演算ブロック(プログラム)を紹介しながら説明を行います。
演算ブロック
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator.png)
演算ブロックは他のブロックの中にいれて使うブロックになります。
たす、ひく、かける、わる
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_03.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_06.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_08.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_11.png)
四則演算が使用できます。
5+6を足してみてましょう。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/add.png)
そして、足した答えをネコに言ってもらいましょう。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_add.gif)
1から10までの乱数
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_13.png)
1から10までの数を得ることが出来ます。
ボタンを押すたびに1から10が選ばれることを確認しましょう。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/random.png)
ネコがランダムな数値を話します。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_random.gif)
より小さい、より大きい、と同じ
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_16.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_18.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_19.png)
これらのブロックは、制御ブロックに使用することが多いです。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/greater.png)
先ほどの乱数ブロックを使用して、ボタンを押したときの数値によって言葉を変えることができます。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_greater.gif)
かつ、または、ではない
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_21.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_23.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_25.png)
より小さい、より大きい、と同じと組み合わせて使うことが多いブロックです。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/and.png)
移動した際にネコの位置を判断しています。
ネコの位置がX、Yともに0以下であれば、うちがわと言うようにしています。
座標は少し難しいので、親御様がお子様に教えてあげてください。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_and.gif)
りんごとバナナ、りんごの1番目の文字、りんごの長さ、りんごにりが含まれる
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_28.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_30.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_32.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_34.png)
こちらのブロックは他の演算ブロックと異なり文字が使えます。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/string.png)
このようにすれば、質問の答えを文字を接続できます。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_string.gif)
○を○で割ったあまり、を四捨五入
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_37.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_39.png)
こちらは四則演算に似ていますが、割り算の余りを求めたり、四捨五入したりできます。
の絶対値、切り下げ、切り上げ…
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/operator_blocks_42.png)
絶対値はマイナスの値が出ても、そのマイナスを取り除いた値を得ることができます。
他にも中学で出てくるSIN、COSなども選択できます。
少し難しいかもしれませんが、絶対値はこのようにすれば結果がわかりやすいと思います。
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/absolute.png)
![operator](https://dk.cheerup.jp/wp-content/uploads/2022/02/cat_absolute.gif)
この例ではプラスの値しか出てきません。
まとめ
今回は、演算ブロックをご紹介しました。少し複雑なことが出来るようになりますが、
算数の知識も必要になってきます。
次回は、「変数ブロック」を取り上げる予定です。