💻
Coding for Creatives Extras
  • Hello
  • Templates & Shortcuts
    • Power of Negative 1
    • Modifiers
    • Start Codes
      • Processing Start Code
      • HTML, CSS, JavaScript Start Code
    • WASD Movement Code
      • Processing Example
      • Unity Example (3D)
      • Unity Example (2D Platformer)
    • Connecting Platforms
  • Useful Links
    • Share & Show Off
    • Software and Apps
    • Free & Affordable Game Assets
  • Exercises
    • Week 1
      • Week 1 Processing Exercise
    • Week 2
      • Week 2 Star Wars Name Exercise
      • Week 2 Mad Libs Exercise
    • Week 3
      • Week 3 Moving Squares Exercise
    • Week 4
      • Week 4-A Movement Using If Statements
      • Week 4-B Boundaries Using If Statements
      • Week 4-C Hover, Click, and Drag Effects
    • Week 5
      • Week 5-A Moving Shapes
      • Week 5-B Looping Arrays
      • Week 5-C Using User Input to Create Arrays
      • Week 5-D For and Foreach Loops in Unity
    • Week 6
      • Week 6-A Snake
      • Week 6-B 2D Character Movement (Unity)
    • Week 7
      • Week 7-A Mario Coin Catch (Unity)
      • Week 7-B Raycasting Example (Unity)
    • TouchDesigner Exercises
      • Colorful Text
      • Audio-Reactive 3D Shapes
      • TouchOSC
  • Glossary and Terms
    • Blank Space / Canvas Origin
    • Shapes / Primitives
    • Color
    • Movement
    • Control
    • Variables
      • Declaring Variables
      • Assigning a Variable
      • Using a Variable
      • Data Types
        • Floating Point or Float
        • Integer or Int
        • Boolean or Bool
        • String
      • Casting a Variable
    • Arrays
      • Creating Arrays
      • Assigning Values to Arrays
      • Using Array Elements
      • Multi-Dimensional Arrays
      • Common Errors
    • Conditional Statements (If/Else)
    • Operators
      • Relational Operators
      • Mathematical Operators
      • Logical Operators
    • Loops
      • While Loops
      • For Loops
      • Foreach Loops
    • Functions & Methods
      • Creating a Function
      • Calling or Invoking a Function
      • Parameters & Arguments
    • Interaction
      • Mouse Interaction
    • Objects, Classes & Libraries
      • Accessing Objects
    • Node-Based Programming
    • Packaging and Sharing
  • TouchDesigner Info
    • Overview
    • Popular TOPs
    • Popular CHOPs
    • Popular SOPs
    • Popular DATs
  • Arduino Info
    • Arduinos!
    • The Parts
    • The Setup
      • Using the Serial Connection
      • Output Component Setup Examples
      • Input Component Setup Examples
      • Create a Night Light
Powered by GitBook
On this page
  • The Goal
  • Step 1: Create the Variables for the Four Steps
  • Step 2: Assign the Variables
  • Step 3: Print the Name
  • Step 4: Polish It a Little
  • Python Version

Was this helpful?

  1. Exercises
  2. Week 2

Week 2 Star Wars Name Exercise

The steps below walk you through a Processing activity we did during Week 2. All code should allow you to copy and paste.

The Goal

To find out your "Star Wars Name."

According to the graphic that has been shared all over Facebook, that's:

First Name:

  1. Take the first three letters of your last name.

  2. Add the first two letters of your first name.

Last Name:

  1. Take the first two letters of your mother's last name. parent's first name

  2. Add the first three letters of the city state in which you were born.

I changed the last two since the info (if you used real info) can be used for identity theft.

Step 1: Create the Variables for the Four Steps

These will be strings.

String lastName;
String firstName;
String parentName;
String state;

void setup() {
}

void draw() {
}

Step 2: Assign the Variables

Normally, these would be assigned after prompting the user and storing their response. To pretend that happened, let's assign the variables in the setup() function.

String lastName;
String firstName;
String parentName;
String state;

void setup() {
    lastName = "Moore";
    firstName = "Hope";
    parentName = "Michael";
    state = "Ohio";
}

void draw() {
}

Step 3: Print the Name

To get parts of the strings (i.e. "first 3 letters" etc.), we need to get the substrings of the variables we have. Let's use Processing's .substring() function:

.substring(index of first letter) starts the string with the index/location of the first letter.

.substring(index of first letter, index of limit letter) starts the string with the index/location of the first letter and ends on the letter before the limit letter

We'll use the second one since we need the beginning of each string. Remember to add a space between the second and third variables to show a separation between the first and last name.

String lastName;
String firstName;
String parentName;
String state;

void setup() {
  lastName = "Moore";
  firstName = "Hope";
  parentName = "Michael";
  state = "Ohio";
  
  println(lastName.substring(0, 3) + firstName.substring(0, 2) + " " + parentName.substring(0, 2) + state.substring(0, 2));
}

void draw() {
}

Output:

MooHo MiOh

Step 4: Polish It a Little

You'll notice the names have capital letters in the middle of each. We can make those lowercase by using the .toLowerCase() function. Just attach it to the end of the substring() function code to add the effect.

String lastName;
String firstName;
String parentName;
String state;

void setup() {
  lastName = "Moore";
  firstName = "Hope";
  parentName = "Michael";
  state = "Ohio";
  
  println(lastName.substring(0, 3) + firstName.substring(0, 2).toLowerCase() + " " + parentName.substring(0, 2) + state.substring(0, 2).toLowerCase());
}

void draw() {
}

Output:

Mooho Mioh

Python Version

Thanks to Nick Montana for providing an example in the discord. This has been modified to be similar to the exercise above.

In this example:

  1. variables are defined at the top and given initial values.

  2. The substrings are put into their own variables.

  3. Variables are created for each name of the Star Wars name.

last = "Moore"
first = "Hope"
pfirst = "Michael"
plast = "Ohio"

# Substrings
swfirst1 = last[:3]
swfirst2 = first[:2]
parent = pfirst[:3]
state = plast[:3]

# Create the names
starwars_first = swfirst1 + swfirst2.lower()
starwars_last = parent + state.lower()

print(starwars_first + " + starwars_last)

What to look at:

In python, substrings are controlled with square brackets [ ] and within them, the beginning letter and the end letter don't need a number to represent them. The "to", as in "from this letter to this letter" is symbolized by a colon ( : )

The function to make the string lowercase is .lower()

PreviousWeek 2NextWeek 2 Mad Libs Exercise

Last updated 4 years ago

Was this helpful?