Table of Contents

setsize()

Function Definition: setsize(percentage = 100)

Parameters

NameTypeDescriptionExpected ValuesDefault Value
percentageintThe percentage size,Integer100

Description

The function sets its sprite’s size to the specified amount. The default sprite size is 100%; anything lower than that will decrease the size of the sprite on the stage, and anything above will increase the size of the sprite on the stage.

Example

The example demonstrates the sprite direction in Python.

Code

sprite = Sprite('Arrow1')

sprite.gotoxy(0, 0)
sprite.setsize(300)

while True:
  if sprite.iskeypressed("left arrow"):
    sprite.left(3)
  if sprite.iskeypressed("right arrow"):
    sprite.right(3)
  sprite.say("Direction is " + str(sprite.direction()))

Output

Read More
The example demonstrates the bouncing of an object from a bird's eye view in PictoBlox.

Code

sprite = Sprite('Tobi')
import time

sprite.gotoxy(0, 0)
sprite.setsize(100)

while True:
  for i in range(10):
    sprite.changesize(sprite.size()/10)
    time.sleep(0.01)
  for i in range(10):
    sprite.changesize(- sprite.size()/10)
    time.sleep(0.01)

Output

Read More
Learn how to use face detection to control humanoid robot movements for interactive and responsive robotics applications. Get started now!

Introduction

One of the most fascinating activities is face tracking, in which the Quarky can detect a face and move its head in the same direction as yours. How intriguing it sounds, so let’s get started with the coding for a face-tracking robot.

Logic

  1. If the face is tracked at the center of the stage, the humanoid should be straight.
  2. As the face moves to the left side, the humanoid will also move to the left side.
  3. As the face moves to the right side, the humanoid will also move to the right side.

Code

sprite = Sprite('Tobi')
quarky=Quarky()
import time
import math
humanoid = Humanoid(7,2,6,3,8,1)

fd = FaceDetection()
fd.video("on", 0)
fd.enablebox()
fd.setthreshold(0.5)
time.sleep(1)
Angle=0
while True:
  fd.analysestage()
  for i in range(fd.count()):
    sprite.setx(fd.x(i + 1))
    sprite.sety(fd.y(i + 1))
    sprite.setsize(fd.width(i + 1))
    Angle=fd.width(i + 1)
    angle=int(float(Angle))
    if angle>90:
      humanoid.move("left",1000,3)
    elif angle<90:
      humanoid.move("right",1000,3)
      time.sleep(1)
    else:
      humanoid.home()

Code Explanation

  1. First, we import libraries and create objects for the robot.
  2. Next, we set up the camera and enable face detection with a 0.5 threshold.
  3. We use a loop to continuously analyze the camera feed for faces and control the humanoid’s movement based on this information.
  4. When a face is detected, the humanoid sprite moves to the face’s location, and the angle of the face is used to determine the direction of movement.
  5. If the angle is greater than 90 degrees, the humanoid moves to the left.if angle is less than 90 degrees, the humanoid moves to the right.if angle is  exactly 90 degrees, the humanoid returns to its original position.
  6. This code demonstrates how to use face detection to control the movement of a humanoid robot and how to incorporate external inputs into a program to create more interactive and responsive robotics applications.

Output

Read More
Learn about face-tracking, and how to code a face-tracking Quadruped robot using sensors and computer vision techniques.

Introduction

A face-tracking robot is a type of robot that uses sensors and algorithms to detect and track human faces in real time. The robot’s sensors, such as cameras or infrared sensors, capture images or videos of the surrounding environment and use computer vision techniques to analyze the data and identify human faces. One of the most fascinating activities is face tracking, in which the Quadruped can detect a face and move its head in the same direction as yours. How intriguing it sounds, so let’s get started with the coding for a face-tracking Quadruped robot.

we will learn how to use face detection to control the movement of a Quadruped robot and how to incorporate external inputs into a program to create more interactive and responsive robotics applications.

Logic

  1. If the face is tracked at the center of the stage, the Quadruped should be straight.
  2. As the face moves to the left side, the Quadruped will also move to the left side.
  3. As the face moves to the right side, the Quadruped will also move to the right side.

Code

sprite = Sprite('Tobi')
quarky=Quarky()

import time
import math
quad=Quadruped(4,1,8,5,3,2,7,6)

fd = FaceDetection()
fd.video("on", 0)
fd.enablebox()
fd.setthreshold(0.5)
time.sleep(1)
Angle=0
while True:
  fd.analysestage()
  for i in range(fd.count()):
    sprite.setx(fd.x(i + 1))
    sprite.sety(fd.y(i + 1))
    sprite.setsize(fd.width(i + 1))
    Angle=fd.width(i + 1)
    angle=int(float(Angle))
    if angle>90:
      quad.move("lateral right",1000,1)
    elif angle<90:
      quad.move("lateral left",1000,1)
    else:
      quad.home()

Code Explanation

  1. First, we import libraries and create objects for the time and math.
  2. Next, we set up the camera and enable face detection with a 0.5 threshold.
  3. Based on this information, We use a loop to continuously analyze the camera feed for faces and control the humanoid’s movement.
  4. When a face is detected, the quadruped sprite moves to the face’s location and the angle of the face is used to determine the direction of movement.
  5. The Quadruped moves to the left if the angle is greater than 90 degrees.
  6. The Quadruped moves to the right if the angle is less than 90 degrees.
  7. If the angle is exactly 90 degrees, the Qudruped returns to its original position.

Output

Our next step is to check whether it is working right or not. Whenever your face will come in front of the camera, it should detect it and as you move to the right or left, the head of your  Quadruped robot should also move accordingly.

Read More
All articles loaded
No more articles to load