← BackPlay with node-canvas and build something usefulu11g.com
1/12/2020

Play with node-canvas and build something useful

Canvas is not the problem, it’s math!

For developers the configurability of things is quite natural. And I wanted to leave different configurations open. Not many elements are needed with a Dot Calender: Circles and text. That’s it. So to start, set up a node project and install canvas:

npm install canvas --save

To draw a circle you use arc:

ctx.beginPath(); 
ctx.strokeStyle = this.properties.dots.dotStrikeColor; 
ctx.lineWidth = this.properties.dots.dotLineWidth; 
ctx.fillStyle = this.getFillColor(dotFlag); 
ctx.arc(x, y, radius, 0, Math.PI * 2, true); 
ctx.stroke(); 
ctx.fill(); 
ctx.closePath();

Adding a text is also very easy with fillText().

The art of this lies in mathematics:

  • Number of circles per month
  • Radius of the circles depending on the base area
  • Basically distances (between circles, between texts, …) And there are some more configurations to consider. This is not about higher mathematics either, but the model has to be assembled nevertheless. To determine the x and y coordinates of the circles I used for example the following formula:
const x = startX + (month * textDistance + month * columns * (radius * 2 + distanceBetweenCirclesX) + column * (radius * 2 + distanceBetweenCirclesX)); 
const y = startY + day * (radius * 2 + distanceBetweenCirclesY);

With the help of configuration files most of the parameters I need can be adjusted. I am quite proud of the results :) Here you can find examples with different color schemes and different numbers of columns per month: The whole project can be found here. I still have a few ideas in my head that I would like to implement, but for now it has served its purpose. And I built my first useful project with canvas ;)

Home
Projects
Newsletter
Blog
Me
Philosophy
Gen Art
Work
Setup
CV
Machine
Dynamic Pong: Territory Conquest Meets Classic Physics
Introducing Camunda Directory
Getting Started with AIME Directory Collections in 5 Minutes
How to use a proxy in a nodejs environment
Introducing weeklyfoo
Create your own epaper calendar with Canvas
Codespaces can become a game changer
Cloudflare pages direct upload with stable preview urls
Building your own Twitter Thread Generator
300 APIs integrated in minutes, not days
Be an orchestration hero
Cut a few braids - new NPM package
ETHme - your chic web3 identity
Automatically update data and commit
Aren't the standard actions going too far for you? Write your own one!
Screenshots - a perfect task to automate!
Send messages to Slack from Camunda Cloud
5 Steps how to track your Team's Mood
Automate your manual tasks with Camunda and Trello!
Go beyond the basics
Is there an alternative to spaghetti?
Play with node-canvas and build something useful
How do I implement a command line tool?
Aime Directory
Boring Dev Tools
Camunda Directory
Data Democracy
Dev Pulse
Dynamic Pong
Lifosy
Art u11g
dapphuntr
DiyPunks
flethy
Maker Oracles
SwagTime
EthME
fcheat
Find the next victim
Generative Arts
MakerDAO Delegates
SkunkWorks NFT
Trees of Life NFT
zukuNFT
RestZeebe
Websiteshot
Zeebetron: How to Manage Multiple Zeebe Profiles with Electron
dot calendar
Sharu
Switch Interface (theme)
LINKEDIN
X
GITHUB