Cấp độ: beginner25 phútminMiễn phíFreeCreative ExplorerCreative Explorer

Nhân vật Scratch đầu tiênYour first Scratch character

Nhân vật biết chào và di chuyểnA character that greets and moves

Bạn sẽ học gìWhat you will learn

  • Tạo sprite và thêm backdropCreate a sprite and add a backdrop
  • Dùng khối when flag clickedUse when flag clicked block
  • Lập trình nhân vật nói và di chuyểnProgram character to speak and move

Bạn sẽ tạo gìWhat you will build

Nhân vật biết chào và di chuyểnA character that greets and moves

Nội dung bài họcLesson content

Scratch là gì?What is Scratch?

Scratch là một ngôn ngữ lập trình hình ảnh do MIT tạo ra dành cho người mới bắt đầu. Thay vì gõ chữ, bạn kéo thả các khối lệnh màu sắc để tạo chương trình. Scratch miễn phí và chạy trên trình duyệt tại scratch.mit.edu.Scratch is a visual programming language created by MIT for beginners. Instead of typing, you drag and drop colorful blocks to create programs. Scratch is free and runs in your browser at scratch.mit.edu.

Sprite và BackdropSprites and Backdrops

Sprite là nhân vật trong Scratch — có thể là con mèo, con chó, hoặc bất kỳ hình ảnh nào. Backdrop là hình nền phía sau nhân vật. Mỗi dự án Scratch có ít nhất 1 sprite và 1 backdrop. Bạn có thể thêm sprite từ thư viện hoặc vẽ riêng.A sprite is a character in Scratch — it can be a cat, dog, or any image. A backdrop is the background behind the character. Each Scratch project has at least 1 sprite and 1 backdrop. You can add sprites from the library or draw your own.

Khối lệnh Event: When flag clickedEvent block: When flag clicked

Khối "when flag clicked" (khi cờ được nhấn) là cách nói với Scratch: "Khi người dùng nhấn nút xanh lá, hãy bắt đầu chạy chương trình". Mọi chương trình Scratch đều bắt đầu bằng một khối event. Nút cờ xanh lá ở trên cùng màn hình Scratch.The "when flag clicked" block tells Scratch: "When the user presses the green button, start running the program." Every Scratch program starts with an event block. The green flag button is at the top of the Scratch screen.

scratch
                      
                        when flag clicked
say "Xin chào! / Hello!" for 2 seconds
move 100 steps
turn 15 degrees
                      
                    

Khối lệnh Motion: di chuyển và xoayMotion blocks: move and turn

Khối "move [10] steps" làm sprite di chuyển về phía trước. Khối "turn [15] degrees" làm sprite xoay. Bạn có thể đổi số trong ô vuông. Thử đổi 10 thành 50 và xem sprite chạy nhanh hơn!The "move [10] steps" block makes the sprite move forward. The "turn [15] degrees" block makes the sprite rotate. You can change the number in the box. Try changing 10 to 50 and see the sprite move faster!

Bài tập thực hànhHands-on exercises

1Tạo sprite mèo, thêm backdrop "Blue Sky", và lập trình mèo nói "Xin chào!" trong 2 giây khi nhấn cờ xanh.Create a cat sprite, add the "Blue Sky" backdrop, and program the cat to say "Hello!" for 2 seconds when the green flag is clicked.

Gợi ýHint

Dùng khối: when flag clicked → say "Xin chào!" for 2 secondsUse blocks: when flag clicked → say "Hello!" for 2 seconds

Lời giảiSolution
scratch
                      
                        when flag clicked
say "Xin chào! / Hello!" for 2 seconds
                      
                    

2Lập trình mèo di chuyển 100 bước rồi xoay 90 độ, lặp lại 4 lần để tạo hình vuông.Program the cat to move 100 steps then turn 90 degrees, repeat 4 times to make a square.

Gợi ýHint

Dùng khối repeat 4, bên trong có move và turn.Use repeat 4 block, containing move and turn inside.

Lời giảiSolution
scratch
                      
                        when flag clicked
repeat 4
  move 100 steps
  turn 90 degrees
                      
                    

Kiểm traQuiz

Chọn đáp án đúng cho mỗi câu. Nhấn để xem giải thích.Choose the correct answer for each question. Click to see explanation.

Câu 1: Sprite trong Scratch là gì?Q1: What is a sprite in Scratch?

Câu 2: Khối "when flag clicked" làm gì?Q2: What does the "when flag clicked" block do?

Câu 3: Backdrop là gì?Q3: What is a backdrop?

Câu 4: Scratch được tạo ra bởi tổ chức nào?Q4: Which organization created Scratch?

Code mẫuSample code

scratch
                when flag clicked
say "Xin chào! / Hello!" for 2 seconds
move 100 steps
turn 15 degrees