You are on page 1of 3

1501100: Introduction to IT (English)

Spring 2023-24
Lab 4: Visual Programming – Repetition
Objectives: Use loops to repeat blocks multiple times.

LOOPS (Control):

1) repeat block: Repeats the blocks under it a specific number of times.

2) forever block: Repeats the blocks over and over until the Stop button is clicked.

Part A
Activity A-1:
PATTERN OF HEXAGONS Video Link

Create a project using the Crystal which will use a Pen to draw a hexagon [side length = 80]
360
A hexagon has 6 sides of equal length with 6 equal angles. Each angle is 60 degrees [ = 60]
6
To draw the first side, add move block with 80 steps. Then, turn 60 degrees clockwise.

Repeat the same process. Draw the 6 sides using the repeat block:
For the pattern: Ask the user to enter the number of hexagons in the pattern.
All hexagons will be the same size (length = 80 and angle = 60)
Step 1: When the sprite is clicked,

− Switch costume to crystal-b


− Set pen color to any light color visible on the dark backdrop (Stars)
− Go to the center of the stage, point in the right direction and clear the stage. Put pen down.
− Ask the user to: “Enter the number of hexagons in the pattern: ”
Step 2: Start drawing the hexagon pattern

− Repeat the following process answer times (given by user). For each hexagon, do:

o Draw the hexagon with 6 sides of length 80 with turns of 60 degrees in the clockwise
direction (wait for 0.2 seconds between each side). Use Repeat here as well.
o
360
o Turn degrees after drawing each hexagon (to form a circular pattern)
𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎

o Wait for 0.5 seconds after each hexagon is drawn


Activity A-2:

Modify Activity A-2 from Lab 3 (check if student passed or failed the course) as follows:
- Repeat the process for each student taking the course
- When the sprite is clicked, ask the user for the total number of students

- Use the repeat block to ask user for each student’s mark and display the result (passed or failed)
for 1.5 seconds.

You might also like