Project: Meditaid

Meditation and concentration exercises are often the first things a magician learns, and they continue to benefit her throughout her career. Meditaid is a meditation assistant I will show you how to make from scratch (no pun intended).

What It Does

Meditaid is a meditation timer that can be set from one second to one hour1, and includes an image to focus on while meditating. A bell sounds at the end of the countdown to alert you that the session has ended.

How It Works

There are many ways we could build a meditation timer, with various features. We shall make Meditaid to do the following:

  1. Display an image for us to gaze at while we meditate.
  2. Allow us to select a number of minutes and seconds for the meditation session to last.
  3. Display an instructional message at the beginning of the session, and a different message at the end.
  4. Play a bell sound at the end of the session.

Conventions

Following are some conventions I use throughout Technomancy 101 when describing projects:

  • Scratch block names are in this style: when green flag clicked.
  • Sprite names and variables are in this style: Ball.

When using Scratch, I follow Java naming conventions (because they are consistent with how I code in Processing):

  • Sprite names are in UpperCamelCase and indicate what the sprite is, e.g.: Timer, Card, Button, StartButton, CloudOne.
  • Variable names are in lowerCamelCase and are usually descriptive: i, j (loop indices); minutes, seconds (representing number of minutes or seconds, respectively); buttonVal, cardVal (to hold the value of a button or card); scoreShowing, buttonMatchesCard (Boolean variables representing whether or not the score is showing, or whether the button value matches the card value).
  • Constants (i.e., variables that are set once, usually when the project starts, and then do not change while the project runs) are in all capital letters with multiple words separated by underscores: PI (= 3.14159), MAX_ITERATIONS (maximum number of iterations).
  • Message names are in lowerCamelCase, indicate what the message is about, and usually begin with a verb: getNewCard, revealCard.
  • Costume and sound names are in lowerCamelCase: title, magicSquare, bellToll.

Building the Project

You may download the completed Meditaid project if you would like something to compare your own work to.

Begin a new Scratch project by either running the offline editor or visiting https://scratch.mit.edu/ and clicking the Create button near the top of the screen.

Rename the project to Meditaid (or whatever you want to call it).

We will not be using the default cat sprite, so delete it by selecting its thumbnail and pressing the Delete key or right-clicking on the thumbnail and selecting delete from the context menu (if right-click gives you trouble, try left-clicking while pressing the Shift key).

We are going to upload an image to gaze at while we meditate. You may use the same one I did (save it locally to your computer), or one of your own choosing (Scratch’s aspect ratio is 4:3, and images larger than 480 × 360 pixels will be automatically shrunk to that size; there are hacks that will allow you to import larger images, but let us ignore those for now). Click on the Stage in the Sprites pane if it is not already selected, and then click on the Backdrops tab and then the button to upload a new backdrop. Navigate to the image’s location on your computer, then select and open the image file.

Delete the default backdrop, backdrop1, by selecting its thumbnail in the Backdrops pane and clicking the x icon on the upper-right side of the thumbnail, or by right-clicking on the thumbnail and selected delete from the context menu.

Now we shall create a sprite that will act as a timer for our meditation sessions. In the Sprites pane, click the Paint new sprite button.

On the Sprite1 thumbnail, click the i icon in the upper-left corner to view the sprite’s properties, then rename the sprite to Timer.

Before we make any scripts for this sprite, we will add two costumes to display at the start and end of the meditation session, and a bell sound to play at the end to alert us that the session has finished. To begin creating the first costume, make sure the Timer sprite is selected in the Sprites pane, then click on the Costumes tab and select costume1. In the paint editor, click the Fill with color tool, then click on the image to fill it in black.

In the lower-right corner of the paint editor, click the Convert to vector button. By making the costume a vector image rather than a bitmap (a.k.a raster) image (q.v.), it will resize properly when we run the project in full-screen mode.

After converting the costume, click on the foreground color in the color palette to switch the foreground color from black to white.

