Clock block programming

    The clock on the wall of the house is ticking, and there are hour, minute and second hands inside. In the clock dial, the second hand completes one circle every 60 seconds, that is, the minimum angle of the second hand is 360/60 = 6°; the minute hand completes one cycle every 60 minutes, that is, the minimum angle of the minute hand is 360/60 = 6°; After 12 hours, after one week, the minimum angle of the instant needle is 360/12 = 30°.

    The following is an introduction to drawing a dynamic clock in Scratch.

1. Define the "dial" building block

Figure (1) Defining the "Dial" building block

Figure (2) "Dial" block code

2. Define the "tick mark" building block

Figure (3) Define the "tick mark" building block

Figure (4) "Tick mark" building block code

3. Define 3 roles

3.1 The role of the second hand

  • Click Scratch --> select a character --> draw --> shape --> line segment
  • Manually draw a horizontal straight second hand in Scratch;
  • Let its left end coincide with the center point of the canvas;
  • The line width is 8, and the color is red, as shown in Figure (5);
  • Define the movement code of the second hand, as shown in Figure (6).
Figure (5) Draw the role of the second hand

Figure (6) Movement code of the second hand

3.2 Minute hand role

  • Click Scratch --> select a character --> draw --> shape --> line segment
  • Manually draw a horizontal straight minute hand in Scratch;
  • Let its left end coincide with the center point of the canvas;
  • The line width is 8, and the color is light yellow, as shown in Figure (7);
  • Define the movement code of the minute hand, as shown in Figure (8).
Figure (7) Draw the role of the minute hand

Figure (8) The movement code of the minute hand

3.3 Hour hand role

  • Click Scratch --> select a character --> draw --> shape --> line segment
  • Manually draw a horizontal straight hour hand in Scratch;
  • Let its left end coincide with the center point of the canvas;
  • The line width is 12 and the color is dark yellow, as shown in Figure (9);
  • Define the movement code of the hour hand, as shown in Figure (10).
Figure (9) Draw the hour hand role

Figure (10) Hour hand movement code

4. Define the angle variable

    Click [Variable] on the left side of Scratch --> Create a variable --> Angle

5. Main function

Figure (11) Main function

    The effect is as follows:

Figure (12) Hour hand effect diagram

Guess you like

Origin blog.csdn.net/sanqima/article/details/113813316