Posts

Environment Problems

Image
I was excited to start reading a new book today. It is Tiny Python Projects. From the get go, the author wants to have you executing PyTest unit tests. Sounded legit to me. However I encountered a problem with the very first test. It complained that python3 was not a valid command. Well I am on Windows 7. My python install has a program called python. There is no python3. Easy enough. I created a python3 program that was a copy of the python one. Got past the first 2 tests. Then it bombs on the third test. The error message is not clear. The book says you will get an error message. But the book error is not the same as my error. It seems that the test is trying to issue some Linux style commands. But hello. That does not work on Windows. To be fair, the book recommends you install the "Windows Subsystem for Linux". Again, this is not going to work for my computer. WSL requires at least Windows 10. I am stuck on Windows 7. I get the feeling this book is specifically written fo...

Langton's Ant

Image
I have been going through this book that has a ton of Python projects. One that had a lot of bang for the buck was Langton's Ant. You give this ant some very simple rules to follow. Then it makes weird patterns on the screen. There are only two types of squares on the board. In my version, I made them periods and each (@) signs. Here are the rules I coded for the ant running around: On a period, turn to the right and change the spot to an @ sign. Move forward. On an @ sign, turn to the left and change the spot to a period. Move forward. That's it. This will allegedly form somewhat symmetrical patterns on the screen. Also the ant will eventually devolve to a repeating long pattern. I did not let the thing run along to confirm either of these assertions. I just enjoyed the weird patterns.

New Uses for Matplotlib

Image
Today I discovered the matplotlib_venn module. It allows you to produce Venn diagrams. I coded up a program to simulate a questionnaire about different sports that students play. Of course one of the sports questions was about football. But another question asked if any other sports was played. Wanted to show both of these questions, plus the overlap. It would have been nice to label the circles "Football" and "Other". However I found that while I could add those labels, the original A and B labels remained. The result was labels written over top of each other. I could not easily find out how to replace those original labels. Might need to dig deeper into this new module.

From Zero to Hero

Image
I was stuck reading this book Python Playground. But I was not learning anything. The projects did not allow me to try to implement them myself. The description of the projects were interlaced with the solutions. After getting lost in a chapter about OpenGL, I decided to punt. Surprised I made it through almost 10 chapters of this book. Instead I moved on to a book called Math Adventures with Python. I am a bit apprehensive. One reviewer claimed that this book actually does not use Python. Instead it uses a program called Processing. For now, the beginning of the book indeed uses Python. If it skips to Processing, I will bounce quickly to another book. The first chapter has me drawing cool stuff with the turtle module. I produced a circle using only squares. The pattern is neat, if asymmetrical. I hope there is a lot of Python and minimal Processing involved in future chapters.

Making a Mosaic

Image
I made a cool program today. Not sure if it works exactly how it should. Still cool though. I started with some image I got from the Internet. It was some art work. My goal was to slice up the image into a grid. Then I would swap out each tile from that grid with another image that was closest in color to the original grid image. The goal was that the resulting image would be made of a whole lot of smaller images. And at a distance, you could see the shape and outlines of the original images if you looked at the new mosaic of small images. Well my final resulting image does not look a lot like my original image at any distance. It was still a cool experiment. My source of mini images to swap in was a directory full of around 50 celebrity images. Maybe if I had a lot more images, and they were not just pictures of celebrities, then my resulting mosaic could look a bit more like the original image. The funny part of this exercise was when there were bugs with my logic. Then my final imag...

Game of Life

Image
I am working through projects in a new book. This chapter has us implementing the Game of Life. The book solution has you employing the numpy and matplotlib modules. I chose pyGame instead. I wanted to make my job easier. So I just forced the border to be all black (off) cells. And I never update them. That way I can check all the neighbors around the cells I do update, and don't have to worry about going off the grid. It turns out Python is just too fast computing the new state of all the cells. Left alone, it proceeds so fast, I cannot experience the life cycle. So I just end up putting myself to sleep for a half second every iteration. That does the trick. When I let the simulation run, just as in the real world, everything dies out. Then I end up with a black screen. I had thought there might be some scenario where life repeats in a never ending pattern.

Book is no Playground

Image
I started reading the book Python Playground today. Went through the first 2 chapters. With a subtitle of "Geeky Projects for the Curious Programmer", I thought I had a hit on hand. Well it turns out this might have some projects. But the book just gives you the code for the projects. I don't have a chance to implement the projects myself. That is just no fun. Might have to just toss this book aside. There is one small hope. In the next chapter, I read enough of a description before looking at the code. And I think I just may be able to try to implement the program myself. However if the rest of the book is anything like the first 2 chapters, this thing is definitely going to get tossed. The real crime is that I purchased a new print copy of this book this year. It feels like that was a royal waste of money. The lesson learned is that I need to be able to predict whether a book will give me the opportunity to write code for the projects presented. Not sure how I will acco...