{"id":380,"date":"2019-04-12T16:51:30","date_gmt":"2019-04-12T15:51:30","guid":{"rendered":"https:\/\/www.maxcanvas.org\/?page_id=380"},"modified":"2026-10-25T22:13:26","modified_gmt":"2026-10-25T22:13:26","slug":"lines","status":"publish","type":"page","link":"https:\/\/www.maxcanvas.org\/?page_id=380","title":{"rendered":"Lines"},"content":{"rendered":"\n<p>The Line Project is a simple project demonstrating how to use the MC.draw.line() method. The simulation illustrates the &#8220;Earth &#8211; Venus&#8221; pentagon. In short, an earth year is 13\/8ths of that of Venus. If you draw a line between the two bodies (over a number of years), the following pattern emerges.<\/p>\n\n\n\n<figure><iframe loading=\"lazy\" width=\"605px\" height=\"405px\" src=\"https:\/\/www.maxcanvas.org\/MaxCanvas\/Examples\/MC%20-%2007%20-%20Lines.html\"><\/iframe><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>This Project utilises:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ConBoxes and GUI for start\/restart, set speed and pause<\/li><li>A novel use of a pair Sprites as &#8220;calculators&#8221; for the point ends (they are not rendered)<\/li><li>MC.draw.line() to draw a large series of white, 90% transparent lines. <\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ MaxCanvas Project\n\/\/ 07-Lines.JS File (April 2019)\n\/\/\n\/\/ Required to drag MC.js into Intellisense\n\/\/ thanks to https:\/\/visualstudiomagazine.com\/blogs\/tool-tracker\/2018\/07\/use-javascript-code.aspx (Dec 2018)\n\/\/\/ &lt;reference path=\"MC.js\" \/>\n\nwindow.onload = (function() {\n\n\/\/ AQUIRE HTML DOM CANVAS REFERENCE\nvar c=document.getElementById(\"canvas\");\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ INITIALISE MC Engine \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nMC.init(c);\n\n\/\/ Configure .game\nMC.game.physicsUpdates = 1;     \/\/ Will Speed up the simulation .. this many lines added per frame\nMC.canvas.setSize(600,400)\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ END OF Initialisation \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/-----------------------------------------------------------------------------\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ VARIABLE DECLARATION \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n    \/\/ GUI Creation\n    var GUI = new MC.GUI();\n    \/\/ Start \/ Restart ConBox - calls \"Start()\"\n    var Restart = new MC.ConBox({ width: 150,\n                                height: 40,\n                                text: \"Restart\",\n                                onClick: function () { start(); } \n                             });\n    \/\/ Pause ConBox - toggles MC.game.paused\n    var Pause = new MC.ConBox({ width: 150,\n                                height: 40,\n                                text: \"Pause\",\n                                onClick: function () {\n                                    MC.game.paused = !MC.game.paused;\n                                    if (MC.game.paused) { Pause.text = \"Unpause\" ;}\n                                    else {Pause.text = \"Pause\";}\n                                    } \n                             });\n    \/\/ Speed ConBox - cycles MC.physicsUpdates &amp; calls \"Start()\"\n    var Speed = new MC.ConBox({ width: 150,\n                                height: 40,\n                                text: \"Speed \" + MC.game.physicsUpdates,\n                                onClick: function () {\n                                    var spd = 0;\n                                    switch (MC.game.physicsUpdates) {\n                                        case 1:\n                                            spd = 5;\n                                            break;\n                                        case 5:\n                                            spd = 10;\n                                            break;\n                                        case 10:\n                                            spd = 15;\n                                            break;\n                                        case 15:\n                                            spd = 20;\n                                            break;\n                                        case 20:\n                                            spd = 1;\n                                            break;\n                                        default:\n                                            spd = 5;\n                                    }\n                                    MC.game.physicsUpdates = spd;\n                                    Speed.text = \"Speed \"+spd;\n                                    start();\n                                }\n                             });\n    GUI.push(Restart,Pause,Speed);\n    MC.mouse.onClickL = function () {\n        GUI.click();\n    };    \n    \n    \/\/ Restart function\n    var start = function () {\n        Lines = [];\n        Ends.bin[0].angle = Ends.bin[1].angle = 0;\n        };\n    \n    \n    var color = new MC.Color(255,255,255,0.1); \n    var Lines = [];\n    var Ends = new MC.SpriteBin();\n    \n    \/\/ Going to utilise the Sprite Class\n    \/\/ Using update function to emulate a body orbiting the graphic centre, with the angle and angleVel tracking an orbital radius angle\n    \/\/ Don't have to render them either\n    var end1 = new MC.Sprite({type: \"circ\", angleVel: 360\/13 * 100, size2: 120 });\n    end1.dev.update = function () {\n                                var rad = new MC.Point(0,end1.size2);\n                                rad.rotate(end1.angle);\n                                rad.add(MC.canvas.midX+100, MC.canvas.midY);\n                                end1.moveTo(rad);\n                             };\n    \n    var end2 = end1.clone();\n    end2.setValues ({angleVel: 360\/8 * 100, size2: 180});\n    end2.dev.update = function () {\n                                var rad = new MC.Point(0,end2.size2);\n                                rad.rotate(end2.angle);\n                                rad.add(MC.canvas.midX+100, MC.canvas.midY);\n                                end2.moveTo(rad);\n                             };\n    Ends.push(end1, end2);\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ END OF declarations  \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/-----------------------------------------------------------------------------\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/      GAME LOOP       \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n\/\/ first call, request subsequently made within\ngameLoop();\n\nfunction gameLoop() {\n    \/\/ ESSENTIAL MAINTAINANCE\n    requestAnimationFrame(gameLoop);\n    MC.game.update();                   \n    \n    \/\/ PHYSICS UPDATE LOOP\n    for (var i = 0; i &lt; MC.game.physicsUpdates; i++) {\n        Ends.update();\n        \/\/ Populate the Lines array with the position of the 2 Sprites\n        if (Lines.length &lt; 5000 &amp;&amp; !MC.game.paused) Lines.push(Ends.bin[0].pos.clone(),Ends.bin[1].pos.clone());\n    }\n    \n    \/\/ NON-PHYSICS UPDATES\n    GUI.update();  \n\n    \/\/ RENDER\n    \/\/ Stage 1.  Clear the canvas\n    MC.draw.clearCanvas(\"Black\");\n\n    \/\/ Stage 2.  Render Sprites\n        \/\/ Draw the lines\n    for (var i = 0; i &lt; Lines.length; i = i+2) {\n        MC.draw.line(Lines[i],Lines[i+1],color,1);\n    }\n    \n    \/\/ Stage 3.  Render GUI\n    GUI.render(0,0);\n}\n\n}); \/\/ EoF\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Line Project is a simple project demonstrating how to use the MC.draw.line() method. The simulation illustrates the &#8220;Earth &#8211; Venus&#8221; pentagon. In short, an earth year is 13\/8ths of that of Venus. If you draw a line between the two bodies (over a number of years), the following pattern emerges. Code This Project utilises: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-380","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380"}],"version-history":[{"count":4,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/380\/revisions"}],"predecessor-version":[{"id":608,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/380\/revisions\/608"}],"wp:attachment":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}