Select the Text tool on the right side of the editor, then click on the costume to begin typing text. Type the following text into the editor: “Use the sliders to set minutes and seconds, then press the space bar to start the timer.” Insert line breaks where needed to keep the text from expanding beyond the edge of the costume.

If needed, use the Select tool to reposition the text wherever you would like it to be on the costume.

Rename the costume to start.

To create the second costume, right-click on the first one and select duplicate, then select the second costume and use the Text tool to edit the text to: “The session has ended. Welcome back to ordinary consciousness.” Again, use the Select tool to reposition the text if needed, then rename the second costume to end. When you are finished, you should have two costumes that look like this:

Click on the Sounds tab and then the Choose sound from library button, then select the bell toll sound and click OK.

In keeping with my naming conventions, I renamed the sound to bellToll; that is optional. You may preview the sound by pressing the play button in the sound editor.

Delete the default pop sound.

Now we shall build the script that will coordinate these images and sounds and make the project interactive. We begin by creating variables for the number of minutes and seconds we want our meditation session to last, and we will build the script such that we can specify that duration at the beginning of each session. Click on the Scripts tab then select the Data category. Click the Make a Variable button. In the New Variable dialog box, name this variable minutes, select the radio button for This sprite only, and click OK.

Do the same thing to make a seconds variable (naming it seconds instead of minutes). You should now see two variables on the stage.

We are going to turn these variables into sliders that will let us select a value between 0 and 59. Right-click on the Timer: minutes display and select slider from the context menu. Then right-click on it again and select set slider min and max.

In the Slider Range dialog box, leave the Min value at 0 and change the Max value to 59, then click OK.

Repeat the last few steps to make a slider for the seconds variable (also in the range from 0 to 59), then click and drag the seconds slider so that the sliders do not overlap. They should look like this when you have finished:

Click on the Scripts tab and then on the Events category, then click and drag the when green flag clicked block from the block palette to the script area.

The blocks we place beneath this one will run in order when the green flag is clicked (clicking the green flag causes a Scratch project to start running).

You may have noticed the Timer sprite is not centered on the stage. Scratch uses a coordinate system to keep track of where each sprite is located. When you add a new sprite, Scratch assigns it a random starting position. You could click and drag the sprite to where you want it, or you can edit its x and y coordinate values. I usually explicitly set the starting positions for all of my sprites in case I move a sprite while editing the project. For the present project, I want the Timer sprite to be centered, so I set its starting x,y position to 0,0—i.e., the center of the stage. In the Scripts pane, select the Motion category, then click and drag the go to x: () y: () block directly beneath the when green flag clicked block until your see a white line appear, then release the mouse button to snap the block into place. Edit the numbers (called arguments) in the block to x:0, y:0.

From now on every time Meditaid starts (when the green flag is clicked) the first thing Timer does is center itself on the stage. The next thing we need to do is set the initial values for the variables and make sure the associated sliders are showing when the project starts. On the Data palette, select the set () to () block twice and use the drop-down list to select minutes for one of the blocks and seconds for the other. Set the argument for the minutes block to 15 and leave the value for seconds at 0. Also drag over the show variable () block twice, and change one of them to minutes and the other to seconds. When you are done your script should look like this:

Next we will make the script select the start costume and display it (in case it is hidden, because we will hide it later). From the Looks palette, get the switch costume to () block and change it to start (if it is not already), and also get the show block.

We need a way to tell Scratch to start the timer after we have selected our values for minutes and seconds. As you may have guessed from the wording of the start costume, we will use pressing the space bar as the event. From the Control palette, get the wait until () block, then get the key (space) pressed? block from the Sensing palette and snap it into place on the wait until () block.

When the space is bar is pressed, we need Scratch to hide the sliders and instructions (so we are not looking at them while we meditate) and then count down the duration we selected with the sliders. Get two of the hide variable () blocks from the Data palette and make sure one is for minutes and the other for seconds, then get the hide block from the Looks palette.

