JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<html>
<head>
<meta charset='utf-8'>
<title>Nathan Lackies Geometry Coding Assignment 3</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--LIBRARIES (no books though)-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<!--INVISIBLE FORM-->
<input id="hintNumFormId" type="hidden" value="0" name="hintNumberForum">
<!--Creates a container for the page to be contained in-->
<div class="container">
<h1>
<!--Makes a hint button-->
<button type="button" class="btn btn-info btn-md hint-btn" onclick="hintFunc()">Hint</button>
Geometry Coding Lesson #3
<!--progress bar-->
<img style="display: inline-block;" id="pbar" src="https://nathanscode.com/assignment3/IMG/PBE.png" width="300px">
<img id="pbar1" style="display: none;" src="https://nathanscode.com/assignment3/IMG/PBC.png" width="300px">
</h1>
<div class="row">
<div class="col-lg-8 left-panel">
<!--Makes the canvas area-->
<canvas-area id="ca" cartesian="true" resizable="none">
<canvas id="c"></canvas>
</canvas-area>
<!--Makes the Cursor Location show under the grid-->
<span id="coords">Cursor Location: ./.</span> <b style="display: none;">|</b> <span style="display: none;" id="size">size: ./.</span>
<br><input id="OLID" type="checkbox" value="Show Origin Lines" name="OL" checked> Show Origin Lines
<br><br>
<!--Adds info box that tells you how to use the graph-->
<div class="card bg-light mb-3">
<h5 class="card-header">Graph Manipulation Instructions</h5>
<div class="card-body">
<div class="card-text">
<p>Click and drag on the graph window to move the viewpoint around. Scroll on the graph window to zoom in and out.</p>
</div>
</div>
</div>
</div>
<!--Makes the panel on the right-->
<div class="col-lg-4 right-panel">
<ul class="nav nav-pills" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="pill" href="#Question">Question</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#Answers">Answers</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#Explanation">Explanation</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#Hints">Hints</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#Code">Code</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#Changelog">Changelog</a>
</li>
</ul>
<div class="tab-content">
<!--Makes the question tab-->
<div id="Question" class="tab-pane fade show active">
<div class="alert alert-primary">
<p>The doorstop factory is making triangle shaped doorstops. You come up with a new idea for a doorstop that will work much better than the current one. Previously, the doorstops were 5 inches wide by 2.88 inches tall. Your new doorstop idea is 7 inches wide by 3 inches tall. You think that since it is longer it will stop the door better. Your manager thinks this is a great idea, and asks for the angle of elevation. Find the measure of Angle A in your new doorstop plan. Input angle A's measure below.</p>
<h5><strong>Round to the nearest hundredth</strong></h5>
<h5>You will need a scientific calculator for this problem, if you don't have one, <a href="https://www.desmos.com/scientific" target="_blank">click here.</a></h5>
</div>
</div>
<!--Makes the explanation tab-->
<div id="Explanation" class="tab-pane fade">
<div style="border-style: solid; border-color: gray;">
<p style="padding:10px">This is an original problem that I came up with. You work in a doorstop factory, and have to find the angle of the doorstop idea that you came up with. If you want more information on how to solve the problem, hit the hints button.</p>
</div>
</div>
<!--Makes the code tab-->
<div id="Code" class="tab-pane fade">
<p data-height="265" data-theme-id="0" data-slug-hash="XZbQXJ" data-default-tab="result" data-user="Naitron" data-embed-version="2" data-pen-title="Geo Lesson 3" class="codepen">See the Pen <a href="https://codepen.io/Naitron/pen/XZbQXJ/">Geo Lesson 3</a> by Nate (<a href="https://codepen.io/Naitron">@Naitron</a>) on <a href="https://codepen.io">CodePen</a>.</p>
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
</div>
<!--Makes the hints tab-->
<div id="Hints" class="tab-pane fade">
<br>
<div id="noHintMessage" style="display: block;" class="alert alert-danger">
<p>You have not used any hints yet, this area shows your previously used hints.</p>
</div>
<div id="hintTabN1" style="display: none;" class="alert alert-success">
<p>Use a triganomic ratio to figure out the measure of angle A.</p>
</div>
<div id="hintTabN2" style="display: none;" class="alert alert-success">
<p>Use Inverse Tangent on the legs of the triangle to find the measure of angle A</p>
</div>
<div id="hintTabN3" style="display: none;" class="alert alert-success">
<p>The measure of angle A is the Inverse Tangent (Tan^-1) of 3/7.</p>
</div>
<button id="hint-btn" type="button" class="btn btn-info btn-md hint-btn" onclick="hintFunc()">Get Hint</button>
</div>
<!--Changelog-->
<div id="Changelog" class="tab-pane fade">
<br>
<ul class="change-log">
<li>Made origin lines toggleable</li>
<li>Added a black border to this right panel</li>
<li>Removed Cookies, not needed this lesson</li>
<li>Added a separate tab for answers</li>
<li>Added a progress bar</li>
</ul>
</div>
<!--Answers Tab-->
<div id="Answers" class="tab-pane fade">
<div style="padding: 20px">
<h5 style="color: gray;">Example: A=25.85</h5>
<input name="answer" id="answer" placeholder="Input distance to nearest house" class="form-control">
<button class="btn btn-md btn-info btn-answer" onclick="checkAnswer()">Check Answer</button>
<span id="answerresults"></span>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://nathanscode.com/assignment3/canvas-area.js"></script>
</body>
</html>
#app {
display: grid;
}
canvas-area {
display: block;
overflow: hidden;
background-color:#eee;
border:solid 1px black;
width: 100%;
height: 55vh;
}
.right-panel {
overflow: scroll;
height: 86vh;
background-color: #ededed;
border-style: solid;
border-color: black;
border-width: 1px;
padding: 10px;
border-radius: 10px;
}
.change-log li {
padding-bottom: 5px;
color: #666666;
}
.left-panel {
padding-right: 35px;
}
.btn-answer {
margin-top: 6px;
}
@media (min-width: 667px) {
canvas-area {
height: 120vh;
}
}
@media (min-width: 684px) {
canvas-area {
height: 100vh;
}
}
@media (min-width: 768px) {
canvas-area {
height: 40vh;
}
}
@media (min-width: 1024px) {
canvas-area {
height: 55vh;
}
}
@media (min-width: 1400px) {
.right-panel {
height: 75vh;
}
}
document.getElementById('hintNumFormId').value = '0';
//sets up variables
let question1Answer = 0;
let question2Answer = 0;
//sets up constants
const ctx = document.getElementById('c').getContext('2d'),
ca = document.getElementById('ca'),
coords = document.getElementById('coords'),
size = document.getElementById('size'),
toggleCartesian = (e) => { ca.cartesian = !ca.cartesian };
//draws stuff on the grid
function draw(ctx, view) {
let w = ctx.canvas.width, h = ctx.canvas.height,
sz = 20*view.scl, xoff = view.x%sz, yoff = view.y%sz;
if (ca.cartesian)
ctx.setTransform(1,0,0,-1,0.5,h-0.5);
else
ctx.setTransform(1,0,0,1,0.5,0.5);
ctx.clearRect(0,0,w,h);
// draw grid ...
if (view.scl > 0.2) {
ctx.strokeStyle = "#ccc";
ctx.lineWidth = 1;
ctx.beginPath();
for (let x=xoff,nx=w+1; x<nx; x+=sz) { ctx.moveTo(x,0); ctx.lineTo(x,h); }
for (let y=yoff,ny=h+1; y<ny; y+=sz) { ctx.moveTo(0,y); ctx.lineTo(w,y); }
ctx.stroke();
}
//draw origin lines
if (document.getElementById('OLID').checked == true) {
ctx.lineWidth = 2;
ctx.strokeStyle = "#555"; // origin lines ...
ctx.beginPath();
ctx.moveTo(view.x,0); ctx.lineTo(view.x,h);
ctx.moveTo(0,view.y); ctx.lineTo(w,view.y);
ctx.stroke();
ctx.closePath();
}
//draw shapes
ctx.save();
if (ca.cartesian)
ctx.setTransform(view.scl,0,0,-view.scl,view.x+0.5,h-view.y-0.5);
else
ctx.setTransform(view.scl,0,0,view.scl,view.x+0.5,view.y+0.5);
//draws the the 1st doorstop
ctx.beginPath();
ctx.strokeStyle = "#555";
ctx.moveTo(40,40);
ctx.lineTo(140,40)
ctx.lineTo(140,97.6);
ctx.lineTo(40,40);
ctx.fillStyle = "#fff2e6";
ctx.fill();
ctx.lineWidth=1;
ctx.stroke();
//draws the the 2nd doorstop
ctx.beginPath();
ctx.moveTo(40,160);
ctx.lineTo(180,160)
ctx.lineTo(180,220);
ctx.lineTo(40,160);
ctx.fillStyle = "#fff2e6";
ctx.fill();
ctx.lineWidth=1;
ctx.stroke();
//draws the text
ctx.scale(1, -1);
ctx.fillStyle = "black";
ctx.font = "20px Arial";
ctx.fillText('D',23,-25);
ctx.fillText('E',145,-25);
ctx.fillText('F',145,-100);
ctx.fillText('5',85,-20);
ctx.fillText('2.88',145,-60);
ctx.fillText('Current Doorstop',240,-60);
ctx.fillText('A',23,-145);
ctx.fillText('B',184,-145);
ctx.fillText('C',184,-220);
ctx.fillText('7',110,-140);
ctx.fillText('3',185,-185);
ctx.fillText('New Doorstop',240,-185);
//Handles if the hints show in the hints tab
if (document.getElementById("hintNumFormId").value == 1) {
document.getElementById("noHintMessage").style = "display: none;"
document.getElementById("hintTabN1").style = "display: block;"
}
if (document.getElementById("hintNumFormId").value == 2) {
document.getElementById("hintTabN2").style = "display: block;"
}
if (document.getElementById("hintNumFormId").value == 3) {
document.getElementById("hintTabN3").style = "display: block;"
document.getElementById("hint-btn").style = "display: none;"
}
}
function render() {
draw(ctx, ca.view);
requestAnimationFrame(render);
}
window.onload = () => {
ca.observe('pointer', e => {
let {x,y} = ca.pntToUsr(e),
prec = Math.max(Math.log(ca.view.scl)/Math.log(2), 0);
coords.innerHTML = `Cursor Location: ${Math.round((x/20)).toFixed(prec)} / ${Math.round((y/20)).toFixed(prec)}`;
});
ca.observe('resize', e => {
size.innerHTML = `size: ${e.width} / ${e.height}`;
});
ca.resize({width,height}=ca); // cause single initial notification ..
render();
}
//Checks if the answer is correct
function checkAnswer() {
let problemAnswer = document.getElementById('answer').value;
document.cookie = 'problemAnswerC='+ document.getElementById('answer').value;
let trimAnswer = problemAnswer.replace(/ /g,'');
if (trimAnswer == 'a=23.2' || trimAnswer == 'a=23.20' || trimAnswer == 'A=23.2' || trimAnswer == 'A=23.20' || trimAnswer == '23.20' || trimAnswer == '23.2') {
document.getElementById("pbar").style = "display: none;"
document.getElementById("pbar1").style = "display: inline-block;"
question1Answer = 1;
document.getElementById("answerresults").innerHTML = "<span class='alert alert-success'>Yay! Correct</span>";
} else {
document.getElementById("answerresults").innerHTML = "<span class='alert alert-danger'>Oops! Try Again!</div>";
}
};
//Displays hints when hint button is pressed
function hintFunc() {
let hintNum = document.getElementById("hintNumFormId").value
if (hintNum == 0) {
alert('Use a triganomic ratio to figure out the measure of angle A.')
document.getElementById("hintNumFormId").value = "1";
}
if (hintNum == 1) {
alert('Use Inverse Tangent on the legs of the triangle to find the measure of angle A')
document.getElementById("hintNumFormId").value = "2";
}
if (hintNum == 2) {
alert('The measure of angle A is the Inverse Tangent (Tan^-1) of 3/7.')
document.getElementById("hintNumFormId").value = "3";
}
if (hintNum == 3) {
alert('Sorry, no more hints, use the hints tab to see previous hints.')
}
if (hintNum > 3) {
alert('Please report this bug to Nathan, as this message should not appear, unless you edited the code, you hacker.')
}
}
Also see: Tab Triggers