Create: Computing AgesBrass Docs
Devices

Camera

A closed-circuit camera: a computer shows live what it sees on its screen, at any size, and turns its head up, down, left and right.

The Camera is the closed-circuit television camera of a guard post: a computer shows what it sees on its own screen, and on the monitors that show that screen, and turns its head to look elsewhere. The picture is the world as the game draws it, live, with its textures, its light, its sky and everything that moves: one call opens it, at the size and the place you choose, and it stays live by itself.

Brass
local cam = peripheral.find("camera")
term.clear()
cam.draw()  -- what the camera sees, live, over the whole screen
Methods
cam.draw([x, y [, w, h]])Shows what the camera sees, live, on the computer's screen, in the rectangle of pixels you give.
cam.hide()Takes the picture of this camera off the screen. gfx.clear() takes off every camera, with the drawing.
cam.turn(yaw [, pitch])Turns the head from where it points now.
cam.set_angle(yaw, pitch)Points the head, whatever it pointed at before.
cam.angle()Where the head points now. The head keeps its angle when the program ends, and when the world is saved.

Setting up

Placing it. The camera hangs from the face you click. On a wall, it looks out of the wall; on a floor or a ceiling, it looks towards you. From there its head turns all the way round, left and right, and from straight down to straight up. A Create Wrench turns the whole camera a quarter turn.

Reaching it from a computer. Put it against a face of the computer (peripheral.wrap("top")), or against the computer's Data Cable, from the Minicomputer on: it is then named after its coordinates, like camera@120,64,-35, so a single cable brings the cameras of a whole base to one guard post. peripheral.find("camera") takes the first one, peripheral.list("camera") names them all. See Peripherals.

What it shows. The world as you see it in the game: blocks with their textures, the light of the day, of the night and of the torches, water, the sky and the weather, players, mobs, dropped items and Create's machines turning. It sees 70 degrees across the longer side of its rectangle, and 96 blocks away. Each player's own game draws the picture, from what that game has loaded: a camera farther from the player than the player's render distance shows NO SIGNAL.

Colours. Each screen shows the picture as well as it can:

screenthe picture
Modern Computer, LCD Monitor (whatever the computer)as the game draws it, in its true colours
Personal Computer, Microcontroller, and a CRT Monitor on themeach pixel in the nearest of the 16 colours
Transistor Mainframe, Minicomputer (green and amber phosphor)in four shades of the phosphor's glow
Tube Computernone: it prints on paper, and draw stops the program

What it costs. Nothing for the program and nothing for the server: the server only tells the players' games which camera goes where on the screen. Each game draws the world again for each camera on a screen it looks at (the terminal open, or monitors in view), up to 30 pictures a second each: a camera nobody looks at costs nothing. Each player can change how far the cameras see, how often and how fine they are drawn, in the client config (viewDistance, frameRate, resolution). The pictures are not drawn with Sodium, Embeddium, Iris or Oculus installed.

Showing what it sees

#

cam.draw([x, y [, w, h]])

Shows what the camera sees, live, on the computer's screen, in the rectangle of pixels you give.

Parameters
x number optional
the left edge, in pixels of the screen from 1; 1 when left out
y number optional
the top edge; 1 when left out
w number optional
the width in pixels; up to the right edge of the screen when left out
h number optional
the height in pixels; down to the bottom of the screen when left out

The picture lies above the background of the text and below the gfx drawing and the characters: clear the text with term.clear() first. Opening it erases the drawing in its rectangle; what you draw over it afterwards stays on top, a crosshair or a caption. It stays live when the program ends, until cam.hide() or gfx.clear(). The parts of the rectangle outside the screen are cut off. Calling draw again with another rectangle moves the picture; with the same one it does nothing. A screen shows four cameras at most.

Brass
local cam = peripheral.find("camera")
term.clear()
cam.draw(1, 1, 192, 108)  -- the top left quarter of a Modern Computer

When it fails:

  • on a Tube Computer: a camera needs a screen with pixels: the Tube Computer prints on paper;
  • with four other cameras on the screen: a screen shows 4 cameras at most: hide one first;
  • when the camera was broken: camera removed.

See also camera.hide() camera.turn() gfx

#

cam.hide()

Takes the picture of this camera off the screen. gfx.clear() takes off every camera, with the drawing.

See also camera.draw()

Turning the head

The angles are in degrees from straight ahead of the mount: the yaw goes from -180 to 180, to the right (negative values to the left), the pitch from -90 (straight down) to 90 (straight up). The head turns at once for the program, and players see it swing there in a quarter of a second, the picture with it.

#

cam.turn(yaw [, pitch])

Turns the head from where it points now.

Parameters
yaw number
degrees to turn to the right; negative to the left
pitch number optional
degrees to turn up; negative down; 0 when left out

Past 180 degrees, the yaw goes on from -180: the head turns round and round. The pitch stops at straight up and straight down.

Brass
local cam = peripheral.find("camera")
cam.turn(-15)    -- a little to the left
cam.turn(0, 10)  -- a little up

A bad angle (a text, a number that is not finite like 0 / 0) stops the program with bad argument #1 to 'turn' (...).

See also camera.set_angle() camera.angle()

#

cam.set_angle(yaw, pitch)

Points the head, whatever it pointed at before.

Parameters
yaw number
degrees to the right of straight ahead, -180 to 180
pitch number
degrees up, -90 to 90
Brass
cam.set_angle(0, 0)     -- straight ahead
cam.set_angle(90, -30)  -- to the right, looking down

A yaw beyond 180 is turned back into -180..180 (270 is -90); a pitch beyond 90 is 90.

See also camera.turn() camera.angle()

#

cam.angle()

→ table

Where the head points now. The head keeps its angle when the program ends, and when the world is saved.

Returns
table
{yaw = degrees to the right, pitch = degrees up}
Brass
local a = cam.angle()
print("yaw " .. a.yaw .. ", pitch " .. a.pitch)

See also camera.turn() camera.set_angle()

Examples

A guard post with the arrow keys

The picture is live by itself: the program only waits for the arrow keys, and turns the camera.

Brass
local cam = peripheral.find("camera")
term.clear()
cam.draw()
while true do
  local e = os.pull_event("key")
  if e.key == "left" then cam.turn(-10) end
  if e.key == "right" then cam.turn(10) end
  if e.key == "up" then cam.turn(0, 10) end
  if e.key == "down" then cam.turn(0, -10) end
end

On a wall of LCD Monitors against the computer, the whole guard post watches the picture in true colours.

Four cameras on one screen

Four cameras on the computer's Data Cable, each in a quarter of the screen.

Brass
local s = gfx.size()
local w, h = math.floor(s.w / 2), math.floor(s.h / 2)
term.clear()
for i, name in ipairs(peripheral.list("camera")) do
  if i <= 4 then
    local col, row = (i - 1) % 2, math.floor((i - 1) / 2)
    peripheral.wrap(name).draw(1 + col * w, 1 + row * h, w, h)
  end
end

The program can end: the four pictures stay live on the screen.

A caption over the picture

What gfx draws after the picture stays on top of it: here the name of the camera and the time of day, redrawn every second.

Brass
local cam = peripheral.find("camera")
term.clear()
cam.draw()
while true do
  local t = os.day_time()
  local clock = string.format("%02d:%02d", (t // 1000 + 6) % 24, t % 1000 * 60 // 1000)
  gfx.rect(1, 1, 48, 9, "black", true)
  gfx.text(3, 3, "GATE " .. clock, "red")
  sleep(1)
end