Sometimes simple can be tough.
I had a bit of a tough time getting my API project to work last week. So this week I figured I would do the most basic version of last week’s API project, and combine it with the simplest version of this week’s assignment – modifying a pre-loaded image.So, first things first, making the API work.
Step by step following the coding train, I built up a p5 page, and I accessed the API for openweathermaps.org.
I got it working to the point where it displayed the temperature given a us ZIP code hard-coded into the program. The goal was ultimately to be able to manipulate a photo to be either more blue or more red given the value of a city’s temperature in Fahrenheit. I felt like I was off to a good start, I just needed to add in the right html code to be able to let the user type in their ZIP code on the web page.
Then my code broke.
I don’t know exactly what happened, but, while I was able to get Javascript to recognize the code typed into the field defined in HTML, I lost all access to the Open Weather Maps API. I scoured the Coding Train videos again looking for what had gone wrong, but I couldn’t get it to work. At this point, I needed to work on other projects, so I had to set this aside for a couple days.
My project was only saved when somebody on the floor showed me a similar project created for the answer to a quiz question created by another ITP student. That code had fixed whatever problem I was having, and was able to print out the temperature from a given city in the browser’s console. I don’t know what the difference was between the code that I wrote and the code that I copied, but the new code worked. Next week I’ll have to look more closely at what I did wrong.
Now all that was left to do was create some modifications to concepts we had covered in class. I set up a for loop to pixelate a picture of my dog
Because of course.
If the temperature is warm, she shows up as red, and her circular pixels are large.
If the temperature is cold, the pixels are small and blue.
And if medium, she’s a little purple-ish.
Whew. It’s not the most awe-inspiring bit of code I’ve ever written, but the dang thing works, and I’m counting that as a success.