// Numbas version: exam_results_page_options {"name": "Tree Diagram", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"tags": [], "functions": {"rectangle": {"parameters": [["branch1", "number"], ["branch2", "number"]], "type": "html", "language": "javascript", "definition": "var c = document.createElement('canvas');\n$(c).attr('width',600).attr('height',250);\nvar context = c.getContext('2d');\n\n//Set interval variables\nvar vertInt1 = (c.height-100)/(branch1-1);\nvar vertInt2 = (c.height-50)/(branch1*branch2-1);\n\n// set line width and colour\ncontext.lineWidth = 2;\n//context.strokeStyle = \"red\";\n\n//Draw tree\nfor (i = 0; i < branch1; i++) { \n // position cursor\ncontext.moveTo(25, c.height/2);\n// draw the line\ncontext.lineTo(c.width/2-25, i*vertInt1+50);\n \nfor (j = 0; j < branch2; j++) { \n// position cursor\ncontext.moveTo(c.width/2+25, i*vertInt1+50);\n// draw the line\ncontext.lineTo(c.width-50, (branch2*i+j)*vertInt2+25);\n}}\n// make visible with stroke colour\ncontext.stroke();\n\nreturn c;\n "}}, "advice": "", "ungrouped_variables": ["branch1", "branch2"], "parts": [], "preamble": {"css": "", "js": ""}, "variable_groups": [], "variablesTest": {"condition": "", "maxRuns": 100}, "extensions": [], "variables": {"branch1": {"templateType": "anything", "description": "", "group": "Ungrouped variables", "name": "branch1", "definition": "random(2..5)"}, "branch2": {"templateType": "anything", "description": "", "group": "Ungrouped variables", "name": "branch2", "definition": "random(2..5)"}}, "statement": "

This set of branches has {branch1} elements, and the second has {branch2} elements.

\n

{rectangle(branch1,branch2)}

", "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

This custom function draws a tree diagram with a random number of branches (branch1 and branch2).

"}, "rulesets": {}, "name": "Tree Diagram", "type": "question", "contributors": [{"name": "David Wishart", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1461/"}]}]}], "contributors": [{"name": "David Wishart", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1461/"}]}