Scrap Mechanic

Scrap Mechanic

Not enough ratings
Camera Module
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
107.118 KB
5 Oct, 2021 @ 1:23pm
30 Dec, 2021 @ 6:33am
4 Change Notes ( view )

Subscribe to download
Camera Module

In 1 collection by wingcomstriker405
My Mods
17 items
Description
This mod adds a camera to the game that can be used to take images to analyse them :)
Note: Place the camera with the round end of the AND symbol facing upwards
SMPL API
getCameras parameters: [] description: returns all cameras connected to the computer setResolution parameters: [camera, width, height] description: sets the resolution that the camera renders setFov parameters: [camera, width, height] description: sets the fov of the camera setMode parameters: [camera, mode] description: sets the mode of the camera Camera.DISTANCE Camera.COLOR Camera.TYPE setCastsPerTick parameters: [camera, amount] description: sets how many raycasts a camera performs per tick setRange parameters: [camera, range] description: sets the number of units the raycast goes capture parameters: [camera] description: starts the capturing process isCapturing parameters: [camera] description: returns if the camera is currently rendering getData parameters: [camera, x, y] description: returns the data for a specific pixel. depending on the mode... DISTANCE -> Number TYPE -> String COLOR -> Tupel ( r: Number, g: Number, b: Number ) ALL -> Tuple ( hit: Boolean, distance: Number, type: String, color: Tuple ( r: Number, g: Number, b: Number ) ) getResolution parameters: [camera] description: returns the resolution of the camera as a tuple (width, height)
Example
This is a simple example that uses the camera and the screen. This is what the program is doing (in general) 1. setting up the screen 2. setting up the camera 3. capturing an image 4. render the image to the screen
import Screen import Camera import Math II.setClockSpeed(10000) screen = Screen.getScreens()[0] (screenWidth, screenHeight) = screen.getResolution() screen.setSize(96, 54) print('clearing screen') screen.fillRect(0, 0, screenWidth, screenHeight, (0, 0, 0)) range = 100 camera = Camera.getCameras()[0] camera.setCastsPerTick(400) camera.setResolution(90, 50) camera.setFov(120, 90) camera.setRange(range) camera.setMode('ALL') camera.capture() print('capturing image') while camera.isCapturing() II.interrupt() end print('drawing image') (width, height) = camera.getResolution() print(width, height) for y = 1, y <= height, y += 1 for x = 1, x <= width, x += 1 entry = camera.getData(x, y) if entry[2] == 'harvestable' screen.fillRect(x, y, 1, 1, entry[3]) elseif entry[0] v = 1.0 - entry[1] / range screen.fillRect(x, y, 1, 1, (v, v, v)) else screen.fillRect(x, y, 1, 1, (0, 0, 0)) end end end
6 Comments
Kototop_CMB 13 Jan, 2022 @ 12:10pm 
i just want see picture from camera on display, preferably small display if this real, 2x3 blocks or anything like it
wingcomstriker405  [author] 13 Jan, 2022 @ 8:41am 
Well a blueprint will probably not help you that much because the important thing is the code
Kototop_CMB 13 Jan, 2022 @ 8:17am 
make example blueprint pls
MYST geek 9 Nov, 2021 @ 5:49pm 
make ex. blueprint please
wingcomstriker405  [author] 12 Oct, 2021 @ 7:06am 
you use it together with the programmable processor mod. ill add a simple example to the description :)
Kototop_CMB 12 Oct, 2021 @ 4:43am 
how use it?