<?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 Bhuvana Chandra P on Medium]]></title>
        <description><![CDATA[Stories by Bhuvana Chandra P on Medium]]></description>
        <link>https://medium.com/@bhuvanachandraprabhu?source=rss-d56eb517125f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IosydXZINrNFwYYh.jpg</url>
            <title>Stories by Bhuvana Chandra P on Medium</title>
            <link>https://medium.com/@bhuvanachandraprabhu?source=rss-d56eb517125f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:20:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhuvanachandraprabhu/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[Introduction to digital art with p5.js]]></title>
            <link>https://medium.com/spidernitt/introduction-to-digital-art-with-p5-js-d8ba63080b77?source=rss-d56eb517125f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8ba63080b77</guid>
            <category><![CDATA[spiders]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[p5js]]></category>
            <dc:creator><![CDATA[Bhuvana Chandra P]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 12:32:15 GMT</pubDate>
            <atom:updated>2021-11-03T12:32:15.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ET8p8J7SSb8rrlmY" /><figcaption>Photo by <a href="https://unsplash.com/@fakurian?utm_source=medium&amp;utm_medium=referral">Fakurian Design</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The question is, why to choose p5.js instead of <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">HTML5 Canvas</a>, which comes inbuilt in javascript. The answer is pretty simple p5.js is more convenient to use and easy to learn also internally uses HTML5 Canvas.</p><p><strong>Come on, let us get started with p5.js!</strong></p><p>p5js.org provides us with an <a href="https://editor.p5js.org/">editor</a>, or we can use the text editor of our choice. I will use my favourite text editor VS code (I hope yours too), which has an extension called <a href="https://marketplace.visualstudio.com/items?itemName=samplavigne.p5-vscode">p5.vscode</a> that makes our job easier.</p><figure><img alt="p5js.vscode extension" src="https://cdn-images-1.medium.com/max/602/1*nZhXH2t3tBIkRLbuVGXiDQ.png" /><figcaption>p5.vscode extension</figcaption></figure><p>After installing the extension, head over to the command palette<br>and type “Create p5.js Project”, which creates a project with all<br>required files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/157/1*KrwTp9cAd9Z2tyu8k2V5XQ.png" /><figcaption>Files created by p5js.vscode</figcaption></figure><p>Now we can head over to the <em>sketch.js</em> file, where you can find two functions named <em>setup()</em> and <em>draw()</em>. Every drawing created with p5.js must contain these two functions.</p><p><em>setup()</em> function runs first and only once, followed by the <em>draw()</em> function, which runs continuously. To view the output on a web page, we need either of these functions to be present.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0edb380d96c58bc0e32fa0735e779ba1/href">https://medium.com/media/0edb380d96c58bc0e32fa0735e779ba1/href</a></iframe><p>Let us start by drawing a simple line by modifying the <em>sketch.js</em> file. First, we will create a canvas using<em> createCanvas(width, height)</em>, which takes width and height as parameters and creates a canvas of the given size.</p><p>If <em>createCanvas()</em> is not used, the window will be given a default size of 100x100 pixels. Next, we shall use <em>line(x₁, y₁, x₂, y₂)</em> to draw the line, which takes up four parameters: the starting <em>(x₁, y₁)</em> coordinates, and the ending <em>(x₂, y₂)</em> coordinates. We shall also add a background to distinguish the canvas from the web page. Open the file <em>index.html</em> in the browser to view the output, or you can also use the <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">live server</a> extension in VS Code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82f3a7aa3deac7b732e9093b1a00b7ee/href">https://medium.com/media/82f3a7aa3deac7b732e9093b1a00b7ee/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*GzKpf43519c2kI6ekB3wWg.png" /><figcaption>The output of the above code</figcaption></figure><p>Now let us move on and create more complex stuff.</p><h3>Creating a smiley face</h3><h4><strong>Face</strong></h4><p>The first step is to create a canvas of the required size. Then we will create a function <em>smiley()</em>, which will draw the smiley face. Next, we will draw a circle using an <a href="https://p5js.org/reference/#/p5/ellipse"><em>ellipse(x, y, width, height)</em></a>. The <a href="https://p5js.org/reference/#/p5/stroke"><em>stoke()</em></a> function gives black color for the outline, and <a href="https://p5js.org/reference/#/p5/fill"><em>fill(255,255,0)</em></a> gives yellow color for the entire circle. The parameters inside the fill represent the RGB color code of yellow.</p><h4><strong>Smile</strong></h4><p>Smile is created with an arc function <a href="https://p5js.org/reference/#/p5/arc"><em>arc(x, y, width, height, start, stop)</em></a>.</p><h4><strong>Eyes</strong></h4><p>To position the eyes, we create a variable called offset. We also use the <em>fill()</em> function to color them. Similar to the face, eyes are also drawn using <em>ellipse()</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08ed590b11db25e5ffe02150c5848908/href">https://medium.com/media/08ed590b11db25e5ffe02150c5848908/href</a></iframe><figure><img alt="Smiley" src="https://cdn-images-1.medium.com/max/437/1*6P_QezflQCbvywxHSHGcZQ.png" /><figcaption>Smiley (Output of the above code)</figcaption></figure><p>Let us delve deeper into p5.js.</p><h3><strong>Maurer Rose</strong></h3><p><a href="https://en.wikipedia.org/wiki/Maurer_rose">Maurer Rose</a> consists of some lines connecting some points on a <a href="https://en.wikipedia.org/wiki/Rose_curve">rose curve</a>. Thinking about what is a rose curve?</p><p>The Rose curve<strong> </strong>is a <a href="https://mathworld.wolfram.com/Sinusoid.html">sinusoid</a> specified by either the <em>cosine</em> or <em>sine</em> functions with no <a href="https://en.wikipedia.org/wiki/Phase_%28waves%29">phase angle</a> plotted in <a href="https://en.wikipedia.org/wiki/Polar_coordinates">polar coordinates</a>. Is it still confusing? Look at the pictures below to get an excellent grasp of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*G9LuMNPjBwAICpLfYixKRA.png" /><figcaption>Rose curves. Source wikipedia.org</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEmGei0JG77ScEhsrpzZhA.png" /><figcaption>Maurer rose. Source wikipedia.org</figcaption></figure><p>The mathematical definition is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfbzaJijhexUv1TXbfhJdw.png" /><figcaption>Source wikipedia.org</figcaption></figure><p>Let us now look at the required functions before starting,</p><ul><li><em>translate(x,y)</em> is used to position the objects in the canvas. Specifies an amount to displace objects within the display window. The x parameter specifies horizontal translation, and the y parameter specifies vertical translation.</li><li><em>vertex(x,y)</em> represents the coordinates of the points in the canvas.</li><li><em>beginShape()</em> starts drawing the given <em>vertex()</em> points below it.</li><li><em>endShape()</em> stops drawing.</li><li><em>strokeWeight(n)</em> adjusts the thickness of the lines drawn.</li><li><em>angleMode(degrees)</em> makes the program accept angles in <em>degrees</em> instead of radians which is the default.</li></ul><p>Let us get into the coding part now,<br>We first initialize the variables <em>n</em> and <em>d</em>, where <em>n</em> represents the number of petals and <em>d</em> is the degrees angle. The <em>setup() </em>function works as usual. The <em>draw() </em>function starts drawing, and the background color is set to black. The <em>translate(width/2,height/2)</em> function position the object at the center.<br>Now here comes the <em>beginShape()</em> which starts drawing.<br>As per definition , we run a loop 361 times which draws the required points, <em>angle k = i*d (where i is the loop counter which starts at 0 and goes up to 361.) radius r = sin(n*k)</em><br>We convert r and k to the <a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system">cartesian coordinate system</a> to use the <em>vertex()</em> function. The first <em>for-loop</em> draws the rose curve, and the next <em>for-loop </em>draws the Maurer rose curve.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09e6f2c06e2dfdbe5f7cf5149d19d007/href">https://medium.com/media/09e6f2c06e2dfdbe5f7cf5149d19d007/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Vb_82QBOOJCRd6pfLJf1A.jpeg" /><figcaption>some of the outputs</figcaption></figure><h3><strong>3D objects</strong></h3><p>p5.js uses <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API">WebGL</a> to render 3d objects. It has a set of inbuilt shapes and also allows us to draw our own too.</p><h4>Some of the common shapes are:</h4><ul><li><a href="https://p5js.org/reference/#/p5/box"><em>box()</em></a></li><li><a href="https://p5js.org/reference/#/p5/sphere"><em>sphere()</em></a></li><li><a href="https://p5js.org/reference/#/p5/cylinder"><em>cylinder()</em></a></li><li><a href="https://p5js.org/reference/#/p5/plane"><em>plane()</em></a></li><li><a href="https://p5js.org/reference/#/p5/cone"><em>cone()</em></a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddf5ee2bb113097fbc674589a576a945/href">https://medium.com/media/ddf5ee2bb113097fbc674589a576a945/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2AUsyIcL5ANmhFCR8H2Zg.png" /><figcaption>The output of the above code</figcaption></figure><h3><strong>Conclusion</strong></h3><p>p5.js is mainly used for creating generative art and animations. We have just covered the basics of p5.js in this article, and it has a lot more. Generally, there are two kinds of libraries in p5.js. Core libraries (<a href="https://p5js.org/reference/#/libraries/p5.sound">p5.sound</a>, <a href="https://github.com/processing/p5.accessibility">p5.accessibility</a>) are part of the p5.js distribution, while contributed libraries are developed, owned, and maintained by members of the p5.js community. p5.js welcomes libraries contributed by others!</p><p>Happy Coding!</p><h3><strong><em>References</em></strong></h3><ul><li>p5.js —<a href="https://p5js.org/"> home</a>, <a href="https://p5js.org/reference/">reference</a>, <a href="https://github.com/processing/p5.js">GitHub</a></li><li>youtube — <a href="https://www.youtube.com/playlist?list=PLglp04UYZK_PrN6xWo_nJ-8kzyXDyFUwi">p5.js Tutorials by Daniel Shiffman/Coding Rainbow</a></li></ul><p><em>This article is published as a part of ‘</em><strong><em>JavaScripted’</em></strong><em> under </em><a href="https://medium.com/spidernitt"><em>Spider Research and Development Club, NIT Trichy</em></a><em> on a Web Wednesday!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8ba63080b77" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spidernitt/introduction-to-digital-art-with-p5-js-d8ba63080b77">Introduction to digital art with p5.js</a> was originally published in <a href="https://medium.com/spidernitt">Spider R&amp;D</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>