Basic movement and timing

This example illustrates how to:

Node algorithms are written by extending the Node class, here in a class called MovingNode.

import jbotsim.Node;

public class MovingNode extends Node{
    public void onStart(){
    public void onClock(){

You can tell JBotSim to use this class by default as follows.

public static void main(String[] args) {
    Topology tp = new Topology(400, 300);
    new JViewer(tp);

Clock and Timing: onClock() allows you to perform some operation periodically, such as, here, moving your node. onStart() allows you to initialize your node, here, by giving a random direction.

Movement Specification: Movements can be specified in many ways. Here, we first set an initial direction; then the node moves by one unit in this direction in each round (using the move()). (This method can also take an argument, specifying the distance to be moved.) Method wrapLocation() re-locates the node in a toroidal fashion when it gets out of bounds.