<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bin </title>
    <description>The latest articles on DEV Community by Bin  (@a26230203).</description>
    <link>https://dev.to/a26230203</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F619645%2F961a9306-1e15-4629-a22c-9b7eca9f845b.png</url>
      <title>DEV Community: Bin </title>
      <link>https://dev.to/a26230203</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/a26230203"/>
    <language>en</language>
    <item>
      <title>Using Canvas in vanilla JavaScript</title>
      <dc:creator>Bin </dc:creator>
      <pubDate>Thu, 24 Jun 2021 16:04:41 +0000</pubDate>
      <link>https://dev.to/a26230203/using-canvas-in-vanilla-javascript-3ncg</link>
      <guid>https://dev.to/a26230203/using-canvas-in-vanilla-javascript-3ncg</guid>
      <description>&lt;h2&gt;
  
  
  What is Canvas?
&lt;/h2&gt;

&lt;p&gt;Canvas is HTML element which you could draw graphic or use it to create some fancy animations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Canvas
&lt;/h2&gt;

&lt;p&gt;In order to setup a canvas in vanilla JavaScript, you need to add &lt;code&gt;canvas&lt;/code&gt; element on HTML file. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3YG4YqvB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g46iok5xr6897y4osh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3YG4YqvB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g46iok5xr6897y4osh5.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
and then using &lt;code&gt;querySelector&lt;/code&gt; to select the element, and setup the size of your canvas and chose the dimensional of context you are going to use, below I using two-dimensional drawing context&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NBdoryPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9odjdqo54365a6mnevmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NBdoryPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9odjdqo54365a6mnevmh.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Shape
&lt;/h2&gt;

&lt;h5&gt;
  
  
  1. Line
&lt;/h5&gt;

&lt;p&gt;We need &lt;code&gt;beginPath()&lt;/code&gt; to set a new path and using &lt;code&gt;MoveTo()&lt;/code&gt; to create a sub-path of beginning of line and &lt;code&gt;LineTo()&lt;/code&gt; to create a sub-path of ending of line. The &lt;code&gt;strokeStyle() &lt;/code&gt; is color of line, the &lt;code&gt;stroke() &lt;/code&gt; to drawing the line &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bDF6d8Kg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5tekxjf41e3om3bgt5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bDF6d8Kg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5tekxjf41e3om3bgt5a.png" alt="image"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FftFUQOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnjkwoerbo3ni9pdt5n0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FftFUQOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnjkwoerbo3ni9pdt5n0.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Circle
&lt;/h5&gt;

&lt;p&gt;Similarly, in order to drawing a circle on Canvas, we need &lt;code&gt;beginPath()&lt;/code&gt; to set a new path, then using the &lt;code&gt;arc()&lt;/code&gt; to create circular arc which require 6 parameters, 1st parameters is x-axis of arc's center, 2nd parameters is y-axis of arc's center, 3rd parameters is radius, 4th parameters is start angle, 5th parameters is end angle (below Math.PI *2 = 360°), the last parameters is determining if drawing the arc counter-clockwise between the start and end angles. The The &lt;code&gt;strokeStyle()&lt;/code&gt; is outline color of circle , the &lt;code&gt;stroke() &lt;/code&gt; to drawing outline of circle&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hx4KRnZy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kabs9jhp0pwhrmnoejec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hx4KRnZy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kabs9jhp0pwhrmnoejec.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vdUUymgH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atc027qqhral8n14d4w5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vdUUymgH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atc027qqhral8n14d4w5.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Rectangle
&lt;/h5&gt;

&lt;p&gt;The &lt;code&gt;fillStyle()&lt;/code&gt; to set to set the color of rectangle and The &lt;code&gt;fillRect()&lt;/code&gt; to create a rectangle &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HPEN6dpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/riy84i9pvc7lc2z8szrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HPEN6dpb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/riy84i9pvc7lc2z8szrs.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3MSHOIlo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iq94le3f94w4tvnwz79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3MSHOIlo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iq94le3f94w4tvnwz79.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Reference:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineTo"&gt;Line&lt;/a&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/arc"&gt;Circle&lt;/a&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/arc"&gt;Rectangle&lt;/a&gt; &lt;a href="https://www.w3schools.com/html/html5_canvas.asp"&gt;More&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Ruby Instance Methods</title>
      <dc:creator>Bin </dc:creator>
      <pubDate>Wed, 02 Jun 2021 16:38:42 +0000</pubDate>
      <link>https://dev.to/a26230203/ruby-instance-methods-8dk</link>
      <guid>https://dev.to/a26230203/ruby-instance-methods-8dk</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Below is some instances method in Ruby might help you easily solving the issue. &lt;/p&gt;

