Table of Contents

key () pressed?

Description

The block checks if the specified key is pressed. If the key is being pressed, the block returns “true”; if it is not, it returns “false”.

Example

The example demonstrates how to use keys sensing to control the movement of the sprite.

Script

Output

Read More
Learn how to control the Mecanum using PictoBlox with keyboard inputs. Make the Mecanum move forward, backward, turn left, and turn right along with unique lateral motions!

In this activity, we will make the computer program that controls the Mecanum Robot. It’s like a remote-control car. You can press different keys on the keyboard to make the Mecanum move forward, backward, left and right.

The Quarky Mecanum Wheel Robot is a type of robot that uses a special type of wheel to move. The wheel is made of four rollers mounted at 45-degree angles to the wheel‘s hub. Each roller has its own motor and can spin in either direction. This allows the wheel to move in any direction, making it an ideal choice for navigating around obstacles and tight spaces. The mecanum wheel robot can also turn on the spot, allowing it to make sharp turns without having to reverse direction.

 

Coding Steps

Follow the steps:

  1. Open a new project in PictoBlox.
  2. Connect Quarky to PictoBlox.
  3. Click on the Add Extension button and add the Quarky Mecanum extension.
  4. Now we will first initialize the Mecanum robots and the servos before starting the main code.
  5. The main code will consist nested if-else conditions that will check specific conditions on which key is pressed, and will react accordingly. We will use the arrow keys for basic movements (Forward, Backward, Left Right) and the keys “a” for lateral left movement and “d” for lateral right movement.

Code

Output

Forward-Backward Motion:

Lateral Right-Left Motion:

Circular Right-Left Motion:

Read More
Learn how to design a cheerful animated birthday card with costume-switching sprites, a birthday soundtrack, and interactive on-screen messages that respond to keyboard input using PictoBlox Blocks.

Introduction

The time has come to create something fun and heartwarming! We are going to design an animated birthday card in PictoBlox! In this activity, your character will celebrate with a cheerful animation, play a birthday song, and display a special message on the screen. We will use simple blocks to control the character, switch costumes for animation, and add sound effects to make the celebration lively.

Let’s begin and bring your birthday card to life!

Setting Up the Stage

Since this card will have some pattern, we need a backdrop that looks like a patterned background. Click on ‘Choose a Backdrop‘ and select the ‘Pattern’ tag in the menu. Choose the Stripes backdrop from the library. 

Adding the Sprites

For this animation, we need three sprites: our Tobi, Cake and balloon, and make something celebration mode. Click on the Choose a Sprite button and add the three sprites one by one from the library.

Make Animation with Tobi

Let’s create the script for Tobi (greeting/character sprite). This script handles both the birthday audio and the on-screen messages.

  1. Go to the Events palette and drag the “when green flag clicked” block into the scripting area.
  2. From the Sound palette, add the “play sound [ ] until done” block and set the sound to “birthday“. This plays the full birthday soundtrack.
  3. From the Motion palette, add the “go to x: y:” block and set the position to x: -200, y: -170. This places the sprite in the lower-left corner of the stage.
  4. From the Looks palette, add the “say [ ] for 2 seconds” block.
  5. Type “Happy Birthday” in the text box. 
  6. Go to the Controls palette and add the “repeat until” block.
  7. From the Sensing palette, place the “key (space) pressed?” block inside it and change the key to Up Arrow. This keeps the message loop running until the up arrow key is pressed.
  8. Inside the repeat until loop: Add a “say [ ]” block and type: “Press the UP arrow key.”
  9. Add another “say [ ]” block and type “Many more happy returns of the day” outside the repeat-until loop.

Cake Animation Script

Let’s create the script for the cake:

  1. Go to the Events palette and drag the “when green flag clicked” block into the scripting area.
  2. From the Motion palette, add the “go to x: 0 y: 0” block. This centers the cake sprite on the stage.
  3. From the Looks palette, drag the “set size to 100%” block and change the value to 150% to enlarge the cake for better visibility.

    Add Animation Condition

  4. Go to the Controls palette and add the “repeat until” block.
  5. From the Sensing palette, place the “key (space) pressed?” block inside it and change the key to Up Arrow.
    → This will keep the animation running until the Up Arrow key is pressed.
  6. Create Cake Animation

Create Cake Animation

  1. Inside the repeat until loop:
  2. Add “switch costume to [cake-b]” from the Looks palette (candles lit).
  3. Add a “wait 0.05 seconds” block from Controls for smooth animation timing.
  4. Add “switch costume to [cake-a]” (candles flicker/blow effect).
  5. Add another “wait 0.05 seconds” block.

