Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

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 Gemotry Coding Assignment 2</title>
		<!--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 #2
			</h1>
			
			<div class="row">
				<div class="col-lg-8 left-panel">
					<!--Loads in the images-->
					<img id="houseImage" src="https://nathanscode.com/assignment2/images/orange-house-hi.png" width="150px" style="display:none;">
					<img id="personImage" src="https://nathanscode.com/assignment2/images/pizza-delivery-boy.png" width="150px" style="display:none;">
					<!--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><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 veiwpoint 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="#Explanation">Explanation</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="#Hints">Hints</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>Each grid space is 1 unit wide, and 1 unit tall. Find the distance between the pizza man and each house.</p>
								<h6><strong>ROUND TO THE NEAREST HUNDRETH</strong></h6>
								<p>(the location of the houses and the person are represented by a black dot on the graph)</p>
							</div>
							<h5>Answers</h5>
							<h7>Example: 4.25</h7>
							<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>
							<br><br>
							<input name="answer1" id="answer1" placeholder="Input distance to furthest house" class="form-control">
							<button class="btn btn-md btn-info btn-answer" onclick="checkAnswer2()">Check Answer</button>
							<span id="answerresults1"></span>
						</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 have to find which house is closest to the pizza man, so he knows where to go first. 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="415" data-theme-id="0" data-slug-hash="ZvwXyJ" data-default-tab="html,result" data-user="Naitron" data-embed-version="2" data-pen-title="ZvwXyJ" class="codepen">See the Pen <a href="https://codepen.io/Naitron/pen/ZvwXyJ/">ZvwXyJ</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>Try using the distance formula to find the distance between the pizza man and one of the houses</p>
							</div>
							<div id="hintTabN2" style="display: none;" class="alert alert-success">
								<p>Rememer, on a triangle, If you sqare both legs and add them together, you get the squared hypotenuse</p>
							</div>
							<div id="hintTabN3" style="display: none;" class="alert alert-success">
								<p>Square both legs of the triangle, add them together, and take the square root of the sum. This should be the distance the pizza man is from the house</p>
							</div>
						</div>
						<!--Changelog-->
						<div id="Changelog" class="tab-pane fade">
							<br>
							<ul class="change-log">
								<li>Added a changelog</li>
								<li>Added a hints system</li>
								<li>Added a hints tab</li>
								<li>The number below the graph are now displays the correct cursor position</li>
								<li>Removed the graph size indicator</li>
								<li>Added origin lines</li>
								<li>Added a nice gray background to the tabs menu</li>
								<li>Added a fade effect upon switching tabs</li>
								<li>Destroyed the trees and built houses</li>
								<li>Promoted the blue person to a pizza man</li>
								<li>Added significantly less nothing</li>
						   </ul>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="https://nathanscode.com/assignment2/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; 
			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;
			let pImg = document.getElementById("personImage");
			let hImg = document.getElementById("houseImage");
			let hintLines = 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
				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 rectangles ...
				ctx.lineWidth = 1;
				ctx.save();
				ctx.setTransform(view.scl,0,0,-view.scl,view.x+0.5,h-view.y-0.5);
				ctx.strokeStyle = "#555";
				ctx.fillStyle = "#555";
				noHintLinesF()
				ctx.beginPath();
				ctx.arc(60, 20, 3, 0, 2 * Math.PI, false);
				ctx.closePath();
				ctx.fill();
				ctx.beginPath();
				ctx.arc(-40, -160, 3, 0, 2 * Math.PI, false);
				ctx.closePath();
				ctx.fill();
				ctx.beginPath();
				ctx.arc(200, 160, 3, 0, 2 * Math.PI, false);
				ctx.closePath();
				ctx.fill();
				ctx.lineWidth = 1;
				ctx.stroke();
				ctx.save();
				ctx.rotate(180*Math.PI/180);
				ctx.drawImage(personImage, -70, -85, 40,58.2 );
				ctx.drawImage(houseImage, -245, -205, 40,40);
				ctx.drawImage(houseImage, 40, 115, 40,40);
				ctx.restore();
				//draws the answers on the grid
				if (question1Answer == 1) {
					drawNumbers1();
				}
				if (question2Answer == 1) {
					drawNumbers2();
				}
				//Calls the dashed lines function
				if (document.getElementById("hintNumFormId").value == 2) {
					hintLinesF();
				}
				//Calls the functtion that draws the lengths of the dashed lines
				if (document.getElementById("hintNumFormId").value == 3) {
					hintLinesF();
					hintNumberzF();
				}
				//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;"
				}
			}
			//Draws the dashed lines
			function hintLinesF() {
				ctx.save();
				ctx.beginPath();
				ctx.setLineDash([5, 5]);
				ctx.moveTo(60,20);
				ctx.lineTo(200,20);
				ctx.lineTo(200,160);
				ctx.lineTo(60,20);
				ctx.stroke();
				ctx.beginPath();
				ctx.setLineDash([5, 5]);
				ctx.moveTo(60,20);
				ctx.lineTo(-40,20);
				ctx.lineTo(-40,-160);
				ctx.lineTo(60,20);
				ctx.stroke();
				ctx.restore();
			}
			//Draws the lengths of the dashed lines
			function hintNumberzF() {
				ctx.save();
				ctx.scale(1, -1);
				ctx.font = "20px Arial";
				ctx.fillText('7',120,-3);
				ctx.fillText('7',205,-100);
				ctx.fillText('5',10,-30);
				ctx.fillText('9',-60,40);
				ctx.restore();
			}
			//Draws the regular lines
			function noHintLinesF() {
				ctx.beginPath();
				ctx.moveTo(60,20);
				ctx.lineTo(200,160);
				ctx.stroke();
				ctx.beginPath();
				ctx.moveTo(60,20);
				ctx.lineTo(-40,-160);
				ctx.stroke();
			}
			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 1st 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 == '9.9' || trimAnswer == '9.90' || trimAnswer == '9.89') {
					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>";
				}
			};
			//checks if the 2nd answer is correct
			function checkAnswer2() { 
				let problemAnswer1 = document.getElementById('answer1').value;
				document.cookie = 'znumber2Answer='+ document.getElementById('answer1').value;
				let trimAnswer1 = problemAnswer1.replace(/ /g,'');
				if (trimAnswer1 == '10.29' || trimAnswer1 == '10.3' || trimAnswer1 == '10.30') {
					question2Answer = 1;
					document.getElementById("answerresults1").innerHTML = "<span class='alert alert-success'>Yay! Correct</span>";
				} else {
					document.getElementById("answerresults1").innerHTML = "<span class='alert alert-danger'>Oops! Try Again!</div>";
				}
			};
			//Draws the answers on the grid
			function drawNumbers1() {
				ctx.save();
				ctx.scale(1, -1);
				let problemAnswerCLet = readCookie('problemAnswerC');
				ctx.font = "20px Arial";
				ctx.fillText(problemAnswerCLet,100,-110);
				ctx.restore();
			}
			function drawNumbers2() {
				ctx.save();
				ctx.scale(1, -1);
				let problemAnswertCLet = readCookie('znumber2Answer');
				ctx.font = "20px Arial";
				ctx.fillText(problemAnswertCLet,25,65);
				ctx.restore();
			}
			//Reads cookies, yum
			function readCookie(name) {
				var nameEQ = name + "=";
				var ca = document.cookie.split(';');
				for(var i=0;i < ca.length;i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
					if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
				}
				return null;
			}
			//Displays hints when hint button is pressed
			function hintFunc() {
				let hintNum = document.getElementById("hintNumFormId").value
				if (hintNum == 0) {
					alert('Try using the distance formula to find the distance between the pizza man and one of the houses')
					document.getElementById("hintNumFormId").value = "1";
				}
				if (hintNum == 1) {
					alert('Rememer, on a triangle, If you sqare both legs and add them together, you get the squared hypotenuse')
					document.getElementById("hintNumFormId").value = "2";
				}
				if (hintNum == 2) {
					alert('Square both legs of the triangle, add them together, and take the square root of the sum. This should be the distance the pizza man is from the house')
					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')
				}
			}
		//A lot less nothing this time!!!
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console