The most effective way to learn something is to do it. These "Getting Started" recipes show how to build 3-D worlds using the Acorn language and its accompanying Type libraries. Each recipe focuses on a specific world-building goal, explaining key concepts using code examples. The recipes become progressively more advanced, building on concepts covered earlier.

To "cook" these recipes, you will need the Pegasus 3D browser, a text editor (e.g., Notepad++), and access to the Internet.

Goal

This first recipe offers a twist on a venerable programming language tradition: showing how to use a language to print out the text "Hello, World!" The twist is that instead of printing out text, we show how to make Acorn render a 3-D model of the world we call Earth.

Recipe

  1. On an HTTP server, or your PC, create a new folder called 'helloworld'.
  2. Copy into the new folder the following files retrieved from http:://ddd.pegasus3d.com/helloworld:
    • helloworld.acn
    • earth.jpg
    • texture_shader.acn
  3. Run the Pegasus3D browser and specify the location of your helloworld folder (e.g., http://ddd.yourserver.com/helloworld or file:///yourfolder).
  4. When you see your Earth displayed by the browser, feel free to greet it enthusiastically with "Hello, World!".

How it works

'helloworld.acn' is an Acorn program (Acorn programs use the extension '.acn'). When you open the 'helloworld.acn' program using a text editor, you will see this code:

$ = +World
	scene: +Group
		parts: +List <<
			+Shape.Sphere(1.0)
				shader: TextureMaterial
				image: @'earth.jpg'

Acorn programs look like outlines, with indented lines belonging to the line they are indented under. Indentations at the start of each line must be created using tabs. Each line is a distinct statement, an instruction to the browser on how to set up the world.

This is what this program does:

Variations

Many simple changes can be made to spice up this simple world. For example:

Using subsequent recipes, more sophisticated capabilities can be implemented. For example: