So you have an idea for your project, but now you have to think about how to actually make it. This calls for starting to think both in terms of the experience you want to create as well as how that translates to programming. So let’s think about how to turn an idea into something more like a plan for program.
Here’s the idea we’re going to pursue:
A frog eating flies
Clearly this is pretty basic and there are a ton of ways you could think about this as a program. It could be an animation, it could be a game, it could be a simulation.
So we need to go from this basic idea to a more specific experience we want to create.
Let’s specify our experience further like this:
The user controls a frog at the bottom of their screen and can trigger the frog’s tongue to shoot out. A fly flies around on the screen and if the tongue hits the fly it gets eaten.
In doing this, we’ve already made some decisions about what is in our experience and also what happens. For instance:
So even expanding our idea a little bit has led to much more clarity about what this project is. At this point we might even have early thoughts about how to do some of these things in code, like:
And more. Our aim is to keep refining our project specification until it is more and more like a total explanation of everything that will need to be in our code.
So let’s get more detailed by answering some questions like
By asking those questions we can get even more specific:
- The main character is a frog drawn out of shapes at the bottom of the screen, facing up
- The user can move the frog left and right with their mouse position (
mouseX, anyone?)- The user can shoot out the frog’s tongue by clicking the mouse
- The fly starts on the left side at a random height and moves to the right in a straight line
- If the end of the tongue hits the fly, it is caught and resets to the left
- If the fly reaches the righthand side it resets to the left
This is now a pretty good specification of something we could start to plan out in code! There are still things that are underspecified, like exactly what the frog and fly look like, or how fast the tongue moves, or the speed of the fly, but these are likely things we’ll want to figure out once we’re working on the code itself.
The next step would be to think about this more in terms of what needs to happen in the program version of this. Particularly thinking in terms of the key things we need to represent (in variables) and the things that will happen both at the beginning (in setup) and each frame (in draw).
It usually makes sense to identify anything in our experience we can think of as a coherent entity (like a frog or a fly) and to think about it as an object with specific, useful, properties.
So we have
What will we need to know about the frog at its most basic (imagine it’s just a circle for now perhaps):
The fly is simpler than the frog, it’s really just a thing moving from left to right all the time, so we need:
So we could imagine something like this:
frog
body
x
y
size
tongue
x
y
size
speed
state
fly
x
y
size
speed
We should be able to translate this into code when the time comes.
Thinking in terms of a p5 program, the most important things to think about are
setup())draw())We probably don’t need to do much here. We could just create the canvas?
There’s more to think about here! We have to think about:
So lets write that down as a series of steps:
The main event we need to think about is the user clicking to send the tongue out.
Well, now we have a pretty detailed plan of how to make this (admittedly not super-duper complicated) little froggy experience.
The next step (before starting our program) is to try to get even more specific about how the program will work by turning it into “pseudocode”.