You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
974 B

9 years ago
var fs = require('fs')
var path = require('path')
var Canvas = require('..')
9 years ago
var canvas = new Canvas(150, 150)
var ctx = canvas.getContext('2d')
9 years ago
ctx.fillRect(0, 0, 150, 150) // Draw a rectangle with default settings
ctx.save() // Save the default state
9 years ago
ctx.fillStyle = '#09F' // Make changes to the settings
ctx.fillRect(15, 15, 120, 120) // Draw a rectangle with new settings
9 years ago
ctx.save() // Save the current state
ctx.fillStyle = '#FFF' // Make changes to the settings
ctx.globalAlpha = 0.5
ctx.fillRect(30, 30, 90, 90) // Draw a rectangle with new settings
9 years ago
ctx.restore() // Restore previous state
ctx.fillRect(45, 45, 60, 60) // Draw a rectangle with restored settings
9 years ago
ctx.restore() // Restore original state
ctx.fillRect(60, 60, 30, 30) // Draw a rectangle with restored settings
9 years ago
canvas.createPNGStream().pipe(fs.createWriteStream(path.join(__dirname, 'state.png')))