Introduction
Little bit about me
I'm @kosamari on the internet pretty much everywhere except Myspace.
I write JavaScript everyday at Scripto in NYC
I also co-organize JavaScript meetup called BrooklynJS in NYC.
... and my favorite data type is Array
Array and Me
I like dealing with physical array like knit stitches on needle.
I make small programming language that spits out array to design knitting pattern...
Cat pattern by @hamishmurphy
I like writing JavaScript arrays to visualize my knitting process.
GIF from Tumblr
...and turn those array into 0s and 1s to move knitting machine.
I also made D3 scarf !
Because of this, I got really interested in "print out" digital image as knitted fabric. In order to do this, I needed to learn how digital image is perceived by computers... turns out, it's also array of data.
Doing research was reading about a lot of math, & learning to use tools... I wonder, can I do all of this in a language I'm familiar (JavaSript) and a software I already use everyday (browser)?
The answer is YES, let's look at what we can do
What is Canvas
So, let's start with "what is Canvas?"
According to MDN, Canvas was "Added in HTML5, the HTML <canvas> element can be used to draw graphics via scripting in JavaScript. "
In order to talk to this canvas we created, we need to make something called context.
In other wards. creating canvas is like you are reserving piece of land, but you don't know where this land is located yet.
you can set width and height of the element, but we can't really talk to this canvas in JavaScript yet.
So, let's get coding, you can create canvas element like this, or write in your HTML and reference it
You might want to have this land in the city where there is a lot of skyscrapers and very 3d...
... or you might be putting vegetable garden in your back yard.
Talking to canvas
Now that we have context established, we can talk to canvas like draw shapes and fill with color.
We can even load picture into canvas.
There are all human understandable language to communicate with canvas...