Project: SigilChant

What It Does

I said in the introduction to Scratch that I could teach you in just a few minutes how to make a project that will manifest a sigil unto visible appearance in response to vocalized sound such as chanting or intoning. First, I will make good on that promise with a rudimentary project; then I will show you a few ways to improve the design.

How It Works

The most basic steps for making a sigil that becomes increasingly visible in response to sound are:

  1. Draw or import an image of the sigil into Scratch.
  2. Use Scratch’s ghost effect to make the sigil effectively invisible by making it completely transparent (ghost = 100).
  3. Use Scratch’s loudness sensor (and a microphone) to detect when you are making some sound.
  4. While the loudness value exceeds some threshold, decrease the ghost effect value thereby making the sigil more visible/opaque (the smaller the unit of decrease, the longer it will take the ghost value to go from 100 to 0, thus the longer it will take for the sigil to completely manifest).

SigilChant implements that basic design. You will need a microphone connected to your computer (if your computer has a webcam built into it, it probably has a mic). After you start the project running, speak, chant, sing, or intone into the microphone and observe what happens. (N.b., the sigil used in this project is meaningless; it is just something I doodled as an example to use in multiple projects. You can easily swap in one of your own making.)

When running projects that require your video camera or microphone, Flash may request your permission to read data from your device. It is safe to allow this. If you are working in the online Scratch editor and you are unable to get your web browser to access your camera or microphone, try downloading the project from the online editor and running it in the offline editor.

SigilChant has but one script:

SigilChant Script

The ghost effect ranges from 0 (fully opaque) to 100 (fully transparent), so the first thing the script does is set the ghost effect to 100. Then it goes into a forever loop of checking the loudness sensor, which also ranges from 0 (complete silence) to 100 (loudest sound the sensor can measure). If the sensor’s value is greater than 15 (arbitrary; experiment with different thresholds), the script decreases the ghost effect by 1. If you want the sigil to take longer to manifest, simply change that 1 to something smaller, e.g., setting it to 0.5 will make the sigil take twice as long to become fully manifested.

The loudness sensor detects any sound interacting with your computer’s microphone, which could include talking, coughing or clearing your throat, background noises, &c. For best results, run SigilChant in an otherwise quiet environment. A headset mic with mute button is helpful for this sort of thing, but not so when you want to detect the sound of a group of people chanting together. Also, if you make a sustained vowel sound (try saying a monotone “aahhh” loudly but slowly for a full exhale) and find the value of your loudness sensor steadily decreases to 0 even while the volume of your voice remains constant, your computer’s microphone may be configured for noise reduction and is computing your persistent, monotone chant as noise. You would need to disable that using your computer’s sound management software. When troubleshooting, you can view the value of the loudness sensor on the stage when the project runs (as shown in the animated GIF at the top of this page) by checking the box next to the loudness block in the Sensing palette of the Scripts tab.

Loudness Reporter

What happens when the ghost effect decreases to less than zero? Visually, nothing; for that effect, anything less than or equal to (<=) 0 is fully opaque, and anything greater than or equal to (>=) 100 is fully transparent; but the forever loop keeps running until you manually stop the project. How about we change the project to detect when the ghost effect has reached 0 and then let us know the manifestation is complete?

Make It Better

SigilChant2 (download or preview online) includes that improvement in the form of a variable named ghostVal that is set to a value between 0 and 100 just before setting the ghost effect equal to the same value, therefore we can effectively track the effect’s value over time. SigilChant2 includes a few additional improvements:

  • When ghostVal goes beyond 0, instead of the script continuing for eternity, the sprite’s costume changes to the word “Finis,” signifying the end of the operation, and then the script stops the entire project (with the stop(all) block).
  • Since the volume of sound for manifesting the sigil could vary by several factors including the microphone’s input level and the sound source’s distance from the microphone, I have included a threshold variable that can be changed to lower or raise the required loudness.
  • In order to change the value of threshold I use one of Scratch’s own slider controls, and made another variable, showThresholdSlider, to determine whether or not the slider displays. showThresholdSlider has two possible values: 0 (off/hidden) or 1 (on/showing). The value is toggled (changed from 0 to 1 or 1 to 0) by pressing the space bar on your keyboard.
  • In addition to having the sigil become more visible in response to sound exceeding the threshold value, the sigil will now begin to disappear again if there is insufficient loudness to manifest it. This is accomplished by changing the if () then block to an if () then, else block: i.e., if loudness > threshold (is true) then change the ghost effect by -1 else change it by (+)1. The if (ghostVal > 100) then block is there to keep ghostVal and the corresponding ghost effect from increasing above 100 in the absence of sound exceeding threshold.

Here are the modified scripts for SigilChant2:

SigilChant2 Scripts

Let us follow the scripts from top to bottom to understand how they work. The first script (on the left) begins when the green flag is clicked. Its first action is to switch the costume to sigil in case the costume was finis the last time the project ran. Then the script hides the threshold slider and sets the beginning values for the variables and ghost effect. Next the script goes into a repeat loop until the value of the ghostVal variable is less than (<) 0. Within that loop, the script keeps checking the value of the loudness sensor; if that value exceeds (>) the value of the threshold variable, then the script changes ghostVal by -1 (i.e., decreases by 1) and sets the ghost effect to the new ghostVal value; otherwise (else) the script checks to see if ghostVal is less than (<) 100 and if it is, then the script increases ghostVal by 1 and sets the ghost effect accordingly. Once ghostVal is less than 0, the script exits the repeat () until loop and proceeds with the next step, switching the costume to finis. Finally, the script waits five seconds before stopping everything.

The second script (on the right) only runs when the space bar is pressed. It checks to see if the value of showThresholdSlider is 0 (which arbitrarily means “no,” “off,” or “false”), and if it does, then the script shows the slider for the threshold variable and changes showThresholdSlider to 1 (which arbitrarily means “yes,” “on,” or “true”). Otherwise, the script hides the slider and changes showThresholdSlider to 0. Effectively, this script acts as a switch that shows the slider if it is not already showing, or hides the slider if it is showing.

The variable, showThresholdSlider, here is intended to act as a Boolean variable, i.e., a variable whose value is either true or false. Boolean variables are useful for recording the the state of anything having two possible states: on/off, active/inactive, showing/hiding, moving/not-moving, &c.

A common feature of Boolean variables is toggling them using a not operator. Say you have a Boolean variable named myBoolVar. If the present value of myBoolVar is true then setting the variable to not true would make it false (and if it is false then setting it to not false would set it to true). Although Scratch has Boolean blocks and allows Boolean parameters in custom blocks, Scratch variables created with the Make Variable button cannot be explicitly typed as Boolean variables, so you cannot plug a variable into Scratch’s not () block in order to flip its value. There is a workaround, however: you can set myBoolVar to (myBoolVar) = (false) which will always switch the value from true to false or from false to true (because if myBoolVar is false then it is true that it is equal to false, but if it is true then it is false that it is equal to false).

Scratch Boolean Variables

This opens up a different and slightly more efficient way to toggle showThresholdSlider:

Scratch Boolean Variables 2

This simple operation of changing the visibility of a sigil (or other image) in response to sound can be the basis of diverse technomantic interactions, as demonstrated by the following two projects, SurroundSigil and Sigilaunch.