HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- 5 meters per pixel (median) -->
<!-- 1 meters per pixel zoomed in -->
<!-- 10 meters per pixel zoomed out -->
<div class="flex-layout-vertical">
<div class="top">
<input type="range" id="zoom" min="0" max="1" value="0.5" step="0.00001">
<p>use the arrow keys to fake movement</p>
</div>
<svg viewbox="0 0 320 320">
<g class="map" transform="translate(160,300)">
<rect width="80" height="80" fill="yellow" stroke="red"/>
</g>
<g class="guides" transform=" translate(160,300) rotate(0)">
<polygon class="you" points="0,-8, 7,4.5, -7,4.5"/>
<g class="pointer">
<polygon class="arrow" id="angleBro" points="0,-48, 4,-24.5, 0, -26, -4,-24.5" transform="rotate(90)"/>
</g>
<g class="proximity">
<g data-range="1600">
<circle r="320"/>
<text y="-320" dy="-6">1600m</text>
</g>
<g data-range="800">
<circle r="160"/>
<text y="-160" dy="-5">800m</text>
</g>
<g data-range="400">
<circle r="80"/>
<text y="-80" dy="-4">400m</text>
</g>
<g data-range="200">
<circle r="40"/>
<text y="-40" dy="-3">200m</text>
</g>
<g data-range="100">
<circle r="20"/>
<text y="-20" dy="-2">100m</text>
</g>
<g data-range="50">
<circle r="10"/>
</g>
<!-- <circle r="2.5"/> -->
</g>
</g>
</svg>
</div>
html,
body{
width:100%;
height:100%;
margin:0;
border:0;
}
.top{
background-color:tan;
}
input[type="range"]{
width:50%;
}
.guides circle,
.guides .you{
stroke-width:1px;
stroke:#000;
fill:none;
}
.guides .arrow{
fill:red;
stroke:none;
}
.guides circle{
stroke-dash-array: 1 1;
}
.guides text{
text-anchor:middle;
font-family:Helvetica;
font-size:8px;
}
.map circle{
fill:red;
}
.flex-layout-vertical{
height:100%;
display:flex;
flex-direction:column;
align-items:stretch;
/* justify-content:space-around;
*/
}
.flex-layout-vertical > *{
flex-grow:1;
}
svg{
width:100%;
height:100%;
}
/**
5 meters per pixel median
(1m/px zoomed in)
(10m/px zoomed out)
* Viewbox
Width = 320px = 1600m
* Center Points
center = 160px = 800m
* Center of Rings
x = 160px = 800m
y = 300px = 1500m
* Coordinates
lat N, long E format
Latitude is N<-->S
Longitude is E<-->W
*/
var metersPerLatitude = 110950; // meters (N<->S)
var metersPerLongitude = 91288; // meters (E<->W)
var metersPerPixel = 5;
// var metersPerPixel = 1;
var walkingSpeed = 1.1; //meters per second
// var walkingSpeed = 1; //meters per second
var uiOffsetX = 160;
var uiOffsetY = 300;
currentPosition = {
latitude: 34.009742226228035,
longitude: -81.0104458417316
};
targetPosition = {
latitude:34.01,
longitude:-81.01
}
mapOffset = {
latitude:34,
longitude:-81
}
///// place dots on the map
var XMLNS = 'http://www.w3.org/2000/svg';
var dot = document.createElementNS(XMLNS,'circle');
document.querySelector('.map').appendChild(dot);
function placeDot(){
dot.setAttributeNS(null, 'r', 5);
dot.setAttributeNS(null, 'cy', -(targetPosition.latitude - mapOffset.latitude) * metersPerLatitude / metersPerPixel );
dot.setAttributeNS(null, 'cx', (targetPosition.longitude - mapOffset.longitude) * metersPerLongitude / metersPerPixel );
}
placeDot();
var zoom = 1;
var metersPerPixel = 5;
function repaint(){
console.clear();
console.log(currentPosition);
var map = document.querySelector('.map');
var y = (currentPosition.latitude - mapOffset.latitude) * metersPerLatitude / metersPerPixel + uiOffsetY;
var x = -(currentPosition.longitude - mapOffset.longitude) * metersPerLongitude / metersPerPixel + uiOffsetX;
map.setAttributeNS(null,'transform','translate('+x+','+y+')');
// var prox = document.querySelectorAll('.proximity > g');
// for(var i=0; i<prox.length; i++){
// var toX = i * 100000 * (targetPosition.longitude - currentPosition.longitude);
// var toY = i * 100000 * -(targetPosition.latitude - currentPosition.latitude);
// prox[i].setAttributeNS(null,'transform','translate('+toX+','+toY+')');
// }
var angle = 360 - Math.atan2(
(targetPosition.latitude-currentPosition.latitude)*metersPerLatitude,
(targetPosition.longitude-currentPosition.longitude)*metersPerLongitude
) / ( Math.PI * 2) * 360 + 90;
console.log(angle,'degrees to the target');
document.getElementById('angleBro').setAttributeNS(null,'transform','rotate('+angle+')');
placeDot();
}
repaint();
// catch keyboard
window.addEventListener('keydown',function(event){
switch(event.keyCode){
case 38: // up
currentPosition.latitude += walkingSpeed / metersPerLatitude;
break;
case 40: // down
currentPosition.latitude -= walkingSpeed / metersPerLatitude;
break;
case 39: // right
currentPosition.longitude += walkingSpeed / metersPerLongitude;
break;
case 37: // left
currentPosition.longitude -= walkingSpeed / metersPerLongitude;
break;
}
repaint();
});
//catch zooming
var zoomEl = document.getElementById('zoom');
var proxGuides = document.querySelectorAll('.proximity > *');
zoomEl.addEventListener('input',function(event){
metersPerPixel = 10 - 9.9 * Math.pow(event.target.value,0.1) + 0.1;
repaint();
console.log(metersPerPixel,'meters per pixel');
});
//// GPS
var GPS = {
coords:{
latitude:34.000,
longitude:-81.000000
}
};
GPS.activated = false;
GPS.updatePosition = function(position){
GPS.position = position;
// console.log('GPS position',position);
};
GPS.handleError = function(error) {
console.error("GPS error",error);
};
GPS.init = function(){
if(navigator.geolocation !== undefined) {
console.log('%cDevice Geolocation works','color:green');
navigator.geolocation.getCurrentPosition(this.updatePosition, this.handleError, { enableHighAccuracy:true });
navigator.geolocation.watchPosition(this.updatePosition, this.handleError, { enableHighAccuracy:true });
} else {
console.error('Device Geolocation unsupported');
}
};
Also see: Tab Triggers