This is the tutorial of Laser DAC, including API reference and some examples.
Laser DAC is a node package, and use yarn as the package manager. At first, you should make sure that install both of node and yarn correctly in your computer.
It is very easy to get started:
- Clone this repository: Find or create an empty folder and open the terminal run
git clone https://github.com/ofcourseio/laser-dac-tutorials.git
. Change directorycd laser-dac-tutorials
- Install dependcies: Run
yarn install
. - Run demo on a simulator: Run
yarn run dev
, and open your browser withhttp://localhost:8080
. - Run demo on the connected device: Change code as follows, then run
yarn run dev
.
import { DAC } from "@laser-dac/core";
import { EtherDream } from "@laser-dac/ether-dream";
import { Scene, Rect } from "@laser-dac/draw";
(async () => {
const dac = new DAC();
dac.use(new EtherDream());
await dac.start();
const scene = new Scene({
resolution: 500,
});
scene.start(step);
dac.stream(scene);
function step() {
const rect = new Rect({
width: 0.2,
height: 0.2,
x: 0.4,
y: 0.4,
color: [1, 1, 0],
});
scene.add(rect);
}
})();
If everything goes right, it looks like as below:
If your want to build your project, just run yarn run build
. After building, run yarn run start
.
The basic structure of Laser DAC program is separated into three parts:
- Create DAC and connect it to selected device.
- Create a new scence and stream the data it to selected device.
- Update scene.
import { DAC } from "@laser-dac/core";
import { /* Device */ } from "@laser-dac/xxx"
import { Scene } from "@laser-dac/draw";
(async () => {
// Create DAC and connect it to selected device
const dac = new DAC();
dac.use(/* selected device */);
await dac.start();
// Create a new scence and stream it to selected device
const scene = new Scene({
resolution: /* custom resolution which default to 500*/,
});
scene.start(step);
dac.stream(scene);
// Update scene
function step() {
/**
* creative coding area.
* **/
}
})();
Each time your want to add a shape to screen, just create the object and call scene.add(obj)
.
import { Rect } from "@laser-dac/draw";
const rect = new Rect({
width: 0.2,
height: 0.2,
x: 0.4,
y: 0.4,
color: [1, 1, 0],
});
scene.add(rect);
Object DAC()
void use(Device Object)
Promise start()
void stream(Scene Object)
Object EtherDream()
Object Helios()
Object Laserdock()
Object Beyond()
Object Easylase()
Object Simulator()
Object Scene(options)
Object Shape(options)
Object Rect(options)
Object Line(options)
Object Circle(options)
Object Point(options)
Object Path(options)
Object Svg(options)
Object Wait(options)
Object QuadCurve(options)
Object CubicCurve(options)
Object HersheyFont(options)
Object Ilda(options)
Object helpers(options)