speechresult()

Function Definition: speechresult()

Description

The function reports the last text detected from the speech.

Parameters

Example

The example demonstrates how to make the sprite track and stamp its image on the mouse when the space key is pressed in Python.

Code

sprite = Sprite('Tobi')
pen = Pen()

pen.clear()

while True:
  if (sprite.iskeypressed("space")):
    sprite.setx(sprite.mousex())
    sprite.sety(sprite.mousey())
    pen.stamp()

Output

The example demonstrates using key sensing to control the sprite's movement in Python.

Code

sprite = Sprite('Beetle')

sprite.setdirection(90)
sprite.gotoxy(0, 0)

while True:
  if sprite.iskeypressed('up arrow'):
    sprite.move(3)
  if sprite.iskeypressed('down arrow'):
    sprite.move(-3)
  if sprite.iskeypressed('left arrow'):
    sprite.left(3)
  if sprite.iskeypressed('right arrow'):
    sprite.right(3)

Output

The example demonstrates how to add movement to a sprite.

Code

sprite = Sprite('Ball')

while True:
  if sprite.iskeypressed('up arrow'):
    sprite.changey(3)
  if sprite.iskeypressed('down arrow'):
    sprite.changey(-3)
  if sprite.iskeypressed('left arrow'):
    sprite.changex(-3)
  if sprite.iskeypressed('right arrow'):
    sprite.changex(3)
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

The example demonstrates how to implement mouse tracking in Python.

Code

sprite = Sprite('Tobi')

while True:
  if (sprite.iskeypressed("space")):
    sprite.goto("_mouse_")

Output

The example demonstrates the wall bouncing of the sprite, rotation style, and costume change in Python.

Code

sprite = Sprite('Tobi')
import time

sprite.setrotationstyle('left-right')

while True:
  sprite.move(5)
  sprite.bounceonedge()
  sprite.switchcostume("Tobi walking 1")
  time.sleep(0.1)
  
  sprite.move(5)
  sprite.bounceonedge()
  sprite.switchcostume("Tobi walking 2")
  time.sleep(0.1)

Output

The example demonstrates how to make the sprite follow the mouse in Python.

Code

sprite = Sprite('Tobi')

while True:
  sprite.pointto()
  sprite.move(3)

Output

The example demonstrates how to add gravity to the project on a bouncing ball.

Code

sprite = Sprite('Ball')
import time
import random

sprite.setx(random.randrange(-200, 200))
sprite.sety(random.randrange(-100, 140))
gravity = -2
xpos = sprite.x()
ypos = sprite.y()
dx = random.randrange(-50, 50)
dy = random.randrange(-25, 25)

while True:
  dy = dy + gravity
  dx = dx * 0.98
  dy = dy * 0.98
  xpos = xpos + dx
  ypos = ypos + dy

  if ypos < -160:
    dy = -dy
    ypos = -160
  if ypos > 130:
    dy = -dy
    ypos = 130

  if xpos < -220:
    dx = -dx
    xpos = -220
  if xpos > 220:
    dx = -dx
    xpos = 220
  
  sprite.gotoxy(xpos, ypos)
  time.sleep(0.01)

Output

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

Script

Output

The example demonstrates the costume change and gliding to the random location when clicked.

Script

Output

The example demonstrates the costume change in PictoBlox.

Script

Output

The example demonstrates how to use a repeat block to recite a table in PictoBlox.

Sprite

Output

The example demonstrates the show and hides of the sprite using the buttons.

Script

Output

The example demonstrates the various graphical effects in the PicotBlox - Brightness, color, fisheye, ghost, mosaic, pixelated, and whirl.

Color

Fisheye

Ghost

Mosaic

Brightness

Pixelate

Whirl

The example demonstrates how to use thinking sprite in a project.

Script

Output

The example demonstrates the various graphical effects in the Python - Brightness, color, fisheye, ghost, mosaic, pixelated, and whirl.

Code

sprite = Sprite('Tobi')
import time

effect = "COLOR"
# effect = "FISHEYE"
# effect = "WHIRL"
# effect = "PIXELATE"
# effect = "MOSAIC"
# effect = "BRIGHTNESS"
# effect = "GHOST"