To count down the session, we will use the wait () secs block from the Control palette and a little arithmetic using blocks from the Operators palette. Since the wait () secs block is expecting an argument in seconds, we need to convert the minutes value to seconds and then add the seconds value. Since there are 60 seconds in one minute, the formula is (minutes * 60) + seconds. Get the minutes and seconds reporter blocks from the Data menu, and the () * () and () + () blocks from the Operators menu, and assemble as so:

Finally, when the count down is complete, we need to display the end costume and play the bellToll sound. Get the switch costume to (end) and show blocks from the Looks palette, the play sound (bellToll) until done block from the Sound palette, and the stop (all) block from the Control palette. Here is the finished script:

Test the project by clicking the green flag, setting the sliders, pressing the space bar, and noticing what happens. When testing, run a couple of brief scenarios such as 0 minutes and 10 seconds, and 1 minute and 30 seconds. Try running the project in full-screen mode by clicking the button above the top-left corner of the stage. At any time when the project is running you may press the stop sign to immediately stop the project, or click the green flag to restart the project.

Scratch automatically saves your work periodically, but if you want to make sure it is saved, select Save now from the Scratch editor’s File menu (not your web browser’s menu).

Congratulations! You have written a computer program that does something useful for magicians, and taken your first steps toward becoming a technomancer.

Make It Better

Meditaid is intentionally very basic to make it an easy first project. Below are some suggestions for modifying and improving it. Do not worry if you do not immediately understand how to implement these. I have included them here to inspire you to look beyond what is to what could be, and to think about how to improve on others’ designs and suit them to your own needs and tastes. After working with Scratch for a while, you should be able to return to this project and implement any or all of these suggestions and more.

  • Change the focus image (the middle costume) to something you prefer to gaze at while you meditate. Try sigils or psychedelic imagery, perhaps amplified by one or more graphic effects.
  • Include an ambient or hypnotic music track or drum beat.
  • Allow a selection from multiple focus images, alarm sounds, or background music.
  • Add some transitions, e.g., use the ghost effect to fade the middle costume out and the end costume in.
  • Animate the focus image. One way is to loop through a series of costumes. E.g., if you find an animated GIF file of a candle flame, you can import it into Scratch and the individual frames will be automatically added as new costumes for the sprite (instructions for doing this). Another way would be to draw the focus image as generative art—see e.g. this fractal kaleidoscope project, or one of the many other kaleidoscope projects.
  • Include a way to see how much time has elapsed or remains in the session.
  • Add a variable for hours so you can run sessions longer than one hour.
  • Add an interval notification, e.g., a chime that sounds every five minutes while the meditation timer is running. Include controls similar to those for seconds and minutes, that allow you to choose the interval time prior to running the timer.
  • The wait () secs block worked fine for this simple project, but it causes Scratch to literally wait until the set time has elapsed. If you need Scratch to do something during that time (such as animate an image), you need a different control structure to keep track of the countdown. Scratch has a timer block that keeps track of the number of seconds that have elapsed since the project started or since the reset timer block was last called. You could replace the wait () secs block with a repeat until () block that loops until the timer value is greater than (minutes * 60) + seconds.

  • Use the video blocks to detect if you move during the session and if so display an image or play a sound of negative feedback—nicer than getting struck with a keisaku, although with physical computing that too is possible. Or keep track of the number of times you move and display it at the end of the session: “You moved 3 times this session; try harder next time!” or “You moved 0 times this session; aces, chummer!”
  • What different kinds of meditation could be facilitated or enhanced by a computer? If you want examples of various meditation techniques, check out Principles of Meditation by C. Alexander Simpkins and Annellen M. Simpkins.

Credits

The hamsa (eye-in-hand) graphic was made by Lisitsa_.


  1. Technically, from 0 seconds to 59 minutes and 59 seconds.