Widget:ReadFile: Difference between revisions

From COMP15212 Wiki
pc>Yuron
No edit summary
 
gravatar W81054ch [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
This shows the principle of file buffering for reading files.
This shows the principle of file buffering for reading files.
[{{canonicalurl:Special:ShowWidget|widget=UsingFileDemos.ReadFile}} Dark-mode widget for embedding]
{{#widget:UsingFileDemos}}
{{#widget:UsingFileDemos}}
{{#widget:ReadFile}}
{{#widget:ReadFile}}
Line 6: Line 9:


<includeonly>
<includeonly>
<div id="readFile">
<p id="read_demo_error" style="color:red"></p>
<p id="read_demo_error" style="color:red"></p>
<div style="display:flex; align-items: center; justify-content: center;">
<div style="display:flex; align-items: center; justify-content: center;">
     <p style="margin-right:10px; margin-top:auto; margin-bottom:auto;">Type your file here:</p>
     <p style="margin-right:10px; margin-top:auto; margin-bottom:auto;">Type your file here:</p>
     <input id="file_content" type="text" name="File" style="flex:2;" value="Can a kangaroo jump higher than a house? Of course; a house doesn't jump at all!"><br>
     <input id="file_content" type="text" name="File" style="flex:2;" value="Can a kangaroo jump higher than a house? Of course; a house doesn't jump at all!"><br>
</div>
</div>
<canvas id="read_canvas" width="800" height="370"></canvas>
<canvas id="read_canvas" width="800" height="370"></canvas>


</div>
<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;


if (typeof(drawDisks) == "undefined")
if (typeof(drawDisks) == "undefined")
Line 70: Line 82:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function title() {
function title() {
     ctx.fillStyle = 'black';
     ctx.fillStyle = usingDarkTheme ? "white" : 'black';
     ctx.font = "30px Calibri";
     ctx.font = "30px Arial";
     ctx.fillText("Read buffer demonstration", 250, 35);
     ctx.fillText("Read buffer demonstration", 250, 35);
     ctx.font = "20px Calibri";
     ctx.font = "20px Arial";
     ctx.fillText('BUFFER', startx + 80, starty + 75);
     ctx.fillText('BUFFER', startx + 80, starty + 75);
}
}


function draw() {
function draw() {
    // Set stroke style according to theme
    ctx.strokeStyle = usingDarkTheme ? "white" : "black";
   
    // Set colour of surrounding text
    document.getElementById("readFile").style.color = usingDarkTheme ? "white" : "black";
   
     ctx.clearRect(0, 0, 800, 400);
     ctx.clearRect(0, 0, 800, 400);
     title();
     title();
Line 138: Line 156:


     fopenClicked = true;
     fopenClicked = true;
     drawDisks(ctx, 'white');
     drawDisks(ctx, usingDarkTheme ? "black" : 'white');
     busy = true;
     busy = true;


Line 198: Line 216:
function fillText() {
function fillText() {
     clearDisk(ctx);
     clearDisk(ctx);
     drawDisks(ctx, 'White');
     drawDisks(ctx, usingDarkTheme ? "black" : 'White');
     clearOutputArrow(ctx, startx, starty);
     clearOutputArrow(ctx, startx, starty);


Line 204: Line 222:
     {
     {
         ctx.fillStyle = "white";
         ctx.fillStyle = "white";
         ctx.font = "22px Calibri";
         ctx.font = "22px Arial";
         buffer_char(inputString[i], i);
         buffer_char(inputString[i], i);
     }
     }
Line 237: Line 255:
function printOutputString() {
function printOutputString() {
     ctx.fillStyle = "red";
     ctx.fillStyle = "red";
     ctx.font = "20px Calibri";
     ctx.font = "20px Arial";
     stringPos += 1;
     stringPos += 1;
     ctx.fillText(backupString.slice(0, stringPos), 40, starty + 95);
     ctx.fillText(backupString.slice(0, stringPos), 40, starty + 95);
Line 292: Line 310:
function drawButton(X, Y, BlockColour, Content) {
function drawButton(X, Y, BlockColour, Content) {
     ctx.fillStyle = BlockColour;
     ctx.fillStyle = BlockColour;
     ctx.font = "19px Calibri";
     ctx.font = "19px Arial";
     ctx.fillRect(X, Y, buttonLength, buttonHeight);
     ctx.fillRect(X, Y, buttonLength, buttonHeight);
     ctx.strokeRect(X, Y, buttonLength, buttonHeight);
     ctx.strokeRect(X, Y, buttonLength, buttonHeight);
Line 317: Line 335:
read_demo(document.getElementById('read_canvas'));
read_demo(document.getElementById('read_canvas'));
</script>
</script>
</includeonly>
</includeonly>

Latest revision as of 07:22, 14 August 2019

This shows the principle of file buffering for reading files.

Dark-mode widget for embedding

Type your file here: