Back to All Assignments

Assignment 4

Brian Kang

Feb 15, 2023

Elegant Orbit

Behold, my demonstration of 2 planets flying through the universe while dancing around each other.

Not sure if this program is more appropriate for week 3, but I just made it today (Feb 15) and wanted to document it. Also the fun part about this is that it's almost entirely generated by Chat GPT, so thanks Chat GPT. I used it to generate the basic mechanics, like the structure of the class and its show method, but I added quite a lot of customized tweaks here and there.

I began with a prompt to write the planet class for me, and I gave it very specific requirements.

It then wrote out the class for me, but I realized I had probably actually just wasted effort for this first step because writing the prompt in plain english was literally longer than if I had just written the code direclty.

I then asked it to make a quick change, which it did perfectly:

Then I asked it to add a "show" method to the planet class and make the radius of the planet proportional to its mass, which it did.

Thus far, it was all pretty simple handiwork, nothing sophisticated. But then I prompted chat to make the planets move and be attracted to each other by gravity. This is where chat GPT really started to show its power:

It didn't work immediately right off the bat, I had to make some minor changes to the G constant and such.

I can't show the entire process here because it was too long, but chat GPT was extremely helpful in writing it. I don't think you could say it's replacing the programmer's job or anything, because it still takes a coder knowledgable in the mechanics of programming to write the appropriate prompts to chat GPT. I also had to continue to tweak it here and there. I still had to conceptualize the whole structure of the program.

Chat GPT was not only useful for building out the framework of the code, it was also a delight to use for the little issues. For example when I forgot how to do exponential calculations, all I had to do was ask:

I also asked it whether naming a variable "color" would give me keyword issues:

Whereas normally resolving issues like the one above would take me some trial and error, and some digging into the documentation, Chat GPT saved me a lot of time by answering the question directly.

At one point I was curious about what the default number of octaves the noise function uses, a question which would be downright impossible to figure out on my own. The only way to answer the question would be to do some googling, and searching around documentation, which may or may not give me the answer I need. Chat GPT gave me the answer instantly:

In the end, Chat GPT was like a super efficient tutor who could help me with anything and everything, and explain it to me perfectly. It was still just a tool, it didn't and couldn't make the entire program for me without me working it. It really just helped with the laborious tasks, like writing out code I already know how to structure in my head, syntax questions, and debugging. Chat GPT helped me work smarter, and not harder.

Arrow Chaser Game

This one is truly insane. I made an entire game, almost entirely with Chat GPT. I didn't even intend to go so far at first, it's just that Chat GPT makes things so I easy I just found myself playing around with it just to see how far I could take it. After a few hours of back and forth, this is what I came up with:

It all began with one of the exercises in the NoC book:

So I basically gave it that exact prompt, while specifying that using the arrow keys should accelerate the car and it should slow down gradually when I'm not "accelerating". Notice how well chat handles such specific prompts:

And then it just gave me the whole damn thing, including the setup() and draw() code to get it running. Of course there's much more not shown in this screenshot, I just had to cut it off to save space.

I plugged in the code chat made for me, and this is was the result:

Basically perfect, other than the fact that the arrow is pointing in the wrong direction. Which of course, I was able to ask it to fix:

Having got the basics of the arrow mover down, it was just a matter of adding small changes to turn it into a full fledged game (although there were a lot). It was a long process, so I'll just show a few highlights here.

First, I added the "enemy" arrows that chase the player around the canvas.

It gave me a "chase" method to add to the arrow class. However, I wasn't happy that the class wasn't using vectors to store its position and velocity. I asked it to rewrite the whole class to incorporate the change.

I thought this was one of the coolest changes it made. At one point, I felt like the game was too easy because enemy arrows were unable to teleport across the canvas, while the player was. I asked chat to make the enemies smarter, so that instead of chasing the player all the way across the canvas, they would have the ability to teleport across the canvas, and intelligently calculate the shortest distance needed to reach the player. All some very high-level instructions, that chat GPT would have to do a lot of human-like language interpretation to pull off. Which it did, flawlessly.

Not only did it understand and solve my problem perfectly, it gave me an easy-to-understand breakdown of how it did it. It has an enemy arrow calculate the raw x and y distance between itself and the target (the player), and if it's greater than half the length of the canvas, it chooses to go the other way. Nothing I couldn't have come up with on my own, but it did save me some effort and time.

Like I said, working smart, not hard.

Here's the truly fun part. I realized it's really time consuming and tedious to do all this documentation showing my process in making the program. So I just asked chat GPT to do it for me. Although chat didn't have access to every step I took on my own developing the game without it, it did I pretty good job on its own too. Here's Chat GPT's side of the story:

NICE.

The final product:

Spring

I struggled with the spring a lot. Even though it's conceptually nothing super hard, it was tedious to code. I didn't use chat GPT either, becuase it seemed like it would be even harder to type out a prompt in plain english than just code it myself. This was my semi-succesful result in the end (drag the ball to stretch the spring).

I did use chat GPT to see how it would implement the spring class, but it turned out to be basically the same as Professor Shiffman's example. I just tried implementing the whole thing myself to get a conceptual grasp on how this thing works.

Wish I had more time to do some more sophisticated work with springs. For example I wanted to implement a whole soft body object with springs, but before I could do many, of course, I had to do one. I didn't get that far unfortunately.