Book Image

Processing 2: Creative Coding Hotshot

By : Nikolaus Gradwohl
Book Image

Processing 2: Creative Coding Hotshot

By: Nikolaus Gradwohl

Overview of this book

Processing makes it convenient for developers, artists, and designers to create their own projects easily and efficiently. Processing offers you a platform for expressing your ideas and engaging audiences in new ways. This book teaches you everything you need to know to explore new frontiers in animation and interactivity with the help of Processing."Processing 2: Creative Coding Hotshot' will present you with nine exciting projects that will take you beyond the basics and show you how you can make your programs see, hear, and even feel! With these projects, you will also learn how to build your own hardware controllers and integrate devices such as a Kinect senor board in your Processing sketches.Processing is an exciting programming environment for programmers and visual artists alike that makes it easier to create interactive programs.Through nine complete projects, "Processing 2: Creative Coding Hotshot' will help you explore the exciting possibilities that this open source language provides. The topics we will cover range from creating robot - actors performing Shakespeare's "Romeo and Juliet", to generating objects for 3D printing, and you will learn how to run your processing sketches nearly anywhere from a desktop computer to a browser or a mobile device.
Table of Contents (16 chapters)
Processing 2: Creative Coding Hotshot
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Drawing a sprite


The first task for our current mission is to create a sprite showing a spaceship and make it move and rotate on the screen. We will make use of the translate() and rotate() methods that Processing provides. We will also generate the level design for our game and generate a landing platform for our spaceship.

To make the game more interesting, these levels will be recreated every time the game is restarted.

Engage Thrusters

Let's start creating the level design:

  1. Create a new Processing sketch and add the setup() and draw() methods, as shown in the following code snippet:

    void setup() {
    }
    
    void draw() {
    }
  2. Now we set the size of the window to 300 by 300 and define an array of integers, which we will use to draw our moon.

    int[] moon;
    
    void setup() {
      size( 300, 300 );
      moon = new int[width/10+1];
      for ( int i=0; i < moon.length; i++) {
        moon[i] = int( random( 10 ));
      }
    }
  3. In our draw() method, we add a light blue grid that fills a white page to make it look like we made our...