Add Celebration Sound

  1. Add Celebration Sound
  2. After the loop, add “play sound [birthday] until done” from the Sound palette.
  3. Go to the Sounds tab at the top.
  4. Click “Choose a Sound” and add a clapping sound from the library.
  5. Return to the scripting area and change the sound in the block to clapping.

Flying Balloon — Clone-Based Confetti Effect

The balloon sprite uses clone feature to create a burst of multiple balloon pieces flying across the screen when the Up Arrow key is pressed. There are two separate scripts on this sprite.

Script A – Hidden on Start

  1. Go to the Events palette and drag the “when green flag clicked” block into the scripting area.
  2. Add the hide block from the looks palette.

Script B – Up Arrow Triggers Balloon

  1. Add the ‘when [space] key pressed’ block from the Events palette; change the key into the up arrow.
  2. Add the repeat block and add the number 10. Runs the following blocks 10 times to create 10 balloon clones.
  3. Inside the repeat block, add the create clone of [myself] from the control palette. Inside the loop spawns a new clone of the balloon sprite.
  4. Adds a tiny delay between each clone creation for a staggered burst effect. From the control palette, add wait 1 seconds, change the seconds to 0.05 seconds.
  5. From the Looks palette, next costume – change through different balloon costumes/colours for visual variety.

Script C – Clone Behaviour

  1. Each clone, when it is created, automatically runs. Add the ‘when I start as a clone’ block from the Controls palette.
  2. Add the go to [random position]’ block from the Motion palette. It teleports the clone to a random location on the stage.
  3. Add a show from the Looks palette; it makes the clone visible.
  4. Add glide 1 sec to [random position]; smoothly glides the clone to another random position over 1 second, creating a floating balloon effect.
  5. Add the delete this clone from the control palette; it removes the clone from the stage after it finishes gliding.

Output

Conclusion

In this project, we learned how to create an animated birthday card in PictoBlox using Blocks. We required a computer with PictoBlox installed and the sprite library to add Tobi, Cake, and Balloon1. We used costume switching and sound blocks to animate the cake, repeat-until loops to display interactive messages, and the clone feature to create a balloon confetti burst. In the end, we wrote three sets of scripts — for Tobi’s greeting, the cake animation, and the flying balloons. With this project, kids and learners will have a better understanding of sprite animation, event-driven programming, and how to build interactive scenes in PictoBlox Blocks.

Read More
Learn to move your Quarky Mecanum Wheel Robot in a square and make an axe figure with PictoBlox. Use the arrow keys to activate the custom movements and watch your robot move in the desired direction!

In this activity, we will create a custom activity where you will be able to move the Mecanum robot in a square effortlessly along with making an Axe type figure.

The Quarky Mecanum Wheel Robot is a type of robot that uses a special type of wheel to move. The wheel is made of four rollers mounted at 45- degree angles to the wheel’s hub. Each roller has its own motor and can spin in either direction. This allows the wheel to move in any direction, making it an ideal choice for navigating around obstacles.

Coding Steps

Follow the steps:

  1. Open a new project in PictoBlox and select Block Coding Environment.
  2. Connect Quarky to PictoBlox.
  3. Click on the Add Extension button and add the Quarky Mecanum extension.
  4. Now we will first initialize the Mecanum robots and the servos before starting the main code.
  5. Here there are two parts specifically : To make a Square and To make an Axe

To make a Square (Logic):

The main steps would include to display the lights in arrow forms before implementing the specific move. The moves would be implemented in the following order:

Forward -> Lateral Right -> Backward -> Lateral Left.

We will display the arrows with the help of Quarky LED’s and implement the code.

Example of arrow:

Code for Square Motion:

To make an Axe (Logic):

The main steps would include to display the lights in arrow forms before implementing the specific move. The moves would be implemented in the following order:

Forward ( 2 steps ) -> Lateral Left ( 1 step ) -> Backward Right ( 1 step ) -> Backward ( 1 step )

We will display the arrows with the help of Quarky LED’s and implement the code.

Code for Axe Motion

Main Code

Now we will keep a specific condition on when to activate the Square Motion and when to activate the Axe Motion.

We will use the if-else conditions where on pressing the “up” arrow key, we will initiate the Square Motion and on pressing the “down” arrow key, we will initiate the Axe Motion with the help of Mecanum Robot.

Final Output

Square Motion:

Axe Motion:

