DEV Community

Ujjwal Goyal
Ujjwal Goyal

Posted on • Edited on

From thinking, to doing

"Perhaps you're laughing. Perhaps you're enjoying it. But that isn't the truth. Only I know the tragedy that's hidden behind your smile."
~One coder to another

Okay, that MAY have been taken from an anime, but it could very well be true. It's been 6 days since I took up the 100 Days of Code challenge, and there have been numerous moments when the aforementioned quote could've been said to me. That's not to say that there haven't been good moments, of course. Oh, the sheer joy of seeing the output you want! I reflexively clapped when that happened, and commended myself on a job well done. Here, I'll try to share my experiences over the past few days.

The road to the challenge

I'm not entirely new to coding. I've taught myself a bit of Python over the past few months, but it's never been consistent. It's always been in short patches followed by long breaks. But with college over, no other interests, and in eventual search of a job, there was no better time to take up the 100 Days of Code challenge and level up my skills while being regular. Okay yes, there's also the small matter of a deadly pandemic confining us to our homes for a still unknown length of period until we develop herd immunity or a vaccine is developed allowing us to carry on with life as usual, but I still would've done it. I hope.

The journey begins. Almost.

I found out about the challenge, and it seemed an excellent idea. Or as Ron Weasley would say, "Brilliant!" It would build up knowledge and experience over time, slowly, sure, but surely. It only required an hour per day, so it wasn't demanding too much. Perhaps most important, however, was the fact that I would publicly commit to the challenge, which as I've experienced, ensures consistency and accountability. It doesn't matter if you've been able to do what you wanted to or not, you put it out there for everyone to see.

So... Why didn't I get started as soon as I found out about it? I put it down to my tendency to be over-prepared and hesitant before embarking on something new. I kept researching for projects to contribute to, read posts on DEV and Twitter about coding, but didn't actually start anything. It's not a bad thing at all to read and think. It's important, but at some point there can be too much input. You do need to think what you're going to do before you do it, but you can also end up just thinking about thinking. So, if you're reading this and haven't started on something you thought you would, do it. It doesn't matter how you start off, it starts making sense eventually.

The journey begins, this time for real

I'd settled on working on Conway's Game of Life towards the end of my postponement phase. It was based on simple rules, and yet seemed so elegant. Here's my project so far.

On Day 1, I tried to make a visible 100*100 grid. To this end, I used matplotlib for the first time. I was able to create a grid alright, but I couldn't control its dimensions or how the cells would be filled. Just random gridlines. Making the axes labels and ticks disappear would come later, first I needed to solve the issue at hand. I was unable to do much however, and so I spent some time learning CSS via FreeCodeCamp, which allowed me to feel like I had achieved something on the day after all.

Day 2 was much better. I switched my approach, and using numpy (again, for the first time), I created a small 11*11 array of 0s. This essentially gave me a blank canvas, on which I could color the cells I wanted by assigning them a value of 1 and choosing a colormap (I went with binary) that visually reflected the difference in values. This method would not show gridlines, but that did not matter, for the animation did not require them to be plotted or visualized. In addition, I managed to clear away the axes ticks and labels, giving me a clean plot. I also wrote the game's rules, and all that was left was animating the plot. Surely that wouldn't be so difficult given the progress I'd made? Oh, how innocent I was.

Day 3 was spent trying to animate the plot, but to no avail. If I didn't use the FuncAnimation function I couldn't animate it, and if I didn't assign a colormap via imshow() then there was nothing to animate. I couldn't seem to get them to work together, so I tried looking for methods that would allow me to assign colors to values without using imshow. I still was as out of luck as movie halls in 2020.

I began day 4 from where I'd previously left off, trying to animate the plot. Not only did I not do it, I found out that the rules of the game, the one part of the code I thought was alright, was ridiculously wrong. I put the animation struggle on hold and fixed the rules. I was just testing to see if it was alright, when that happened. The animation worked. All by itself. Oh, I was so happy! Just goes to show that your problems may not lie where you think they lie.

Day 5 was the beginning of enhancing the project. I increased the array size to 51 * 51, allowing bigger animations. I also wrote some code specifically for the edges and corners of the array, thinking that I was getting index errors in some cases because of general description of all cells. Later, I realized that it made no difference, so I removed that block. The animation was also getting slowed down in later frames, so I added a function that would clear the previous image before plotting the next one. This however, brought back the ticks and labels, so after the clearing function, I cleared away the ticks and labels within the loop.

Today is day 6. I realized that the coding block I thought was redundant was not so after all. I found the earlier commit and merged it after some difficulties.

There is still more work to do on the project, but I'm very happy with what I've done so far. I honestly did not expect to get here so quickly, since the animations I'd seen before looked very complex. Judging by how it's been so far, there will be even worse days of work, but there'll be rewarding days as well, and I'm ready for it.

Top comments (0)