<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by William Ngan on Medium]]></title>
        <description><![CDATA[Stories by William Ngan on Medium]]></description>
        <link>https://medium.com/@williamngan?source=rss-17e72dbca315------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I4JJGSK6qwQTetQYUaO4kg.png</url>
            <title>Stories by William Ngan on Medium</title>
            <link>https://medium.com/@williamngan?source=rss-17e72dbca315------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:28:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@williamngan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Taking a line for a walk]]></title>
            <link>https://medium.com/@williamngan/taking-a-line-for-a-walk-6fd947acb227?source=rss-17e72dbca315------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fd947acb227</guid>
            <category><![CDATA[generative]]></category>
            <category><![CDATA[drawing]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[William Ngan]]></dc:creator>
            <pubDate>Fri, 15 Apr 2016 11:35:50 GMT</pubDate>
            <atom:updated>2016-04-15T11:35:50.891Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2pfeKTZhctxrFqfohDxwg.png" /></figure><p>David Hockney is one of my favorite artists. Two years ago, I went to see his exhibition at DeYoung Museum. I love his colossal canvases, delicate drawings, and inventive montages. But I felt very disappointed when I saw his iPad and iPhone drawings.</p><p>In his Woldgate charcoal drawings, for example, I see a countryside that is brimming with light and textures, with such intense vitality that one can almost feel the weather and touch the trees. In contrast, the Yosemite iPad drawings appear like unfinished sketches. Pixelated lines waver and fluster, as if they cannot keep up with movements of the hand. Monotonous digital brushes fill the sky with smog and litter the land with rubber bands. Alas!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1m4-tYwibszqSMUGJKHogQ.jpeg" /><figcaption>Details of Hockney’s drawings. Left: Woldgate, 26 May 2013, Charcoal on Paper. Right: View From Terrace II, Watercolor on paper, 2003.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ARK_EbVBfIABTOqA0FsX3w.jpeg" /><figcaption>Details of Hockney’s iPad drawings. The Yosemite Suite, 2010.</figcaption></figure><p>It leads me to wonder: When a line is drawn on iPad, whose line is it?</p><p>The man-in-the-middle between Hockney and his iPad drawings is the creator of that drawing app. Thus creative expressions can be expansive or limited based on the app, and the app creator’s invisible hand guides the artist’s hand whenever he or she draws a line.</p><p>Many iPad drawing apps offer a similar conservative approach to drawing, in which they try to emulate traditional media as closely as possible, and in doing so, it re-iterates the old ideas instead of inventing new ones, and misses the true opportunities offered by a new medium. If Magritte now paints a pipe on iPad, perhaps he would call it <em>The Treachery of Pixels </em>instead.</p><p>So how should we draw in this paper-less age? I cannot see a future with pseudo-watercolor on retina-paper-thing. I want to imagine a future where artists would create their own lines before they draw them.</p><p>When I was an art student, one conceptual technique I learned was to study a master’s drawing, trace out the lines with a finger, and imagine what it’s like to draw those lines: Matisse’s elegance, Klimt’s flourish, Kollwitz’s rigor. This lesson taught me to appreciate the emotive aspect of a line, and even more importantly, that drawing is an active experience.</p><p>This idea of an active experience, of an active line, of Paul Klee taking a line for a walk, becomes the basis of a code experiment.</p><p>I want to interpret the ideas of drawing with code. I go back and forth between old ideas of drawing and new prospects of code, knowing that the new isn’t always better than the old, but that by studying the tensions between them we may find new modes of expressions.</p><p>I started with some naive questions: Can I trace out a master’s drawing not with finger but with code? In what ways can we express a point’s movements and its path? Is it possible to take a concept of drawing a line, and translate it into a function? And can these concepts be put together to form an alternative approach to digital drawing?</p><p>The result is a series of code sketches about a single line, whose form corresponds to a simple <em>function( points, parameters ). </em>Nothing too fancy, just simple code to try out simple ideas.</p><p>For example, here are some sketches are inspired by basic drawing techniques: using straight line segments to construct a form ( <a href="https://github.com/williamngan/line/blob/master/src/js/lines/LineForm.js#L161"><em>growLine(…)</em></a> ), restating instead of erasing ( <a href="https://github.com/williamngan/line/blob/master/src/js/lines/LineForm.js#L252"><em>restatedLine(…)</em></a> ), and hatching to create tones and textures ( <a href="https://github.com/williamngan/line/blob/master/src/js/lines/LineForm.js#L278"><em>hatchingLine(…)</em></a> ). All these sketches are created using <a href="http://williamngan.github.io/pt">Pt library</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*YuiXtyFZsj8uU5Iy3DZDWQ.gif" /><figcaption>drawing multiple lines to restate a contour</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*4MRULWQaoplcmPuy30mziA.gif" /><figcaption>A curve approximated by straight lines</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*bZnPI0W-SyzmN95k4VTrdg.gif" /><figcaption>A thick line composed by hatching</figcaption></figure><p>Here are some sketches examine the idea of a brushstroke. Using a combination of parameters (velocity, noise, opacity, oscillation, and so on) to craft a line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*oSvewKRlOBo5LL1uETnIGw.gif" /><figcaption>Each cross segment represents the distance travelled by a point at each time step</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*tDY0hPfy65ywBjy2kQjRqg.gif" /><figcaption>A composite line whose variations are produced by a noise function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*KC8OYurd2yyhHU_QVQl8IA.gif" /><figcaption>A line composed of short waving dashes</figcaption></figure><p>And of course there are imaginary lines, lines that are visible to the mind’s eye and then made visible in code. They are the easiest to do and the hardest to do well. Here are a few examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*UW-g41ZpSBOTDgsjphebGw.gif" /><figcaption>An aggressive line with teeth</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*o0ZyrEncbRFzHxmijLAhUA.gif" /><figcaption>A meandering line with shorter lines that flow through it</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*wqyf7YHEvAfha7PKqT15GQ.gif" /><figcaption>“…a shining web, a floating ribbon of cloth, a dragon of air…” inspired by a Yeats’ poem</figcaption></figure><p>And if these movements of an active line are recorded and put onto a single image, what kinds of drawing would it be? I made a <a href="http://williamngan.github.io/line/app.html">quick web app</a> to test it out. Here are some of my doodles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eyTBkBPxct0RegYwUIJcoA.png" /><figcaption>Doodle 1 — Muscat grapes?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nva1TIxOAHikfwwapD7pug.png" /><figcaption>Doodle 2 — Mark Zuckerberg??</figcaption></figure><p>As a critic of my own works, I think these code sketches are somewhat interesting but fall short in many ways. It is a simple approach to create unusual brushstrokes, but it is still a bit conservative, it doesn’t take the original idea of an active line far enough. In particular, I feel akin to cheating from time to time when making “generative art”, in which complexity is free but simplicity is elusive. Because loops and recursions are easy, I am always tempted to go with dazzling dramatic things. But if one looks at all sorts of generative art, and then glimpse at this simple drawing by Matisse, it’s easy to see what’s missing: A different way of seeing, a different kind of drama.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*vqUjs2TlYeQOUSSxCa642g.jpeg" /></figure><p>Still a long way to go, and many roads not yet taken. Exciting times!</p><p>Take a look at <a href="http://williamngan.github.io/line/">Taking a Line for a Walk</a> here, with interactive demos and source code. Also check out <a href="https://vimeo.com/metaphorical">some old works</a> based on a similar idea.</p><p>And there are many other cool digital drawing projects. Check these out:</p><ul><li><a href="http://prostheticknowledge.tumblr.com/post/20734326468/aaron-the-first-artificial-intelligence-creative">AARON</a> is a classic from 1970s</li><li><a href="http://vellumapp.com/">Vellum</a> and <a href="http://vellum.cc/">other projects</a> by David Lu</li><li><a href="https://www.androidexperiments.com/experiment/ink-space">Inkscape</a> and <a href="http://thesystemis.com/projects/">other projects</a> by Zach Lieberman</li><li><a href="http://sougwen.com/Drawing-Operations-D-O-U-G">Drawing Operations</a> by Sougwen Chung</li><li><a href="http://mrdoob.com/projects/harmony/">Harmony</a> by mrdoob</li><li>And many others!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fd947acb227" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A quick start guide to Pt]]></title>
            <link>https://medium.com/@williamngan/a-quick-start-guide-to-pt-758f2e082da5?source=rss-17e72dbca315------2</link>
            <guid isPermaLink="false">https://medium.com/p/758f2e082da5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[William Ngan]]></dc:creator>
            <pubDate>Wed, 02 Sep 2015 19:14:53 GMT</pubDate>
            <atom:updated>2016-08-24T07:14:10.193Z</atom:updated>
            <content:encoded><![CDATA[<p>This is an introduction to <a href="http://williamngan.github.io/pt/">Pt</a>. Pt is experimental and fun. You can read more about <a href="https://medium.com/@williamngan/93382bf5943e/">the motivations here</a>.</p><p>This guide will talk about the basic concepts of Pt, and I would like it to be understandable to people who are learning to code. Please bear with me if it seems dull at times.</p><p>I’ll just assume you can read basic html and javascript code and nothing else. If you already know javascript well, check out <a href="http://williamngan.github.io/pt/demo/index.html?name=color.LABtoRGB">the demos</a> and <a href="http://williamngan.github.io/pt/docs/">the docs</a>. If you like spoiler, this is <a href="http://williamngan.github.io/pt/docs/start.html">what we’ll be building</a> in this guide.</p><p>Let’s get started then. We’ll first create an html file, which grants us the power to show cats and stuff on the interweb. (If you don’t have a text editor for coding, try the free <a href="https://atom.io/">Atom editor</a> .) Let’s save it as <strong>start.html</strong>. It looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e17cb0086aed640c5b5c57a87cac929d/href">https://medium.com/media/e17cb0086aed640c5b5c57a87cac929d/href</a></iframe><p>Inside <em>`&lt;head&gt;`</em>, we add a title and include the pt javascript library file.<br>And inside <em>`&lt;body&gt;`</em>, we add a 500px by 500px container element,<br>and also include another <em>`&lt;script&gt;` </em>block, into which the most exciting code will go.</p><p>Next, we will jump start our artistic career by drawing a dot.</p><p>Pt is based on the concepts of Point, Form, and Space. For simplicity, let’s imagine <strong>Space </strong>as your canvas, <strong>Form </strong>as your brush, and <strong>Point </strong>as your idea.</p><p>Our most exciting code starts off by creating a space in javascript, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae8586878b06ecbd66e9efba41f8b514/href">https://medium.com/media/ae8586878b06ecbd66e9efba41f8b514/href</a></iframe><p>What this means is that we&#39;ll create a Space using html5 canvas.<br>By default, this will look for an element in your html that has an attribute <strong>id=&quot;pt&quot;</strong>, and add a <em>`&lt;canvas&gt;` </em>element inside it.</p><p>We can customize this by passing parameters into it. Using `<em>setup({…})</em>`, you can optionally specify background color and other things.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1321591f209fc9b1d977d664cd8e7f3/href">https://medium.com/media/d1321591f209fc9b1d977d664cd8e7f3/href</a></iframe><p>The code above will create a canvas with a light grey background, displayed inside a container element whose <strong>id=&quot;pt&quot;</strong>.</p><p>Done! The advanced coder will notice (with furious anger) that we’re missing stuff like the damn semicolon and the annoying <em>var </em>and the sacred <em>namespace</em>. Let’s not worry about being correct for now. Let’s have fun and make a mess!</p><p>Next we’ll make the Form, which is like our brush. The basic Form class that comes with Pt will work with CanvasSpace. We just need to create it like this: `<em>form = new Form(</em><strong><em>space</em></strong><em>)`</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4799db2ee71fafbfa0cfd94c8721dd05/href">https://medium.com/media/4799db2ee71fafbfa0cfd94c8721dd05/href</a></iframe><p>Notice the Form takes a parameter, which is the <em>space </em>we just created. This defines the context and links the form to the space. In plain language, it’s saying we will be using this brush for this canvas.</p><p>You may ask: where is the action? Here is the action:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0139817af2b06ea2c0403d7f3362c1d/href">https://medium.com/media/e0139817af2b06ea2c0403d7f3362c1d/href</a></iframe><p>Let’s take a look at what’s going on.</p><p>First, we create a <strong>dot</strong>, which is a Point at position <strong>250, 250</strong> (x and y coordinates). See, it is a point in space. It is known.</p><p>Secondly, we need someone to pick up our brush and draw our dot. So we create a <strong>bot</strong>, which is a little robot to go into space and draw the dot. The robot has a function called <strong>animate</strong>.</p><p>When we put the robot in space, via `<em>space.add( bot )`</em>, it will execute the <strong>animate </strong>function, and do `<em>form.point( dot )`</em>, which draws the dot as a visible point.</p><p>And there are other convenient drawing functions in Form, such as `<em>form.circle`</em>, `<em>form.triangle`</em>, etc. You can even extend Form to draw all kinds of crazy stuff.</p><p>Lastly, after all these preparations, the space comes alive when we hit `<em>space.play()`</em>.</p><p>One quick note: The bot is an example of an <strong>object </strong>in javascript. Any object that defines an <strong>animate </strong>function can be added to a space using `<em>space.add(…)`.</em></p><p>Let’s take a deep breadth, and behold this minimalistic beauty we’ve created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FsgtdCxvcwAJ2hh7Dlu-Hw.png" /></figure><p>During intermission, think about Point, Form, and Space a bit more. This scary looking diagram here is a recap of what we just discussed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9rV8sV7Y9sXMA_Wt_358Q.png" /></figure><p>You may now get a coffee and come back for more exciting developments.</p><p>Perhaps the dot is not what you imagined it to be. Perhaps, like Kandinsky, you’re thinking about a metaphysical circle in blue color. Let’s revise the code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/149aa1542a9305486cb0f762685c73f9/href">https://medium.com/media/149aa1542a9305486cb0f762685c73f9/href</a></iframe><p>What’s changed? Now the <strong>dot</strong> goes from a Point to a Circle, with its radius to <strong>50</strong>. Inside the bot’s <strong>animate</strong> function, we pick a fill color of blue (#5AF is a <a href="https://en.wikipedia.org/wiki/Web_colors">hexadecimal rgb color</a>) and no stroke color for our brush, and use it to draw a circle. Voila!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Ufi8hcfhK1H5C5oll8lGBA.png" /></figure><p>Notice the parameters `<em>(time, fs, …)</em>` in <strong>animate </strong>function? These help you keep track of the passing of time and doing things with it.</p><p>The first parameter <strong>time </strong>tells you, in milliseconds (1/1000th of a second) the time that has passed.</p><p>The second parameter <strong>fs </strong>indicates the time taken to refresh the drawing. (Think of an animation as a sequence of frames, shown one after another, each is displayed for some milliseconds). If you calculate 1000/fs, then you’ll know the current frame rate, ie, how many frames were shown per second. 60 frames-per-second is great, 30 fps is ok. But when frame-rate is low, side effects may include nausea, headache, and depression.</p><p>Let’s use Time to our advantage, and do something fun with it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/765c824db1246c800b6df6457dcf9776/href">https://medium.com/media/765c824db1246c800b6df6457dcf9776/href</a></iframe><p>The code now looks a bit frightening, but it’s worth it because now our circle is pulsating! Let’s go through it.</p><p>First we set the fill color to a medium grey (<strong>#999</strong>), and use it to draw text at position <em>(20, 20)</em>. We calculate the frame rate as <em>1000/fs</em> and display it as text.</p><p>Then we modify the circle’s radius based on time. What does that crazy formula `<em>Math.abs(500 - time % 1000)/20 + 20</em>` mean?</p><p>If you imagine the time passing in 3 seconds or 3000 milliseconds:</p><pre>0...1...345...<strong>1000</strong>...1231...1983...<strong>2000</strong>...2314...2781...<strong>3000</strong></pre><p>So if we divide by 1000 and take the remainder (`<em>time % 1000`</em>), we’ll get:</p><pre>0...1...345...0......231....983....0......314....781....0</pre><p>Then if we subtract it by 500 and make it an absolute value which is always positive ( <em>Math.abs </em>), we’ll get this:</p><pre>500..499.155..500....269....483....500....186....281...500</pre><p>And we divide it by 20 to scale it down to the size we want:</p><pre>25...25..8....25.....13.....24.....25.....9......14....25</pre><p>So the final radius of the circle is set to be at least 20px, plus the dynamic value from time we just calculated: `<em>Math.abs(…)/20 + 20</em>`. As time passes, the circle will pulsate between radii from 20 to 45.</p><pre>45...45..28...45.....33.....44.....45.....29.....34....45</pre><p>And this is why I feel that code is like clay. With your mind’s eye, you can see it, and when you can see it, you can touch and mold it. It’s exciting. And <a href="https://www.youtube.com/watch?v=THNPmhBl-8I">it’s not brain surgery, is it</a>?</p><p>Let’s mold it a bit more. What if we can make it move? First, we will create another circle, called <strong>another</strong>, obviously. Then we’ll ask the <strong>bot </strong>to draw it like what we did with the <strong>dot</strong>. The only difference is that we’ll draw it with no fill color, but with a 5px orange outline: `<em>stroke(“#fc0”, 5)`.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c7f4f7cd1e52d57965494c901a4320f/href">https://medium.com/media/2c7f4f7cd1e52d57965494c901a4320f/href</a></iframe><p>Our <strong>bot </strong>can observe the “events” happening in space, such as when user clicks or moves the mouse. To set it up, we get all mouse events from space, via a helper function `<em>space.bindMouse()`</em>. Then, in addition to <strong>animate</strong>, we add another callback function in the bot called <strong>onMouseAction</strong>. So it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dbe7623fe8cc4a424e1ba8505b86f68/href">https://medium.com/media/2dbe7623fe8cc4a424e1ba8505b86f68/href</a></iframe><p>The <strong>onMouseAction </strong>function has parameters `<em>(type, x, y, evt)`</em>. The parameter <strong><em>type </em></strong>gives you a “string”, which is a piece text to tell you what the type of action is, such as “move”, “drag”, “drop”, and “down”. The parameters <strong><em>x</em></strong> and <strong><em>y</em></strong> then gives you the current mouse position.</p><p>To move the <strong>another </strong>circle with the mouse, we can add some simple logic into <strong>onMouseAction</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15dcb84e3c57ea58fb84540cb6837135/href">https://medium.com/media/15dcb84e3c57ea58fb84540cb6837135/href</a></iframe><p>If you move your mouse around, you should see the orange circle is following your cursor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*GzX01O4_dgoLznYVTf21tg.png" /></figure><p>With a circle pulsating, and another moving with the mouse, we are now on the verge of a creative breakthough! One thing that <strong>Circle </strong>can do is to check if it intersects with another circle. Let’s try:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6da6bf0415602aa93f5b17e10dcd3d60/href">https://medium.com/media/6da6bf0415602aa93f5b17e10dcd3d60/href</a></iframe><p>We start by checking for intersection using `<em>another.intersectCicle( dot )`</em>. If intersection occurs, this function will give us two intersection points in a list called an <em>array</em>. We store the points array in a variable called <strong>hits</strong>.</p><p>Next we check if hits array has more than 0 items in it, using an<em> `if(…)`</em> statement. In plain language, it says: if (hits array has more than 0 items), then do the things inside the curly braces { … }.</p><p>Here we draw the intersection points as circular points with 5px radius, by calling the convenient function `<em>form.points(hits, 5, true)`</em>. The last parameter value `<em>true` </em>means the point will be circular. If it’s set to `<em>false` </em>or omitted, then the points are rectangular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*RJCYVWn5eAkTA-nEiojrwQ.png" /></figure><p>And why stop here? For example, you can connect the hits points with a line. It’s as simple as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e10244ec159e38796886191426bf2310/href">https://medium.com/media/e10244ec159e38796886191426bf2310/href</a></iframe><p>We create a new <strong>Line </strong>by specifying its two end points as the <strong>hits </strong>points. We use the array index notation ( `<em>something[0]` </em>) to get the point out of the array. Notice that the first item in an array is at position 0. Finally we asks our Form to draw the line: `<em>form.line( … )`.</em></p><p>Whoa, <a href="http://williamngan.github.io/pt/docs/guide/quickstart_demo.html">take a look at what we have achieved</a> with less than 40 lines of javascript code in a basic html file. Congratulations! Now it’s your turn to put your imaginative forces to work. Take a look at the demos, and the docs, and if you haven’t, learn to code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*byAFQcyFi6q54H3Xyz-TwA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e1797eaac04283a8823faffd5f130e0/href">https://medium.com/media/3e1797eaac04283a8823faffd5f130e0/href</a></iframe><p>And this is how this guide will end, not with a bang, but with some technical notes:</p><ul><li>You can see <a href="https://github.com/williamngan/pt/blob/master/docs/guide/quickstart_demo.html">the actual source code here</a>, along with semicolons and vars and stuff.</li><li>Pt’s full source code is at <a href="http://github.com/williamngan/pt">http://github.com/williamngan/pt</a></li><li>Also check out Pt’s <a href="http://williamngan.github.io/pt/demo/?name=color.LABtoRGB">demos</a>, <a href="http://williamngan.github.io/pt/docs/guide/quickstart.html">guides</a>, and <a href="http://williamngan.github.io/pt/docs/">documentation</a>.</li><li>There are many free resources online for learning to code. For javascript, there are <a href="https://www.codecademy.com/en/tracks/javascript">Codecademy </a>and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">Mozilla</a> and many others. A good javascript book that’s free to read online is <a href="http://eloquentjavascript.net/">Eloquent Javascript</a>.</li><li>If you like graphics and making things move, there are many excellent javascript libraries such as <a href="http://d3js.org/">d3.js</a>, <a href="http://paperjs.org/">paper.js</a>, and <a href="http://threejs.org/">three.js</a>. There is also the awesome <a href="http://processing.org/">Processing project</a>, which is based on Java and has a javascript version <a href="https://p5js.org/">p5.js</a> as well.</li></ul><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=758f2e082da5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pt]]></title>
            <link>https://medium.com/@williamngan/pt-93382bf5943e?source=rss-17e72dbca315------2</link>
            <guid isPermaLink="false">https://medium.com/p/93382bf5943e</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[experimental]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[William Ngan]]></dc:creator>
            <pubDate>Wed, 02 Sep 2015 19:13:25 GMT</pubDate>
            <atom:updated>2017-09-09T07:19:22.750Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9b-qLNnOvt4_C5bKE-bOhg.png" /></figure><p><strong>Point, Form, and Space — an experiment</strong></p><p><em>By a like law we see how earth is pied<br>With shells and conchs, where, with soft waves, the sea<br>Beats on the thirsty sands of curving shores.<br>Wherefore again, again, since seeds of things<br>Exist by nature, nor were wrought with hands<br>After a fixed pattern of one other,<br>They needs must flitter to and fro with shapes<br>In types dissimilar to one another.</em></p><p>— Lucretius, <em>On the Nature of Things</em></p><p>Two thousand years ago, Lucretius described a universe of atoms, by invoking Venus and composing in heroic hexameters. Words are indeed codes, transforming ideas into syntax trees and then back into ideas in a reader’s mind. Even though empires rose and fell, and cats appeared on the web, millennia later I can still read Lucretius on a kindle.</p><p>But what if the internet was invented in ancient Rome, and Lucretius could code in javascript: How would he then trace the ray of sunlight that illuminates dancing specks of dust, or generate those soft waves that fashion sands into shapes? And two thousand years later, in what forms would I read or experience his narrative of an atomic universe?</p><p>Perhaps, by imagining the old poet writing javascript, we may set our mind free for a moment, and so to unchain code from the shackles of business logic or app stores, and to consider this medium in its pure form: a form even lighter and more expansive than words, and a form full of potentials for poetry and abstraction.</p><p>If combinations of words bring forth poetry, and fire turns clay into pottery, then can code, through its variables and functions and classes, produce a new form of humanistic expression? Does form follow <em>function()</em>?</p><p>It is not easy to answer these questions, because code pushes us to ponder the multiplicity of forms as variations of a single concept in different contexts and states. It enables interactions, recursions, and transpositions. Indeed, to tell <em>One Thousand and One Nights</em> in javascript, Scheherazade could encounter a stack overflow error if she pushed it too far (or did she do it deliberately so dawn will never come?) Thus code challenges us to seek and sort relationships, to analyze and to imagine at the same time.</p><p>These questions and considerations motivate me to speculate and experiment into the night. I thought of unity in variety, of complexity from simple rules, of growth of cells and forces of atoms, but for a long time I couldn’t organize these thoughts into something more than a random collection. Where should I begin?</p><p>It was Paul Klee who inspired me with a deceptively simple idea:</p><blockquote>A line is a dot that went for a walk.<br>Drawing is taking a line for a walk.</blockquote><p>So I decided to start with a simple dot. The dot is so small. I had to squint my eyes for years. I had dropped this project, only to pick it up again, and again, never quite sure what it was and where it would lead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGWORYt_bEb9HyvxsYmK6g.jpeg" /><figcaption>Mosumi, a project I created in 2010 for Code:Craft exhibition in Museum Sheffield, was a first-take on this idea. (<a href="https://vimeo.com/9151250">Video</a>) Then I wasted a couple years playing video games.</figcaption></figure><p>What is a simple concept that can be modeled, extended, and visualized in code?<br><strong>A point.</strong></p><p>What is a point?<br><strong>A position in a space.</strong></p><p>What is this space?<br><strong>A compartment of an outer space that extends infinitely. </strong>A room. A cave. A pair of brackets.</p><p>What are these rooms or caves or brackets?<br><strong>A context. </strong>( . ) { . } | . | [ . ]</p><p>What is a context?<br><strong>A limited set of possibilities</strong>, comprehensible to a human mind.</p><p>So if a space and its walls define a set of possible ideas, then a point specifies a unique idea. Its meanings are always contextual to its space. Each form is an interpretation of a point in a particular context.</p><p>Space gives meaning to a point, and Form makes a point visible.</p><p>Through code, we can move points, switch spaces, and change forms, and thus access and express a multiplicity of ideas. To me, this provides a minimalistic union of code and art: as a point made visible in a space.</p><p>This is the model at its simplest:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9rV8sV7Y9sXMA_Wt_358Q.png" /></figure><p>It is easy to see how <strong>Point</strong>, <strong>Space</strong>, and <strong>Form </strong>can extend. For instance, you may specify a new form of a point, perhaps as a tiny ink blot, perhaps as a histrionic gesture of pointing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pg8Uhx6HStEm-RXdwnJmYg.png" /></figure><p>Or you may envision a three-dimensional color space, where a point defines hue, saturation, and lightness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kaIQkGzEXjcDgljLBi1DvA.png" /></figure><p>Or you may brood upon the concept of a pair of points and discern, with your mind’s eyes, the various interpretations of a single idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_YPtkfolCB23TfOzx5A6g.png" /></figure><p>Better yet, you may explore the variations of these 3 ideas put together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZmQuL3nZbwKjBBpgq_aXw.png" /></figure><p>These are the motivations and ideas behind <a href="http://williamngan.github.io/pt/"><em>Pt</em></a>, an experiment on point, space, and form. It is an attempt to reduce an idea into its very essence, and extrapolating from its initial conditions, to investigate its possibilities and its limits.</p><p>In particular, I would like to seek a model of coding in which the mind does not fixate on code initially, nor does it exhaust itself by studying algorithms or drawing diagrams like a visual-programming tool. Instead, the mind should focus on bringing forth imagery and abstraction, like Appollonius slicing a cone to look for an ellipse, like Michelangelo setting free the prisoners from marbles. Code is a medium, and while the medium may be the message, it needs not be the motive or the source of vision.</p><p>What code offers us is the potentials of a new medium: it can automate processes, model abstractions, and design interactions. And I would say its defining characteristic is the immediacy, which lets us quickly iterate variations of a single concept and evaluate them in visible ways. This cannot be achieved with pencil or stone or word or Photoshop. Code is a luxury that artists didn’t have throughout history.</p><p>But one drawback of this immediacy (or what’s called a <em>generative </em>method<em>) </em>is a potential confusion of cause and effect: that by tweaking some parameters of a function, one can generate a whole new set of dazzling effects, and in 15 minutes so much were created and lost, including the original thought. Some would argue this is a feature, not a bug. I would beg to differ.</p><p>In a sense, it is a bug in the mind. Like language, code channels our thoughts as well as conditions our thinking. Weak thoughts get carried away by stronger currents, but stronger ideas yet persist and are perfected through iterations. We may discover these stronger ideas not by playing with parameters, but by looking outside code, into poetry, philosophy, biology and other fields. Or think of Mona Lisa as we code, which Walter Pater describes as “a beauty wrought out from within upon the flesh, the deposit, little cell by cell, of strange thoughts and fantastic reveries and exquisite passions.” Strange thoughts are what we need!</p><p>Within these endless possibilities of forms generated by code, our task is to find in them a vision of beauty, or a layer of meaning, or a combinatorics of logical abstractions and humanistic values, that is both personal and shared.</p><p>Allow me to conclude with this paragraph, which I love, that marks the end of Italo Calvino’s Six Memos for the Next Millennium:</p><blockquote>But perhaps the answer that stands closest to my heart is something else: Think what it would be to have a work conceived from outside the self, a work that would let us escape the limited perspective of the individual ego, not only to enter into selves like our own but to give speech to that which has no language, to the bird perching on the edge of the gutter, to the tree in spring and the tree in fall, to stone, to cement, to plastic…</blockquote><p>I hope you will <a href="http://williamngan.github.io/pt/">give Pt a try</a>, and let me know what you think.</p><p><strong>Edit on Sep 2017: Yay! An improved version of Pt has been launched as a new library: Pts.js. </strong><a href="https://ptsjs.org/"><strong>https://ptsjs.org</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93382bf5943e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubist]]></title>
            <link>https://medium.com/@williamngan/kubist-6ed1d8025806?source=rss-17e72dbca315------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ed1d8025806</guid>
            <category><![CDATA[design-process]]></category>
            <category><![CDATA[web-apps]]></category>
            <category><![CDATA[computational-aesthetics]]></category>
            <dc:creator><![CDATA[William Ngan]]></dc:creator>
            <pubDate>Mon, 20 Apr 2015 10:06:20 GMT</pubDate>
            <atom:updated>2015-04-20T10:22:38.881Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubist transforms an ordinary image into cubism-like composition. You can play with the <a href="http://williamngan.github.io/kubist/"><strong>web app</strong></a> and get the <a href="https://github.com/williamngan/kubist"><strong>source code</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sF_HCtsF7GeLQt7sYhcyQA.png" /></figure><p>A few years ago, I came across a curious image made of colorful triangular tiles. The triangles seemed to be placed randomly, and somehow they looked rhythmic and unified. How does that work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*QV9TX-Z0UgmlJz-_cqdJGA.gif" /><figcaption>Delaunay triangulation maximizes the inner angles of a triangle. This is an animated image from <a href="http://en.wikipedia.org/wiki/Delaunay_triangulation">Wikipedia’s article</a>.</figcaption></figure><p>Then I learned about Delaunay triangulation. Fascinated by the algorithm and its aesthetic quality, I quickly experimented with it in Processing. The resulting tessellations reminded me of <a href="http://en.wikipedia.org/wiki/Orphism_%28art%29">Orphic Cubism</a> paintings , with sharp colors and rhythmic mosaic, though perhaps a bit more mechanical. I called it Kubist (<a href="http://www.metaphorical.net/note/on/kubist">old sketch</a>).</p><p>Now tessellation style has become popular again, and with d3.js, making Delaunay triangles is as simple as a function call. So here I updated Kubist into <a href="http://williamngan.github.io/kubist/">a little web app</a>, along with some thoughts:</p><h4>Composition</h4><p>Delaunay tessellation is based on a set of points. As the points’ positions change, the resulting image will also change. How do we place these points?Here are 4 studies of Chairman Mao, the destroyer of all the good things in China. From left to right:</p><ol><li>Points that are randomly placed</li><li>Points sampled using <a href="http://bl.ocks.org/mbostock/d7bf3bd67d00ed79695b">best candidate algorithm</a></li><li><a href="http://en.wikipedia.org/wiki/Interest_point_detection">Feature points detection</a> on the original image using JSFeat library</li><li>Manually moving the points.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i4ovkqNa6oSTFoyV_j2rFw.png" /></figure><h4>Colors</h4><p>By mapping the points’ positions to original image’s pixels, we can extract the colors and apply them to paint our triangles. For example, you can take the color from a triangle’s <em>incenter</em>, or an average color from the 3 points of a triangle, or a gradient with multiple stops based on the interpolated points of a bisector line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qI-3BBEeNwGLn9rBuDPHPA.png" /></figure><h4>Abstraction</h4><p>More triangles furnish an image with extra details, though make it more apathetic also. Gradients add ornaments and softness to the image, while solid colors feel more direct and confident. Adding auxiliary graphic elements, such as circles and borders, flattens the image and renders it graphical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3q6vrM62QnANbYFQ5wzuXQ.jpeg" /></figure><p>One of the most fascinating aspects in digital arts is the interplay between imaginations and algorithms, the unending surprises derived from tweaking your ideas and tweaking your code, back and forth. I encourage you to try out <a href="http://williamngan.github.io/kubist/">Kubist</a>, as well as getting the <a href="https://github.com/williamngan/kubist">source code</a> and putting your imaginative forces to work!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ed1d8025806" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pasta as a medium]]></title>
            <link>https://medium.com/@williamngan/pasta-as-a-medium-219c8ff76059?source=rss-17e72dbca315------2</link>
            <guid isPermaLink="false">https://medium.com/p/219c8ff76059</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[food]]></category>
            <dc:creator><![CDATA[William Ngan]]></dc:creator>
            <pubDate>Mon, 20 Apr 2015 08:58:17 GMT</pubDate>
            <atom:updated>2015-04-20T08:58:17.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yznWXrfbVl7PbJTeCM0xtw.jpeg" /></figure><p>While well-cooked pasta is good for teeth, well-designed pasta is food for thought. When I was living in a small Italian town, I cooked pasta and contemplated upon their forms in idle evenings.</p><p>What a fantastic medium to capture tomato sauce indeed!</p><p>Spaghetti often isn’t sauce enough, and Rigatoni sometimes has too much. Variations of Fusilli (spiral-shape), Farfalle (butterfly-shaped), and Casarecce (has a nice twist) are lovely, practical, well-engineered solutions.</p><p>But my favourite is Canalini: it is like Linguini but with a “canal” in the middle, into which the perfect amount of sauce flows. It is an intellectual pasta.</p><p>Because of these witty, elegant, and high-carb inventions, life is good.</p><p><em>(Testing medium with a little piece written in 2009)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=219c8ff76059" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>