Source code
The source code of the Layercake project is available on Bitbucket. It is written in Java and uses Maven as build system. The code has no external dependencies and should run out of the box with all Java 8 compatible runtimes.
The Git repository comes with one branch per chapter.
For example 01-gradient-noise
only contains the code discussed in the Gradient noise chapter.
You can find examples of how to use the code in the src/main/test
folder.
Those are not unit tests, instead they are intended to be run out of your IDE for experimenting with the code base.
License
All sources are licensed under the Apache License, Version 2.0. It is one of the permissive free software licenses. There is a good overview on Wikipedia.
Oh no, Java!
Don’t worry if you are inexperienced with or simply do not like the Java programming language. The code makes little use of Java specific language features and should be easy to read if you are familiar with C-style syntax.
However, some of the design choices were driven by Java’s memory model. The tutorial will try to point those out. An example is the rudimentary math package that is included in the source code.
Setup
If you have not worked with Java before, you can use the setup described int this section. There are of course many ways to get the code running, but I believe this to be the most approachable.
You will need to install a Java Development Kit (JDK) and an IDE. For the latter will use the community edition of IntelliJ IDEA.
If you are on Windows or macOS, you can either download Oracle’s distribution or a build from the AdoptOpenJDK project. If you are on Linux, you should be able to install OpenJDK via your distribution’s package manager. Make sure to download a JDK and not one of the runtimes (JREs).
You can download the community edition of IntelliJ IDEA here. Once you have installed the IDE you should be greeted with this screen:
If you have already cloned the Git repository, you can import it using the Import Project wizard.
Alternatively, you can check out the repository directly from the IDE.
To do so, click on Check out from Version Control and select Git.
In the next window specify https://bitbucket.org/jimknopf/layercake.git
as URL and clone the project:
The IDE will ask you whether you want to create an IntelliJ IDEA project. Click yes. This should open the following window:
It is important that you import the project as Maven model. Otherwise the IDE will have trouble understanding the project structure. Follow the wizard and use the default settings. Make sure the correct JDK is selected in the corresponding step:
The following screenshot shows the 01-gradient-noise
branch of the project.
You can switch between branches via the VCS menu or in the bottom right corner of the window:
To run the NoiseTexture.java
example in test/java
open the file and click on the small run icon next to the main method:
Once the process finished, you should see a new file named texture.png
at the top level of the project.
You can open it directly in the IDE:
As a next step I recommend looking into the debugging functionality of the IDE.
For example, you could set some breakpoints in Noise.java
and run the code again (in debug mode).