Assignment 4 – House Picker

Concept:

For this project I decided to connect it to one of my favorite movies, Harry Potter. One of the best scenes in Harry Potter is when they have just arrived to Hogwarts and the are sorted into four houses (Gryffindor, Slytherin, Ravenclaw, and Hufflepuff) by wearing the sorting hat.

So I decided to use the generative text to sort all our names into these four houses randomly.

Highlighted Code:

function mousePressed() {
  if (csvLoaded && names.length > 0 && houses.length > 0) {
    // Once the mouse is pressed and the CSV is loaded, show the castle
    showCastle = true;
    
    // Pick a random name and a random house
    let name = names[int(random(names.length))];
    let house = houses[int(random(houses.length))];
    
    // Random House picker message 
    message = name + " is in " + house + " house";
  } 
   
}

The code that I am mostly proud of is the randomized picker. So when you press the mouse, the castle and stars appear and the random name picker starts, and when you press the mouse again another name appears.

Sketch:

Future Improvements:

For the future, I want to try to let the name be picked once and a name does not repeat, for example if it chose my name it should no choose my name again.

 

Leave a Reply