// Numbas version: exam_results_page_options {"name": "Katrin's copy of Use canvas to draw a rectangle", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"question_groups": [{"pickingStrategy": "all-ordered", "name": "", "pickQuestions": 0, "questions": []}], "variablesTest": {"maxRuns": 100, "condition": ""}, "variable_groups": [], "functions": {"rectangle": {"parameters": [["w", "number"], ["h", "number"]], "language": "javascript", "definition": "\n var c = document.createElement('canvas');\n $(c).attr('width',w+40).attr('height',h+40);\n var context = c.getContext('2d');\n \n //fill in rectangle with a light shade\n context.fillStyle = '#eee';\n context.fillRect(5,5,w,h);\n \n //draw outline\n context.strokeStyle = '#000';\n context.lineWidth = 3;\n context.strokeRect(5,5,w,h);\n \n //draw labels\n context.fillStyle = '#000';\n context.font = '20px sans-serif';\n var wstring = w+'m';\n var tw = context.measureText(wstring).width;\n console.log(tw);\n context.fillText(wstring,5+(w-tw)/2,5+h+25);\n \n var hstring = h+'m';\n var hw = context.measureText(hstring).width;\n context.save();\n context.translate(5+w+25,5+(h+hw)/2);\n context.rotate(-Math.PI/2);\n context.fillText(hstring,0,0);\n \n return c;\n ", "type": "html"}}, "ungrouped_variables": ["h", "w"], "parts": [{"showPrecisionHint": false, "prompt": "

What is the rectangle's perimeter, in metres?

", "maxValue": "2(w+h)", "type": "numberentry", "showCorrectAnswer": true, "minValue": "2(w+h)", "allowFractions": false, "correctAnswerFraction": false, "marks": 1, "scripts": {}}, {"showPrecisionHint": false, "prompt": "

What is the rectangle's area, in metres?

", "maxValue": "w*h", "type": "numberentry", "showCorrectAnswer": true, "minValue": "w*h", "allowFractions": false, "correctAnswerFraction": false, "marks": 1, "scripts": {}}], "type": "question", "statement": "

This rectangle is {w} metres wide and {h} metres long.

\n

{rectangle(w,h)}

", "rulesets": {}, "showQuestionGroupNames": false, "variables": {"w": {"group": "Ungrouped variables", "definition": "random(100..200#5)", "templateType": "anything", "name": "w", "description": ""}, "h": {"group": "Ungrouped variables", "definition": "random(50..100#5)", "templateType": "anything", "name": "h", "description": ""}}, "tags": ["canvas", "demo", "function", "graphic"], "name": "Katrin's copy of Use canvas to draw a rectangle", "preamble": {"js": "", "css": ""}, "advice": "", "metadata": {"licence": "Creative Commons Attribution 4.0 International", "notes": "

Doesn't work in IE8, because it doesn't support the canvas element.

", "description": "

The custom function rectangle(width,height) draws a rectangle with the given dimensions, along with some labels.

"}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Katrin Thomson", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3424/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Katrin Thomson", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3424/"}]}