How to run in a Node.js environment?

38 views
Skip to first unread message

小七

unread,
Jul 16, 2024, 5:05:15 AM7/16/24
to Paper.js
The generated canvas is empty!!!
code:
const paper = require("paper");
const { createCanvas } = require("canvas");

// Create a canvas and set the size
const canvas = createCanvas(800, 600);
// Set the canvas to be the active layer
paper.setup(canvas);
// Create a circle shape
const circle = new paper.Path.Circle({
    center: [400, 300],
    radius: 50,
    fillColor: "red",
});
// Create a square shape
const square = new paper.Path.Rectangle({
    point: [300, 200],
    size: [100, 100],
    fillColor: "blue",
});
// export img
const fs = require("fs");
const out = fs.createWriteStream(__dirname + "/test.png");
const stream = canvas.createPNGStream();
stream.pipe(out);
out.on("finish", () => console.log("The PNG file was created."));

Reply all
Reply to author
Forward
0 new messages