Read More
The examples show how to use pose recognition in PictoBlox to make jumping jack counter.

Introduction

In this example project, we are going to create a machine learning model that can count the number of jumping jack activities from the camera feed.

Pose Classifier in Machine Learning Environment

The pose Classifier is the extension of the ML Environment used for classifying different body poses into different classes.

The model works by analyzing your body position with the help of 17 data points.

Pose Classifier Workflow

  1. Open PictoBlox and create a new file.
  2. You can click on “Machine Learning Environment” to open it.
  3. Click on “Create New Project“.
  4. A window will open. Type in a project name of your choice and select the “Pose Classifier” extension. Click the “Create Project” button to open the Pose Classifier window.
  5. You shall see the Pose Classifier workflow with two classes already made for you. Your environment is all set. Now it’s time to upload the data.

Class in Pose Classifier

Class is the category in which the Machine Learning model classifies the poses. Similar posts are put in one class.

There are 2 things that you have to provide in a class:

  1. Class Name: The name to which the class will be referred.
  2. Pose Data: This data can be taken from the webcam or uploaded from local storage.

Adding Data to Class

You can perform the following operations to manipulate the data into a class.

  1. Naming the Class: You can rename the class by clicking on the edit button.
  2. Adding Data to the Class: You can add the data using the Webcam or by Uploading the files from the local folder.
    1. Webcam:

Training the Model

After data is added, it’s fit to be used in model training. To do this, we have to train the model. By training the model, we extract meaningful information from the hand pose, and that in turn updates the weights. Once these weights are saved, we can use our model to predict previously unseen data.

The accuracy of the model should increase over time. The x-axis of the graph shows the epochs, and the y-axis represents the accuracy at the corresponding epoch. Remember, the higher the reading in the accuracy graph, the better the model. The range of accuracy is 0 to 1.

Testing the Model

To test the model, simply enter the input values in the “Testing” panel and click on the “Predict” button.

The model will return the probability of the input belonging to the classes.

Export in Block Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Block Coding Environment if you have opened the ML Environment in the Block Coding.

Script

The idea is simple, after running code we will do jumping jack activity in front of camera and tobi sprite will say counting of jumping jack.

  1. Select the Tobi sprite.
  2. We’ll start by adding a when flag clicked block from the Events palette.
  3. We made the new variable “count” by choosing the “Make a Variable” option from the Variables palette.
  4. Also we made the new variable “temp” by choosing the “Make a Variable” option from the Variables palette.
  5. Add “forever” from the Control palette.
  6. Inside the “forever” block, add an “analysis image from ()” block from the Machine Learning palette. Select the Web camera option.
  7. Inside the “forever” block, add an “if () then” block from the Control palette.
  8. In the empty place of the “if () then” block, add an “key () pressed?” block from the Sensing palette. Select the ‘q’ key from the options.
  9. Inside the “if () then” block, add the “Set () to ()” block from the Variables palette. Select the count option at the first empty place, and for the second, write a 0 value.
  10. Also add the “Set () to ()” block from the Variables palette. Select the temp option at the first empty place, and for the second, write a 0 value.
  11. Inside the “forever” block, add an new “if () then” block from the Control palette.
  12. In the empty place of the “if () then” block, add an “is identified class ()” block from the Machine Learning palette. Select the ‘Upper hand‘ option from the options.
  13. Inside the “if () then” block, add the “Set () to ()” block from the Variables palette. Select the temp option at the first empty place, and for the second, write a 1 value.
  14. Inside the “forever” block, add an new “if () then” block from the Control palette.
  15. In the empty place of the “if () then” block, add an “is identified class ()” block from the Machine Learning palette. Select the ‘Down hand‘ option from the options.
  16. Inside the “if () then” block, add the another “if () then” block from the Control palette.
  17. In the empty place of the “if () then” block, add a condition checking block from the operators palette block. At the first empty place, put the temp variable from the variables palette, and at the second place, write a 1 value.
  18. Inside the “if () then” block, add the “Set () to ()” block from the Variables palette. Select the count option at the first empty place, and for the second, write a 1 value.
  19. Also add the “Set () to ()” block from the Variables palette. Select the temp option at the first empty place, and for the second, write a 0 value
  20. Inside the “if () then” block, add an “say () for () seconds” block from the Looks palette block. At the first empty place, add the “join () ()” block from operator palette and at the second place, write a 2 value.
  21. Inside “join () ()” block at the first empty place, write the appropriate statement and at the second place, add count variable from Variables palette.

    Final Output

     

Read More
All articles loaded
No more articles to load