Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. Tutorials
  4. Colored Map of the 50 States in US (Difficulty: 3)

Colored Map of the 50 States in US (Difficulty: 3)

Scheduled Pinned Locked Moved Tutorials
1 Posts 1 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     

    The map of all 50 states in the US is a handy tool for creating interactive projects for social studies or geography. In this tutorial, you will learn to build a very basic demo that shows all 50 states in different colors. You will practice using table variables and clones along the way.

    states2.gif

     
     

    Step 1 - Remix the Template

     

    Please open the following project and remix it as your own project.

    play.creaticode.com/projects/6787f4c3b71b8505f221326c

    This project has only one sprite called “states”. It contains the costumes of all 50 states, in pure white color. It also includes a table with these columns about each state: state, x, y, shortname, color, saturation. You will learn how to use the costumes and this table in the steps below.

    states.gif

     
     

    Step 2 - Use Clone to Display One State

     

    Next, to keep it simple, we will first try to display one state. We will need to use a clone to represent that state, and hide the original sprite itself. This way, to show more states later, we just need to add more clones.

    8a1a6544-d72d-4211-b7ca-d6ac4a775714-image.png

     
    You can pick the costume of any state, such as “Florida”. When you run the project, you will see the map of that state at the center:

    98185cae-b14c-4883-9f60-325ef09e03fd-image.png

     
     

    Step 3 - Specify the State Using Clone ID

     

    In CreatiCode, when you create a clone, you can also specify a “clone ID”, which can be any text or number. This makes it easy to tell each clone to do something differently. In this step, we will set the clone ID to be 1. And when we select the costume, we will use the clone ID as the row number to read the state name from the “stateinfo” table. Since the clone ID is set to 1, we will get the first state in the table, which is “Alabama”:

    5b069b9c-82ea-4ce9-878c-587ed7218b09-image.png

     
    The program will show the map of Alamaba now when we run it:

    62c10244-e23e-439f-8532-a39af34d4773-image.png

     
     

    Step 4 - Move the clone to the given position

     

    To show each state at its correct position, we need to read the x and y positions of that state from the table, then make the clone go there. Again, we are still using the “clone ID” as the row number to index into the table.

    4fcb41a0-3b39-4cf1-a3c5-501b0be661a0-image.png

     
    Now we see the Alabama state in the correct position:

    6b655f4e-a6be-4f7a-bfb4-2482e4805e7d-image.png

     
     

    Step 5 - Add Color to the State

     

    We can also use color effects to change the “color” and “saturation” of the state, so that it is no longer white. We need to read these 2 columns from the table in a similar way, using clone ID as the row number:

    74020578-0c6f-4804-993d-1c5b900b5d09-image.png

     
    And now the Alabama state has a nice color:

    9bff28a5-5a02-441e-aee4-62153b054a57-image.png

     
     

    Step 6 - Print the Short name (Abbreviation) of the state

     

    Next, we can read the “shortname” column to get the 2-letter abbreviation of the state, and then “print” them at the same x and y positions. Note that this block is too wide so it is shown as 2 rows below:

    23adfa1f-aa8e-4b19-8eb0-9bbc4b6efbbe-image.png

    1fbe4b3e-3475-43a1-8591-1c15d3cadd3c-image.png

     
    This is what we get now:

    30acd6b5-3cd0-4866-9c0c-0226b5d9008b-image.png

     
     

    Step 7 - Make 50 Clones Using a For-loop

     

    To add all 50 states, we just need to make 50 clones with clone ID going from 1 to 50. An easy way to do it is to use a for-loop like this:

    f0a190b1-a5b3-4f2e-b6ce-f1f447d00d2a-image.png

     
    This will give us a complete map:

    77a2c857-cf2a-4e20-ba89-5e8dd22e9a28-image.png

     
     

    Step 8 - Random Coloring

     

    If you don’t like the default color/saturation that is given, you can color the states in other ways. For example, you can use 2 random numbers for the color and saturation effects. Note that the color effect takes any number between 1 and 200 (not 100), and the saturation is a number between 1 and 100. If you don’t want to use colors that are too “strong” or “light”, you can limit the saturation between 20 and 80 like this:

    655b1769-040f-4d96-af12-48b3a71693d6-image.png

     
    Now every time you run the project, you will get a new random color set:

    55b24254-a177-4baf-b01b-245415e1086f-image.png

     
     

    Step 9 - Faster Drawing (Advanced)

     

    You might have noticed that it takes a few seconds to draw all 50 states. This is because after adding each clone, the playground will update the stage to reflect that. If we just want to draw all 50 states quickly, we can use a common trick that disables “screen refresh”:

    Define a new custom block named “add states”, and check “Run without screen refresh” on the left:

    9a56e211-3190-45d5-bd2e-c3cc0a3ab174-image.png

     
    Next, move the for-loop inside the definition of this block:

    ab955487-4fb1-455a-8623-98145e148539-image.png

     
    Essentially, the program is running the same tasks, but the playground will not update the stage until all 50 states are added, so it is much faster:

    states2.gif

     
     

    Additional Challenges

     

    You can build many interesting projects based on this template. Here are some ideas for you to try:

    • Political Map: color each state red or blue based on its Republican or Democratic. You can either add a new column to the “stateinfo” table or use a list to store the names of all Republican states.

    • Shift the short name: Currently the 2-letter abbreviation is printed at the center of each state. However, it does not look good for some states, such as Hawaii, Michigan, New York, Idaho, etc. You can add 2 new columns of “xshift” and “yshift” to the “stateinfo” table, and fill in how much you want to shift the 2 letters from the center of the state. For example, if you want the “HI” to be printed below the Hawaii map, you can set the yshift for the row of Hawaii to be -30, and when you print the “HI” onto the map, add the yshift to the y position of the letters.

    • Interactive Map: You can make a state show a highlight whenever it touches the mouse pointer by changing its “brightness” color effect.

    • Zoom-in: When a user clicks any state, you can show an enlarged version of that state and other states near by. You will not only need to change the “size” of the clone, but also scale its x and y positions.

    1 Reply Last reply
    1
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode