Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dloscutoff committed Mar 4, 2024
2 parents 7fb838a + c510421 commit ee5fa9c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 59 deletions.
23 changes: 13 additions & 10 deletions BitCycle/bitcycle.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@
margin: 2px;
}
.float-left {
display: inline-block;
float: left;
margin-right: 15px;
}
.float-right {
.float-left > * {
display: inline-block;
margin-right: 10px;
}
.float-right {
float: right;
margin-left: 15px;
}
.float-right > * {
display: inline-block;
margin-left: 10px;
}
.output {
font-family: 'Courier New', monospace;
Expand Down Expand Up @@ -74,6 +78,11 @@ canvas {
input[type="number"] {
width: 4em;
}
code {
padding: 0.25rem;
background-color: #ddd;
border-radius: 0.25rem;
}
#cheat-sheet-indicator {
font-family: 'Courier New', monospace;
}
Expand All @@ -82,9 +91,3 @@ input[type="number"] {
background: #888;
cursor: default;
}

code {
padding: 0.25rem;
background-color: #ddd;
border-radius: 0.25rem;
}
83 changes: 50 additions & 33 deletions BitCycle/bitcycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,34 +812,50 @@ function unpackCode(packedCode) {
function showEditor() {
const editor = document.getElementById('editor'),
interpreter = document.getElementById('interpreter'),
startEdit = document.getElementById('start-edit'),
permalink = document.getElementById('permalink'),
mainControlsEdit = document.getElementById('main-controls-edit-mode'),
mainControlsRun = document.getElementById('main-controls-run-mode'),
executionControls = document.getElementById('execution-controls'),
sourceCode = document.getElementById('source');

editor.style.display = "block";
interpreter.style.display = "none";
startEdit.value = "Execute";
editor.classList.remove("hide");
interpreter.classList.add("hide");

permalink.style.display = "inline-block";
executionControls.style.display = "none";
mainControlsEdit.classList.remove("hide");
mainControlsRun.classList.add("hide");
executionControls.classList.add("hide");

sourceCode.focus();
}

function hideEditor() {
const editor = document.getElementById('editor'),
interpreter = document.getElementById('interpreter'),
startEdit = document.getElementById('start-edit'),
permalink = document.getElementById('permalink'),
mainControlsEdit = document.getElementById('main-controls-edit-mode'),
mainControlsRun = document.getElementById('main-controls-run-mode'),
executionControls = document.getElementById('execution-controls');

editor.style.display = "none";
interpreter.style.display = "block";
startEdit.value = "Edit";
editor.classList.add("hide");
interpreter.classList.remove("hide");

permalink.style.display = "none";
executionControls.style.display = "block";
mainControlsEdit.classList.add("hide");
mainControlsRun.classList.remove("hide");
executionControls.classList.remove("hide");
}

function updateByteCount() {
const byteCount = document.getElementById('byte-count'),
sourceCode = document.getElementById('source');
const sourceAsBytes = unescape(encodeURIComponent(sourceCode.value));

byteCount.innerText = pluralize(sourceAsBytes.length, "byte");
}

function pluralize(number, noun) {
if (number === 1) {
return `${number} ${noun}`;
} else {
return `${number} ${noun}s`;
}
}

function toggleCheatSheet() {
Expand Down Expand Up @@ -886,14 +902,14 @@ function loadProgram() {
// Display the current state of the playfield
program.displayPlayfield();

runPause.style.display = "block";
step.style.display = "block";
runPause.classList.remove("hide");
step.classList.remove("hide");
if (framesPerTick.value > 1) {
tick.style.display = "block";
tick.classList.remove("hide");
} else {
tick.style.display = "none";
tick.classList.add("hide");
}
done.style.display = "none";
done.classList.add("hide");
runPause.value = "Run";
haltRestart.value = "Halt";
}
Expand All @@ -919,21 +935,21 @@ function haltProgram() {

program.halt();

runPause.style.display = "none";
step.style.display = "none";
tick.style.display = "none";
done.style.display = "block";
runPause.classList.add("hide");
step.classList.add("hide");
tick.classList.add("hide");
done.classList.remove("hide");
haltRestart.value = "Restart";
}

function startEditBtnClick() {
if (program === null) {
loadProgram();
hideEditor();
} else {
unloadProgram();
showEditor();
}
function startBtnClick() {
loadProgram();
hideEditor();
}

function editBtnClick() {
unloadProgram();
showEditor();
}

function runPauseBtnClick() {
Expand Down Expand Up @@ -982,9 +998,9 @@ function speedInputChange() {
tick = document.getElementById('tick');
program.setSpeed(ticksPerSecond.value, framesPerTick.value);
if (!program.done && framesPerTick.value > 1) {
tick.style.display = "block";
tick.classList.remove("hide");
} else {
tick.style.display = "none";
tick.classList.add("hide");
}
}

Expand Down Expand Up @@ -1012,5 +1028,6 @@ window.onload = function() {
context = null;
program = null;
loadFromQueryString();
updateByteCount()
showEditor();
}
46 changes: 30 additions & 16 deletions BitCycle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@

<body>
<h1><a href="https://github.com/dloscutoff/Esolangs/tree/master/BitCycle" target="_blank"><span class="blue">Bit</span><span class="green">Cycle</span></a></h1>
<div id="main-controls" class="container">
<input type="button" id="start-edit" class="control float-left so-box" value="Start/Edit" onclick="startEditBtnClick()" />
<input type="button" id="permalink" class="control float-right so-box" value="Permalink" onclick="permalinkBtnClick()" />
<div id="main-controls-edit-mode" class="container">
<div class="float-left">
<input type="button" id="start" class="control so-box" value="Execute" onclick="startBtnClick()" />
</div>
<div class="float-right">
<span id="byte-count" class=""></span>
<input type="button" id="permalink" class="control so-box" value="Permalink" onclick="permalinkBtnClick()" />
</div>
</div>
<div id="main-controls-run-mode" class="container">
<div class="float-left">
<input type="button" id="edit" class="control so-box" value="Edit" onclick="editBtnClick()" />
</div>
</div>
<div id="editor">
<div id="source-container" class="container">
<textarea id="source" placeholder="Enter your program here" rows="10" wrap="off" data-gramm_editor="false" spellcheck="false" autocapitalize="none" autocorrect="off"></textarea>
<textarea id="source" placeholder="Enter your program here" rows="10" wrap="off" data-gramm_editor="false" spellcheck="false" autocapitalize="none" autocorrect="off" oninput="updateByteCount()"></textarea>
</div>
<div id="inputs-container" class="container">
<textarea id="inputs" placeholder="Inputs, one per line" rows="3" wrap="off" data-gramm_editor="false" spellcheck="false" autocapitalize="none" autocorrect="off"></textarea>
Expand All @@ -41,20 +51,24 @@ <h1><a href="https://github.com/dloscutoff/Esolangs/tree/master/BitCycle" target
</div>
<div id="execution-controls">
<div id="execution-buttons" class="container">
<input type="button" id="run-pause" class="control float-left so-box" value="Run/Pause" onclick="runPauseBtnClick()" />
<input type="button" id="step" class="control float-left so-box" value="Step" onclick="stepBtnClick()" />
<input type="button" id="tick" class="control float-left so-box" value="Tick" onclick="tickBtnClick()" />
<span id="done" class="control float-left so-box">Done.</span>
<input type="button" id="halt-restart" class="control float-left so-box" value="Halt/Restart" onclick="haltRestartBtnClick()" />
<div class="float-left">
<input type="button" id="run-pause" class="control so-box" value="Run/Pause" onclick="runPauseBtnClick()" />
<input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" />
<input type="button" id="tick" class="control so-box" value="Tick" onclick="tickBtnClick()" />
<span id="done" class="control so-box">Done.</span>
<input type="button" id="halt-restart" class="control so-box" value="Halt/Restart" onclick="haltRestartBtnClick()" />
</div>
</div>
<div id="execution-options" class="container">
<div class="option float-left so-box">
<label for="ticks-per-second">Ticks per second:</label>
<input type="number" id="ticks-per-second" min="1" value="10" onchange="speedInputChange()" />
</div>
<div class="option float-left so-box">
<label for="frames-per-tick">Frames per tick:</label>
<input type="number" id="frames-per-tick" min="1" value="1" onchange="speedInputChange()" />
<div class="float-left">
<span class="option so-box">
<label for="ticks-per-second">Ticks per second:</label>
<input type="number" id="ticks-per-second" min="1" value="10" onchange="speedInputChange()" />
</span>
<span class="option so-box">
<label for="frames-per-tick">Frames per tick:</label>
<input type="number" id="frames-per-tick" min="1" value="1" onchange="speedInputChange()" />
</span>
</div>
</div>
</div>
Expand Down

0 comments on commit ee5fa9c

Please sign in to comment.