Today was an introduction to the langauge an IDE, Processing, which is built upon Java. Although, it was less of a Java lesson and more of a 'Learn the Concepts to Developing in Code!'. It was good for me to hear what a professional had to say, because even though I knew the concepts, they were self-taught.
The concepts below are prefixed with a quote from Wikipedia.
Concepts
Variables
A variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents.In Java, we denote a variable like so: int age = 23. This says we have a variable named 'age', that it is an 'integer' and that its value is '23'!
Data Types
A data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type.In the previous concept, we prefixed our variable with 'int' to say that this data was an 'integer' - that is one form of a data type.
Conditionals
...conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.In Java, a simple conditional statement would look like this: if(age == 23) { "Simon is" + println(age); } If our age variable value was equal to 23, this would print "Simon is 23." in the console, if it was another value, it would do nothing.
'For' Loops
A for loop is a programming language statement which allows code to be repeatedly executed.I shan't write an example on my blog, because the formatting would make it impossible to read.
There are many different kind of loops, but they all do the same thing. They stop us from having to write lines of code to perform similar tasks. For example, instead of having to use ellipse() ten times to draw ten circles, we could loop over one, ten times.
Position and Animation
All shapes drawn to the screen have a position that is specified as a coordinate. All coordinates are measured as the distance from the origin in units of pixels. The origin [0, 0] is the coordinate is in the upper left of the window and the coordinate in the lower right is [width-1, height-1].Source: http://www.processing.org/learning/basics/coordinates.html
These are joint subjects as, we learnt that, to animate we had to change an objects position (well, duh!). In Processing, each object is drawn into position via a coordinate system, as explained above, and to manipulate an objects position, X and/or Y coordinates must change; these are changed through the use of operators.
This will be touched upon further, in a following post.
Collisions
Since we don't have actual physics to determine when there's been a collision, as we have in real life, we need to create a set of rules for when a collision has occured then implement those rules in our code.Source: http://beginwithjava.blogspot.com/2010/08/simple-collision-detection-in-java.html
This is more of a 'Coding with Physics' concept, and how to detect whether an object has collided with another; it fascinates me. For such a long time, I've wondered how games did this. Seb taught us how to this with a ball, and even how to give the ball gravity so that it dropped realistically! More on that, below.
Result
For each lesson, I will pick out one of my favourite examples of the day and explain how it functions. Shown below is Seb's example used to teach us how to make a ball collide with its bounding box.
Put simply, the ball has an X and Y position and so do the edges of our box. We know that the right edge of a 300 x 300 box will mean X = 300, Y could be anything. So, to make the ball bounce off the right edge of the box, we check its X position each frame. When it's X position equals 300, it's collided with the right side - all we do then is reverse the speed of the ball to simulate a bounce! The same's done for all four walls.
We were also set an assignment to complete over the Christmas holiday, more on that later!