6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

obniz(Node.js)で画面に日本語を表示する

Posted at

IMG_0755.JPG

node-canvasを使って日本語を描画します。
obnizで対応しているのは2系以上の最新バージョンなので、canvas@nextをダウンロードします。

$ npm i canvas@next

canvasは1.6系(2018年9月現在)なので、obnizでは使えません!

const Obniz = require("obniz");
const { createCanvas } = require('canvas');

var obnizeId = "YOUR-OBNIZ-ID";
var obniz = new Obniz(obnizeId);

obniz.onconnect = async function () {
  obniz.display.clear();
  const canvas = createCanvas(128, 64);
  const ctx = canvas.getContext('2d');
  ctx.fillStyle = "white";
  ctx.font = "15px Avenir";
  ctx.fillText('こんにちは', 0, 20);
  obniz.display.draw(ctx);
}

文字を横にスライドさせてみます。

output4.gif

const Obniz = require("obniz");
const { createCanvas } = require('canvas');

var obnizeId = "YOUR-OBNIZ-ID";
var obniz = new Obniz(obnizeId);

obniz.onconnect = async function () {

  const canvas = createCanvas(128, 64);
  const ctx = canvas.getContext('2d');
  ctx.fillStyle = "white";
  ctx.font = "20px Avenir";

  for (var i = 0; i < 130; i++) {
    obniz.display.clear();
    ctx.fillText('こんにちは', i, 30);
    obniz.display.draw(ctx);
    ctx.clearRect(0, 0, 128, 64)
    await obniz.wait(100);
  }
}

参考:https://obniz.io/doc/sdk/doc/display

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?