&lt;h2&gt;
  
  
  .flatten()
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.flatten()&lt;/code&gt; is method will return a new array that flattening of itself and it also taking argument to determine the level of recursion to flatten.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F964hrh02c7dveo1344hu.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F964hrh02c7dveo1344hu.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  .reverse()
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.reverse()&lt;/code&gt; method will return a new array containing self's elements in reverse order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0gow25cvaee40llrnv5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0gow25cvaee40llrnv5.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  .rotate()
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.rotate()&lt;/code&gt; method will rotate first element of self and return by new array and it also taking argument to determine how many element need to rotate, if passing negative argument like (-1) then it will rotate in opposite direction&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthj9g2akuq8zqrugykf9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthj9g2akuq8zqrugykf9.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  .insert()
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.insert()&lt;/code&gt; method is taking at least two argument, first argument is index of array, and second argument is value that you are going to insert, if using negative index will insert the value at the end of array &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqsq8avnbpv8o1r8o3jy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqsq8avnbpv8o1r8o3jy.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;References:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://apidock.com/" rel="noopener noreferrer"&gt;API DOCK&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
    </item>
    <item>
      <title>Use State in functional component of React                </title>
      <dc:creator>Bin </dc:creator>
      <pubDate>Thu, 13 May 2021 16:08:45 +0000</pubDate>
      <link>https://dev.to/a26230203/use-state-in-functional-component-of-react-5c0m</link>
      <guid>https://dev.to/a26230203/use-state-in-functional-component-of-react-5c0m</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nwH_yUQM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uf90qv0dwtvwtvvydy1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nwH_yUQM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uf90qv0dwtvwtvvydy1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This post to understand how to use state in functional component of React. As we know React has functional and class components and we usually using the &lt;strong&gt;Class Components&lt;/strong&gt; whenever we require to use state of components: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--45WbXYt_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ypcwlcxzjpeirlokojl.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--45WbXYt_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ypcwlcxzjpeirlokojl.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
But we also able to use &lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;React Hooks&lt;/a&gt; to add state into &lt;strong&gt;Functional components&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React.useState Hook
&lt;/h2&gt;

&lt;p&gt;The function of &lt;code&gt;useState&lt;/code&gt; is hook that allow you add and maintain state within the &lt;strong&gt;Functional components&lt;/strong&gt;. First of all, you need to import &lt;code&gt;useState&lt;/code&gt; from React &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wUrFLps2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tze6r3z93h8m0ibme0hl.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wUrFLps2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tze6r3z93h8m0ibme0hl.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then here we have &lt;code&gt;dog&lt;/code&gt; as state variable and &lt;code&gt;setDog&lt;/code&gt; as the function to update the &lt;code&gt;dog&lt;/code&gt;. The &lt;code&gt;useState&lt;/code&gt; Hook only allow one state variable being declare at once, in other words if you have multiple state, you should create multiple variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fssrIcQc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9y8sxyzneuwo8he0v9iq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fssrIcQc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9y8sxyzneuwo8he0v9iq.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Update state
&lt;/h2&gt;

&lt;p&gt;Like we using setState in &lt;strong&gt;Class components&lt;/strong&gt;, we are going to use &lt;code&gt;setDog&lt;/code&gt; in &lt;strong&gt;Functional components&lt;/strong&gt; to updated the value of &lt;code&gt;dog&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5mjOeo1T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1mysy79i3jokw2affrm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5mjOeo1T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1mysy79i3jokw2affrm.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;References&lt;/em&gt;:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;https://reactjs.org/docs/hooks-intro.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
