window

v0.1.7
createWindow(w, h, [mode]);

Create a GLFW window.

Arguments

wWindow width
hWindow height
[mode]Rendering mode, either GL2D or GL3D, by default GL2D is set.

function setup()
  createWindow(100, 100);
end

function draw()
  background('magenta');
  -- draw things
end

Output

See createWindow in window.h
noLoop();

Prevents lu5 from calling draw again.

When noLoop is called, the draw continues execution, but will not be called again.

angle = 0;
radius = 100;

function setup()
  createWindow(300, 300);
  
  textAlign(CENTER);
  noStroke();
end

function draw()
  background('purple');

  text('Click to pause', width/2, height/2);

  circle(
    radius * cos(angle) + 150, 
    radius * sin(angle) + 150,
    16
  );

  angle = angle + 0.05;
end

function mousePressed()
  noLoop(); -- Stop loop
end

function mouseReleased()
  loop();
end

Output

See noLoop in window.h
loop();

Allow lu5 to call the draw function.

angle = 0;
radius = 100;

function setup()
  createWindow(300, 300);
  
  textAlign(CENTER);
  noStroke();
end

function draw()
  background('purple');

  text('Click to pause', width/2, height/2);

  circle(
    radius * cos(angle) + 150, 
    radius * sin(angle) + 150,
    16
  );

  angle = angle + 0.05;
end

function mousePressed()
  noLoop();
end

function mouseReleased()
  loop(); -- Start back the loop
end

Output

See loop in window.h
frameRate(fps);

Set the frame rate.

Arguments

fpsThe frame rate to set

If frame rate is called without an argument, it will return frame per seconds

x = 0;
r = 16;
speed = 50;

function setup()
  createWindow(200, 200);

  frameRate(30); -- Set the frame rate
end

function draw()
  background('purple');
  text('fps: ' .. frameRate(), 20, 30);

  square(x, 100, r);
  if x > width+r then 
    x = -r;
  else
    x = x + speed * deltaTime;
  end
end

Output

x = 0;
r = 16;
speed = 50;

function setup()
  createWindow(200, 200);

  frameRate(12); -- Set the frame rate
end

function draw()
  background('purple');
  text('fps: ' .. frameRate(), 20, 30);

  square(x, 100, r);
  if x > width+r then 
    x = -r;
  else
    x = x + speed * deltaTime;
  end
end

Output

See frameRate in window.h
saveWindow(path);

Save the current window into an image. Acts as a screenshot.

Arguments

pathThe image path to write to.

In this example, press the mouse to save a screenshot of the window.x

function setup()
  createWindow(300, 300);
end

function draw()
  circle(200, 200, 32);
  fill(255, 50, 100);
  square(200, 200, 32);
end

function mousePressed()
  saveWindow("./screenshot.png");
end
See saveWindow in window.h
widthGlobal

The window's width in pixels. If no window was created, this value is nil.

See width in window.h
heightGlobal

The window's height in pixels. If no window was created, this value is nil.

See height in window.h
deltaTimeGlobal

Elapsed time since the last draw call in seconds.

x = 0;
vx = 128;

function setup()
  createWindow(400, 400);
  frameRate(24); -- try with 60
end

function draw()
  background('purple');

  circle(x, height/2, 32);

  -- Get the same velocity with different framerates
  x = x + vx * deltaTime;
end
See deltaTime in window.h
windowResized();Event

Called when the window is resized.

function setup()
    createWindow(500, 500);
end

function draw()
    background('purple');
end

function windowResized()
    print('Resized!');
end
See windowResized in window.h