Interface Sketch


public interface Sketch
Base interface for all framework sketches.

setup(Graphics) is called once, before the first frame. render(Graphics, Frame, Params, Input) is called every frame. Subinterfaces may add lifecycle hooks for other kinds of content.

Usage:


 public class MySketch implements Sketch {
     public void render(Graphics g, Frame f, Params p, Input in) {
         g.background(30);
         g.fill(255);
         g.circle(g.cx(), g.cy(), 40 + 20 * Math.sin(f.time()));
     }

     public static void main(String[] args) {
         SketchApp.run(new MySketch());
     }
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    render(Graphics g, Frame f, Params p, Input in)
    Renders one frame of the sketch.
    default void
    Initializes sketch resources before rendering begins.
  • Method Details

    • render

      void render(Graphics g, Frame f, Params p, Input in)
      Renders one frame of the sketch.

      Usually called about 60 times per second, but the actual frame rate can vary. Use f.dt() for movement rather than assuming a fixed time between frames.

      Parameters:
      g - the graphics context for drawing
      f - timing and frame-count information for this tick
      p - interactive parameters (sliders, toggles, etc.); may be Params.NO_OP when the GUI is disabled
      in - mouse and keyboard state for this frame
    • setup

      default void setup(Graphics g)
      Initializes sketch resources before rendering begins.

      Called once, after the graphics context is ready. Load images and create reusable resources here rather than in render().

      Parameters:
      g - graphics context