add bg() and console text display

This commit is contained in:
lee2sman 2021-02-14 01:44:15 -05:00
parent aad87ec36d
commit 06c47c9e01
1 changed files with 33 additions and 9 deletions

View File

@ -3,6 +3,7 @@ let angle,
y,
drawing = true,
retroStyle = false,
showCommands = true,
turtleC;
function setup() {
createCanvas(windowWidth, windowHeight); //canvas is size of window
@ -10,6 +11,7 @@ function setup() {
turtle();
displayTurtle();
retroFilter();
displayConsole();
}
function resetDefaults() {
@ -28,15 +30,6 @@ function setpos(_newX, _newY, startx = x, starty = y) {
}
x = newX;
y = newY;
try {
if (_newX == "" || _newY == "") throw "is missing input x,y coordinates";
if (isNaN(_newX) || isNaN(_newY)) throw "requires: x,y input coordinates";
if (_newX < 0 || _newY < 0 || _newX > windowWidth || _newY > windowHeight)
throw "drawing offscreen";
} catch (err) {
console.log("Error: setpos " + err);
}
}
function forward(d, startx = x, starty = y, _angle = 360 - angle) {
let newX = startx + d * sin(_angle);
@ -82,9 +75,15 @@ function randint(max = 100) {
//default returns int between 0 and 100
return int(random(max));
}
function bg(c='black'){
background(c)
}
function retro() {
retroStyle = true;
}
function noConsole() {
showCommands = false;
}
function retroFilter() {
if (retroStyle) {
//attempts a 'retro' aesthetic
@ -102,6 +101,31 @@ function displayTurtle() {
triangle(-10, 10, 10, 10, 0, -10);
pop();
}
function displayConsole() {
if (showCommands) {
let programCode = turtle.toString();
programCodeArr = splitTokens(programCode, "\n");
let container = createDiv();
for (let i = 1; i < programCodeArr.length - 1; i++) {
createP("\u00A0" + programCodeArr[i])
.style("font-family", "monospace")
.style("font-weight", "bold")
.style("font-size", "2rem")
.style("display", "fixed")
.style("background-color", "black")
.style("color", "yellow")
.style("border", "0")
.style("margin", "0")
.style("padding", "0")
.style("display", "inline-block")
.parent(container);
}
container.position(0, height - height / 8);
}
}
function windowResized() {
//resizes canvas if window is resized
resizeCanvas(windowWidth, windowHeight);