sprite.gotoxy(0, 0)
sprite.setsize(200)
sprite.cleareffects()
sprite.seteffect(effect, 0)

while True:
  for i in range(10):
    sprite.changeeffect(effect, 5)
    time.sleep(0.1)
  for i in range(10):
    sprite.changeeffect(effect, -5)
    time.sleep(0.1)

Color

Fisheye

Ghost

 

Mosaic

Brightness

 

Pixelate

Whirl

The example demonstrates the show and hides of the sprite in Python.

Code

sprite = Sprite('Tobi')
import time

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

while True:
  sprite.show()
  time.sleep(1)
  sprite.hide()
  time.sleep(1)
The example demonstrates how to use say and think of sprite in a project.

Code

sprite = Sprite('Tobi')
import time

sprite.say("Saying for 2 seconds", 2)
sprite.say("Saying forever")
time.sleep(2)

sprite.think("Thinking for 2 seconds", 2)
sprite.think("Thinking forever")

Output

The example demonstrates the costume change in PictoBlox.

Code

sprite = Sprite('Tobi')

sprite.gotoxy(0, 0)
sprite.setsize(200)
sprite.switchcostume("Tobi")

while True:
  sprite.say(sprite.costume("name"), 1)
  sprite.nextcostume()

Output

The example demonstrates how to use a repeat block to recite a table in PictoBlox.

Code

sprite = Sprite('Tobi')

sprite.input("Which table you want to recite")
number = int(sprite.answer())

for i in range(1, 10):
  sprite.say(str(number) + " x " + str(i) + " = " + str(number*i), 1)

Output

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

The example demonstrates the LED emotions of the Quarky.

Script

Output

The example demonstrates the various animation of the Quarky LED display.

Script

Output

The example demonstrates how to display scrolling text to make a name badge.

Script

Output

The example demonstrates how to implement a while loop running from 1 to 9 and show it on the Quarky display.

Script

Output

The example demonstrates how to control the individual LEDs of the Quarky and run patterns using the loops.

Script

Output

The example demonstrates how to calibrate the IR sensors to detect black lines on the white surface.

Logic

An IR sensor consists of 2 LEDs: one which transmits the IR light and one which receives the IR light. When the IR rays are transmitted, they bounce from the nearest surface and get back to the receiver LED. That’s how an IR sensor detects an object.

But to detect colors, we depend on the number of rays the surface reflects:

  1. The dark surface will absorb more IR rays and as a result, the receiver will get fewer IR rays.
  2. White or shiny objects will absorb fewer IR rays and as a result, the receiver will get more IR rays.

We can get the sensor values in PictoBlox and based on that value we can estimate whether the surface is black or white.

  1. If the sensor detects the black line, its output value is increased. This means that the sensor is active.
  2. If it detects the white area, its output value decreases. This means that the sensor is inactive.

We will call the threshold value above which the sensor detects the black line. If the sensor value is less than the threshold, it means that the sensor hasn’t detected the line yet.

Alert: IR sensors DON’T work in sunlight. IR rays from the sun increase the overall threshold of the sensors therefore they stay active all time. A closed environment or nighttime is the place/time to work with your line following robot.

Script

Calibrating the IR Sensors

Now, run the script by clicking the green flag and bringing the black line of the track close to the IR sensor. One of the following three conditions will happen:

  1. Your calibration value is HIGH: The black region will not be detected in this case. Reduce the calibration value.
  2. Your calibration value is LOW: The white region will not be detected in this case. Therefore, increase the calibration value.
  3. Your calibration value is OK. The white and black regions are detected accurately.

Now modify the script to add the detection value for the right IR sensor.

Output

The example demonstrates how to create a random colored LED pattern on Quarky.

Script

Output

The example demonstrates how to control the glowing LED using the keyboard keys.

Script

Output

The example displays how we can display a custom pattern on the matrix by making a script to display a Traffic Light.

Script

Output

All articles loaded
No more articles to load
Table of Contents
[PythonExtension]

Get in Touch!