In this next worksheet you will learn how to display some weather data visually, producing a Weather Dashboard. You'll want to start a new Scratch file and enable the remote sensors, just like you did in the first worksheet.
The first thing you'll want to do is to choose a weather forecaster, who will be telling the viewers what the weather is like. Weather forecasters are often called meteorologists.
-
Choose a new sprite by clicking on the middle button as shown below:
-
Choose any sprite you like. Here we've gone for the
squaregirl
image:
-
You can start off by making your weather forecaster set the ID of the Weather Station you'll be using, by creating a new variable.
-
She'll then need to say a little bit about the location of the weather forecast. Use a
join
block (fromOperators
) within asay
block to begin with, just like you did in the first worksheet: -
Now grab two more
join
blocks. In the right-hand side of one, you can place thetown
the weather forecast is coming from. In the left-hand side of the other, you can place thecountry
of the weather forecast: -
Now the two
join
blocks can be placed together. It may not be obvious in the image, but you should add a single space character between the twosensor values
: -
With that done, you can place all three
join
blocks together into thesay
block: -
Your forecaster is now finished. Next, you can add some graphical elements to help users visualise the weather.
Next, you can make a weathervane. Weathervanes show the direction of the wind, but yours is also going to visualise the speed of the wind.
-
Click on the
New Sprite
button to choose another sprite: -
In
things
you should see aClock-hand
which is basically just an arrow. Import this sprite and delete any scripts that come with it:
-
When your weather forecast begins, you'll need to set the size and direction that the arrow points:
-
In
Motion
you should see aturn clockwise __ degrees
block. Add this to the bottom of the script. Then choose thewind_direction
sensor value, and add this block in: -
To visualise the wind speed, you can change the size of the arrow. Find the
change size by __
block (inLooks
) and add this to your script: -
To finish off, find the
__ * __
block inOperators
and use it to multiply thewind_speed
by10
. You can choose a different number if you like, though: -
This can then be added into the
change size by __
block:
-
Next, you're going to produce a working thermometer. You'll need a graphic to represent it, and the one below should be good enough. You can get a large version of it here.
-
Import this sprite into your Scratch program. You'll need to place this sprite in a very particular place, so it's best to add this into the script. You're also going to use the pen tool to draw the mercury inside the thermometer, but because you can't draw over the top of sprites, you need to stamp the sprite's image to the canvas first, and then hide it. This is the only script you'll need on the thermometer:
You'll notice the broadcast
at the end. This is going to be used to tell the pen to start filling in the mercury inside the thermometer.
-
Now you're going to need a new and very tiny sprite. Click on the leftmost button in the
New Sprite
menu: -
All you need is a single white dot in the middle of the screen. Draw a white dot and then click OK.
-
Now you're going to get this tiny pixel to draw a red line of mercury inside the thermometer. When the pixel receives a message to draw, it needs to set up its pen:
-
How the mercury is drawn will depend on whether the temperature is higher or lower than
0
. You write the code for temperatures above0
first: -
The first thing to do is to make the pen go all the way to the bottom of the thermometer, and for the pen to be placed
down
on the canvas: -
Next, the pen can move up to the
0
degrees mark on the thermometer: -
Then, depending on the temperature, the pen can move upwards on the
y
axis. You might want to tweak the values a little, but 1.7 pixels per degree seems to work fairly well: -
If the temperature is below zero, the pen needs to move to the
-30
degree mark: -
Then the pen needs to again move in the
y
direction. This can be achieved using a little bit of maths: -
The pen can then be placed into the finished script:
In worksheet three you'll learn how to fetch the weather from more than one Weather Station, giving you a global weather dashboard.