Widget:BarrierDemo: Difference between revisions
From COMP15212 Wiki
Yuron [PHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) m (1 revision imported) |
pc>Yuron No edit summary |
||
Line 14: | Line 14: | ||
<button type="button" id="resetBtn"onclick="reset();stoppedMode()">reset</button> | <button type="button" id="resetBtn"onclick="reset();stoppedMode()">reset</button> | ||
<script> | <script> | ||
// Set to use dark theme if the body's background color is too darkw | |||
var bodyColour = $("body").css("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; | |||
/** | /** | ||
Line 56: | Line 65: | ||
green: "#00ff00", | green: "#00ff00", | ||
} | } | ||
// Replace black with white in dark theme | |||
if (usingDarkTheme) | |||
Colors.black = "#ffffff"; | |||
/** | /** | ||
* The way a rectangle should be drawn | * The way a rectangle should be drawn | ||
Line 510: | Line 524: | ||
{ // Global variable prevents overprinting | { // Global variable prevents overprinting | ||
ctx.save(); // in the event of being called repeatedly | ctx.save(); // in the event of being called repeatedly | ||
ctx.fillStyle = "Black"; | ctx.fillStyle = usingDarkTheme? "white" : "Black"; | ||
ctx.font= "10px Calibri"; | ctx.font= "10px Calibri"; | ||
ctx.fillText(name, x, y); | ctx.fillText(name, x, y); |
Revision as of 14:48, 13 August 2019
This widget serves as a demonstration for memory barriers.