Widget:PeripheralIO: Difference between revisions
From COMP15212 Wiki
Yuron [PHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) m (1 revision imported) |
pc>Yuron No edit summary |
||
Line 6: | Line 6: | ||
<p><canvas id="peripheral_canvas" width="600" height="200"></canvas></p> | <p><canvas id="peripheral_canvas" width="600" height="200"></canvas></p> | ||
<script> | <script> | ||
// Set to use dark theme if the body's background color is too dark | |||
var bodyColour = window.getComputedStyle(document.querySelector('body')).getPropertyValue("background-color").match(/rgba?\((.*)\)/)[1].split(',').map(Number); | |||
var usingDarkTheme; | |||
if (bodyColour[3] === 0) | |||
usingDarkTheme = false; | |||
else | |||
usingDarkTheme = bodyColour.reduce((a, b) => a + b, 0) < 255 * 1.5; | |||
// Javascript interactive demo. of I/O ports. | // Javascript interactive demo. of I/O ports. | ||
Line 102: | Line 110: | ||
function draw() { | function draw() { | ||
// Set stroke style according to theme | |||
ctx.strokeStyle = usingDarkTheme ? "grey" : "black"; | |||
drawLabel(); //Draw Label | drawLabel(); //Draw Label | ||
draw_IO(); | draw_IO(); | ||
Line 228: | Line 239: | ||
function drawLabel() { | function drawLabel() { | ||
ctx.font = '30px Arial'; | ctx.font = '30px Arial'; | ||
ctx.fillStyle = "black"; | ctx.fillStyle = usingDarkTheme ? "white" : "black"; | ||
ctx.fillText(labelString, labelPositionX, labelPositionY); | ctx.fillText(labelString, labelPositionX, labelPositionY); | ||
ctx.font = '20px Arial'; | ctx.font = '20px Arial'; | ||
ctx.fillStyle = "black"; | ctx.fillStyle = usingDarkTheme ? "white" : "black"; | ||
ctx.fillText(" Address", HEX_X - 80, HEX_Y - 10); | ctx.fillText(" Address", HEX_X - 80, HEX_Y - 10); | ||
ctx.fillText(" Data", HEX_X + 20, HEX_Y - 10); | ctx.fillText(" Data", HEX_X + 20, HEX_Y - 10); | ||
Line 296: | Line 307: | ||
context.fill(); | context.fill(); | ||
if (stroke) { | if (stroke) { | ||
context.strokeStyle = "black"; | context.strokeStyle = usingDarkTheme ? "white" : "black"; | ||
context.lineWidth = 3; | context.lineWidth = 3; | ||
context.stroke(); | context.stroke(); |
Revision as of 15:57, 13 August 2019
This widget serves as a demonstration for peripheral IO.