{"id":2006,"date":"2017-07-15T03:29:31","date_gmt":"2017-07-15T03:29:31","guid":{"rendered":"http:\/\/javascript-tutor.net\/?page_id=2006"},"modified":"2018-04-08T08:22:50","modified_gmt":"2018-04-08T08:22:50","slug":"javascript-quadratic","status":"publish","type":"page","link":"https:\/\/javascript-tutor.net\/index.php\/javascript-quadratic\/","title":{"rendered":"Drawing a Quadratic Curve"},"content":{"rendered":"<p>To draw a quadratic curve, we use the <strong> quadraticCurve()<\/strong> method. However, we need to combine the quadraticCurve() method with the <strong>beginPath()<\/strong> and <strong>moveTo()<\/strong> methods in order to draw a quadratic curve. The <strong>beginPath()<\/strong> and <strong>moveTo()<\/strong> methods define the starting point of the quadratic curve. The <strong> quadraticCurve()<\/strong> method is to define the lowest point to the end point of the quadratic curve. The syntax of the <strong> quadraticCurve()<\/strong> method is<\/p>\n<pre>quadraticCurveTo(x<sub>1<\/sub>, y<sub>1<\/sub>, x<sub>2<\/sub>, y<sub>2<\/sub>)\r\n<\/pre>\n<p>*(x<sub>1<\/sub>, y<sub>1<\/sub>) is the lowest point.<br \/>\n*(x<sub>2<\/sub>, y<sub>2<\/sub>) is the end point.<\/p>\n<p>Before we can draw a quadratic curve, we need to create a canvas by defining its width and height, using the &lt;canvas&gt; tag. Please note that &lt;canvas&gt; is an HTML5 tag that may not be supported by certain versions of browsers.<br \/>\nPlease refer to our tutorial for further explanation on drawing graphics.<br \/>\n<a href=\"http:\/\/javascript-tutor.net\/index.php\/javascript-lesson-31-creating-graphics-using-javascript\/\">JavaScript Tutorial Lesson 31<\/a><\/p>\n<p>The code to draw a quadratic curve is as follows:<\/p>\n<p>&lt;canvas id=&#8221;myCanvas&#8221; style=&#8221;border: 1px solid #d3d3d3;&#8221; width=&#8221;250&#8243; height=&#8221;300&#8243;&gt;<br \/>\n&lt;\/canvas&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;Draw Curve&#8221; Onclick=&#8221;DrawCurve()&#8221;&gt;<br \/>\n&lt;script&gt;<br \/>\nfunction DrawCurve()<br \/>\n{<br \/>\nvar c = document.getElementById(&#8220;myCanvas&#8221;);<br \/>\nvar ctx = c.getContext(&#8220;2d&#8221;);<br \/>\nctx.beginPath();<br \/>\nctx.moveTo(20, 20);<br \/>\nctx.quadraticCurveTo(90, 400, 200, 20);<br \/>\nctx.stroke();<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<p>Please click on the Draw Curve button to view the output.<\/p>\n<p><canvas id=\"myCanvas\" style=\"border: 1px solid #d3d3d3;\" width=\"350\" height=\"300\"><br \/>\n<\/canvas><br \/>\n<input type=\"button\" value=\"Draw Curve\" \/><br \/>\n<script>\nfunction DrawCurve()\n{\nvar c = document.getElementById(\"myCanvas\");\nvar ctx = c.getContext(\"2d\");\nctx.beginPath();\nctx.moveTo(20, 20);\nctx.quadraticCurveTo(140, 400, 300, 20);\nctx.stroke();\n}\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To draw a quadratic curve, we use the quadraticCurve() method. However, we need to combine the quadraticCurve() method with the beginPath() and moveTo() methods in order to draw a quadratic curve. The beginPath() and moveTo() methods define the starting point of the quadratic curve. The quadraticCurve() method is to define the lowest point to the &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/javascript-quadratic\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Drawing a Quadratic Curve&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2006","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"description\" content=\"Learn how to create a javascript that can draw a quadratic curve\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a javascript that can draw a quadratic curve\" \/>\n<meta property=\"og:url\" content=\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:modified_time\" content=\"2018-04-08T08:22:50+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/javascript-quadratic\/\",\"url\":\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html\",\"name\":\"Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2017-07-15T03:29:31+00:00\",\"dateModified\":\"2018-04-08T08:22:50+00:00\",\"description\":\"Learn how to create a javascript that can draw a quadratic curve\",\"breadcrumb\":{\"@id\":\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Drawing a Quadratic Curve\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Learn how to create a javascript that can draw a quadratic curve","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html","og_locale":"en_US","og_type":"article","og_title":"Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"Learn how to create a javascript that can draw a quadratic curve","og_url":"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_modified_time":"2018-04-08T08:22:50+00:00","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/javascript-quadratic\/","url":"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html","name":"Drawing a Quadratic Curve - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2017-07-15T03:29:31+00:00","dateModified":"2018-04-08T08:22:50+00:00","description":"Learn how to create a javascript that can draw a quadratic curve","breadcrumb":{"@id":"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/javascript-tutor.net\/jSample\/jsp_quadraticgraph.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"Drawing a Quadratic Curve"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=2006"}],"version-history":[{"count":30,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2006\/revisions"}],"predecessor-version":[{"id":2543,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2006\/revisions\/2543"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}