Widget:BarrierDemo: Difference between revisions
From COMP15212 Wiki
pc>Yuron (Multiple transclusion doesn't seem to work) |
W81054ch [PHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) m (1 revision imported) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
This widget serves as a demonstration for memory barriers. | This widget serves as a demonstration for memory barriers. | ||
[{{canonicalurl:Special:ShowWidget|widget=BarrierDemo}} Dark-mode widget for embedding] | |||
{{#widget:BarrierDemo}} | {{#widget:BarrierDemo}} | ||
Line 14: | Line 16: | ||
<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 = 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; | |||
/** | /** | ||
Line 56: | Line 67: | ||
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 526: | ||
{ // 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); |