Creative programming

Course reflection

A few years ago I wanted to learn how to program. So I bought the book “Java in 24 hours” by Rogers Cadenhead. I read through the first hours and made the examples. However after having made eight chapters in the book I didn’t have the idea that I knew how to write my own program. That was a big hit for my motivation and I decided to put the book away.

When I heard that programming would be one of our first courses, I was very excited. I was finally going to learn how to write code. After the first lecture, I read all the corresponding chapters in the book. That was a great addition to the information given in the lecture.
I started working on the homework for that week, and soon I had my rotating name that followed the cursor wherever it went. Getting the color to change in a way that I liked was a bit trickier. At first, I had the color change random, but this resulting in chaos. I later made four color options that changed based on a variable that got bigger every frame and reset if a certain condition was met.

For fun, I started on programming something like pong. I started with a circle that bounced on all the edges. I later tried to add a player controlled bar to have the ball bounce on. This is where I stopped. The course continued and there were other assignments. I might revisit the project, but I am more interested in starting with Arduino.

As a short side project, I programmed a framerate counter that displays the framerate in the top right corner. I wanted to display the framerate as a whole number, but the framerate is a floating point value. Mathias explained to me that you can convert a floating point value to an integer by using code like this: int frame =(int) frameRate; With this, I could program the basic counter.
The next problem was that it would update the framerate every frame this gave a constant switch between 60 en 59 for the standard framerate. I tackled this problem by taking the framerate every 5 frames and displaying that value til the next update. This made the counter better to read. For convenience, I put the code in a function so it could be easily put into any program.

The challenge where we had to program discs that didn’t overlap with a random was quite a lot harder than the challenges before. Using arrays was rather hard at first. One reason for this was my misconception about how 2D arrays work. I thought that every column of the array got its own brackets. For example, an array with three columns would look like: Array[][][]. I asked Tjeu to help me since he had already written the program. He explained to me the way arrays work and he sent me his code.
I did not want to copy any of his code, but I did use it to get an understanding of how the program could work, and that helped me write my own code. I copied one small part of his code, that was the Boolean that compared the current disc to all the previews ones to see if there was no overlap.
I wrote my code is a way that it would redraw the current circle until it found a viable sport for it. Using println() and an extra value I could see how many tries it took to draw each circle. When drawing a large amount of circles it could take a couple of thousand tries for some of the circles, especially the last ones.
Adding the different colors was doable, but I used Tjeu’s code as an inspiration for this as well. He used the color mode HSB and a mapped value, this made it much easier to get the different colors and choose how many different colors you wanted.

For the challenge, I did not have any inspiration whatsoever. I did not want to draw a lot of lines and shapes to create a picture. I wanted to make something that was mostly generated my loops and functions. During one of the lectures someone who was sitting next to me was making a picture that was shown in small squares, bigger pixels basically.

This gave me the idea to use a similar basis for my design. But instead of squares, I wanted to use circles that I named Pixels in the code. First I tried to make the array that would generate all the coordinates for the Pixels. I succeeded in some kind, but all the rows and columns had the same place in the array. But instead, I wanted every Pixel to have its own place in the array. Tjeu, who had made a similar program helped me with the loop that generates the coordinates and draws all the Pixels.

Now I had the same problem as I had before, I didn’t have any inspiration. Just for fun, I made different blocks with colors, and I toyed around with random colors. Having done this I decided to depict a photo via the Pixels. Using a variation in brightness the picture would be shown. I added an extra array to store the information for the color.
I tried different pictures and eventually continued with a picture of Steve Jobs. I removed the different colors from and instead used one. At this moment the render reminded me of the work of Andy Warhol and I decided to make four pictures next to each other in different colors. This was rather easily done by shifting over the picture several times and just adjusting the width of the render. In the code, it is very easy to adjust the size of the Pixels, and the Hue step for the different colors.

Making this challenge gave me a very good understanding of the way arrays and loops can be used to generate lots of circles for example. It gives me an understanding of how useful programming is for an Industrial Design student. I am really looking forward to working with Arduino’s to make and create interactive products and designs.