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.
#app
#canvas_container
canvas
#gui
| Time: {{ timeLimit }}<br>
| Found: {{ score }} of {{ GHOSTS_COUNT }}<br>
#overlay(:class="inGame ? '' : 'shown'")
#info
h1
|Ghost Boo-sters!<br>
small|Use your mouse as a flashlight and find all the ghosts in the attic before the time runs out.
p
button(@click="startGame()")
|Start
#timeout(:class="gameOver ? 'shown' : ''")| {{message}}<br>
button(@click="restartGame()")
|Again?
.hidden-elements
img#wood(src="https://firebasestorage.googleapis.com/v0/b/portfolio-vue-2019.appspot.com/o/tmp%2Fwooden_floor.jpg?alt=media&token=11553a04-d041-42ed-97f8-1b1f147a92d7", alt="wood")
img#ghost(src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABgZJREFUeNrEWklIZUcUre/QOCPOOHQ7z9pNRxeO2AGnhRtBExcxi+wclskmZGGy0UTBAaOIICQ0SBbSCwccWnGjSAKK0t34EdFkIcQJB3C2cu/jPVO//qv//xu+Hrj6quq+W3X+q+HWrbIQ8xAH8gYkDyQNJB4kDMQfxAJyDnIAsgOyCfIXyALIP0YqpZSa0vjnID+AfECbOuWDbOOFXiJGyLwE+QPkzgABXu5kmy/1ELFoJBAB8jNIo9xdHhASEkIqKytJQUEBSUtLI/Hx8SQsLIz4+/sTi8VCzs/PycHBAdnZ2SGbm5tkeXmZTE9Pk6OjI7u2gfwG8h3Iv+7oWnUgx/wvWVhYSKFBVC/wXbSh8oWO5TpN61rPQH7lKyoqKqLr6+vULKAttKlCaEBugyE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YB28oQQQ7/R0kcxadw57ayskInJiYkF1tEGvcw9fX1qqs15pu1x5mZmWFtzyCRPiWjr6/PcAUdHR0OQ6Pt7e2mEMG2MnaRA/layWhoaDBkHNwVhx6t4tWinlE0Njaydr9x6jQa+JWEYsaXh0Xaxml06sZrQU1NjUtEUM8IuC2v1eWNlauIi4tziQjqGQG3sfqJJRLvaKvrKsBVcYkI6hkJdjva6joNPphJBDdNeuEs+ID4zFk46Km7lqvhIJsAHQbDtG5h3TnYtQTo7EKm6IpoQW9vr9um35aWFk0hUyIHiHUFsXGhwwXP7AUR26A1iK1gQO+xgtkuisqxwuCjHPQ4choxDKrFaVQ56Hmv9aBH9egN+6krR2/orvf390vuO061+B/TrrrxNzc3/JjQffT2pIehSNzMw1C2mw0+4fH0oBnH0099YaDenVc4fgH5ir/CgbEovMKBURUM9ClXOJTgHnuFw2q1kqWlJQK7PClP5QrH7yDfuusKh02I0o2Xal495u0g/prTRwMEPplxzclCzMNz+eJZvhxPVi6eKbMNe/HMCvKnfPHsbzMunv0nwADsn3+amrlVCAAAAABJRU5ErkJggg==", alt="ghost")
img#ghost_tagged(src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAByBJREFUeNrcWttvFGUU/+2yLW1h225rC1LcttibFiPUpIi+mIg+aeIj4h9g4oPGS7zEGCBeAEWNPpj4B4C+aaJPiIlPcoulTayl3UrLSomFXqCF3mE9v9l+49fZb6azs7vFeLLTnX5ndub8vnP5zjnfhFLID70K7IgB+8qBTjnqo0BVGVBSBERCwl8AlmaAuWlgYgq4JMfZSeD450B3Pp4fygXI68DOzcC79cCT9wCVQe4xBly/BPw8Chw6Cvy2pkDeBJ65HzjcDDzIe+RJqakE8MefwNsfAz8WFMgrQHMr8I0cjzilLyoqQlVVFSoqKlBWVoaSkhJrbN26dRb/9u3bWFxcxNzcHGZmZnDjxg1MT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ection {
background: transparent;
}
*:focus {
border: none;
background: none;
outline: none;
}
* {
outline: none;
}
body {
background: #1e1308;
color: #fff;
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
font-family: 'Permanent Marker', cursive;
font-size: 22px;
p {
width: 100%;
margin: 0;
line-height: 1;
}
canvas {
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
cursor: grab;
image-rendering: auto;
}
#overlay {
width: 100vw;
height: 100vh;
position: absolute;
z-index: 998;
top: 0;
left: 0;
display: none;
flex-wrap: wrap;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, .3);
transition: all ease-in-out .3s;
&.shown {
animation: fadeIn 1s;
display: flex;
}
}
#info {
text-align: center;
width: 100%;
max-width: 450px;
small {
// font-size: 50%;
line-height: 1;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}
}
h1 {
font-weight: 400;
margin: 0 0 10px;
line-height: 1;
}
#gui {
position: absolute;
top: 15%;
right: 5%;
z-index: 999;
text-align: right;
font-size: 24px;
pointer-events: none;
opacity: .6;
span {
font-size: 60px;
margin-left: 5px;
}
}
#timeout {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -55%) scale3d(1, 1, 1) rotate(-10deg);
transition: all 1s cubic-bezier(0.455, 0.03, 0.515, 0.955) 3s;
z-index: 999;
font-size: 5vw;
color: #fff;
background-color: rgba(0, 0, 0, .8);
padding: 20px 35px;
line-height: 1;
text-align: center;
display: none;
&.shown {
// opacity: 1;
transform: translate(-50%, -55%) scale3d(1.3, 1.3, 1) rotate(-1deg);
animation: fadeIn 1s;
display: block;
}
}
.hidden-elements {
display: none;
}
button {
border: none;
padding: 10px 30px;
margin-top: 20px;
font-family: 'Permanent Marker', cursive;
border-radius: 40px;
text-transform: uppercase;
cursor: pointer;
font-size: 30px;
background-color: $mainColor;
transition: all cubic-bezier(0.19, 1, 0.22, 1) .3s;
color: #fff;
&:hover,
&:focus {
background-color: darken($mainColor, 10%);
}
}
}
@media screen and (max-width: 990px) {
body {
font-size: 12px;
#info {
bottom: 25px;
left: 25px;
top: 20px;
}
#gui {
top: 20px;
}
h1 small {
display: none;
}
p:first-of-type {
margin-top: 0;
}
.range-slider {
bottom: 45px;
top: initial;
width: 100%;
right: 35px;
transform: translateY(0);
}
#timeout {
padding: 0px 12px;
}
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
/* I made this as a part of Codepen challenge using Vue.js, anime.js and illuminated. The attic and ghosts positions are randomly generated. Use your mouse or tap on the screen to light a section of the attic up. Click or tap the ghosts to bust them. Hope you enjoy it.💡 */
new Vue({
el: '#app',
data: {
gameOver: false,
message: 'Game Over',
position: {
x: 500,
y: 100
},
flashLightAngle: 0,
score: 0,
inGame: false,
timer: null,
timelineParameters: null,
timeLimit: 20,
PIXEL_SIZE_X: Math.floor(window.innerWidth / 50),
PIXEL_SIZE_Y: Math.floor(window.innerHeight / 20),
PIXEL_COUNT: Math.floor(window.innerWidth * window.innerHeight / 3000),
GHOSTS_COUNT: Math.floor(window.innerWidth * window.innerHeight / 55000),
GHOSTS_RADIUS: 14,
ghostsArr: [],
taggedGhostsArr: []
},
watch: {
score(val, newVal) {
if (val === this.GHOSTS_COUNT && !this.gameOver) {
this.gameOver = true
this.message = 'YOU WIN!'
clearInterval(this.timer)
}
},
timeLimit(val) {
if (val <= 0) {
clearInterval(this.timer)
this.gameOver = true
this.message = 'TIME OUT!'
}
}
},
methods: {
restartGame() {
this.timelineParameters.loop = false
this.timelineParameters.autoplay = false
this.timelineParameters.pause()
this.inGame = true;
this.gameOver = false;
this.ghostsArr = []
this.taggedGhostsArr = []
this.timeLimit = 20
this.score = 0
this.initGame()
this.timer = setInterval(() => {
this.timeLimit -= 1
}, 1000)
},
startGame() {
this.restartGame();
},
getRndInteger(axis, max) {
if (axis === 'x') {
return this.PIXEL_SIZE_X + this.PIXEL_SIZE_X * Math.floor(Math.random() * (max / this.PIXEL_SIZE_X))
} else {
return this.PIXEL_SIZE_Y + this.PIXEL_SIZE_Y * Math.floor(Math.random() * (max / this.PIXEL_SIZE_Y))
}
},
dist(a, b) {
return Math.abs(a - b)
},
initDemo() {
this.timelineParameters = anime.timeline({
direction: 'alternate',
loop: true
})
this.timelineParameters
.add({
targets: this.position,
x: [this.getRndInteger('x', window.innerWidth), this.getRndInteger('x', window.innerWidth), this.getRndInteger('x', window.innerWidth), this.getRndInteger('x', window.innerWidth)],
y: [this.getRndInteger('y', window.innerHeight), this.getRndInteger('y', window.innerHeight), this.getRndInteger('y', window.innerHeight), this.getRndInteger('y', window.innerHeight)],
duration: 10000,
easing: 'easeInOutQuad'
})
},
initGame() {
let _this = this
const Lamp = illuminated.Lamp,
RectangleObject = illuminated.RectangleObject,
DiscObject = illuminated.DiscObject,
Vec2 = illuminated.Vec2,
Lighting = illuminated.Lighting,
DarkMask = illuminated.DarkMask
const wood = document.getElementById("wood")
const ghost = document.getElementById("ghost")
const ghost_tagged = document.getElementById("ghost_tagged")
const canvas = document.querySelector("#canvas_container canvas")
canvas.width = window.innerWidth
canvas.height = window.innerHeight
const ctx = canvas.getContext("2d");
const light2 = new Lamp({
position: new Vec2(parseInt(_this.position.x), parseInt(_this.position.y)),
color: '#d66a00',
distance: 180,
radius: 5,
samples: 3,
// angle: _this.flashLightAngle,
// roughness: .9
})
if (_this.inGame) {
document.addEventListener('touchmove', (event) => {
event.preventDefault()
var touch = event.touches[0]
_this.position.x = touch.clientX
_this.position.y = touch.clientY
})
document.addEventListener('mousemove', (event) => {
_this.position.x = event.clientX
_this.position.y = event.clientY
})
}
var objArr = []
var maskArr = []
for (let x = 0; x <= _this.PIXEL_COUNT; x++) {
let randX = _this.getRndInteger('x', window.innerWidth - _this.PIXEL_SIZE_X)
let randY = _this.getRndInteger('y', window.innerHeight - _this.PIXEL_SIZE_Y)
maskArr.push({
x: randX,
y: randY
})
objArr.push(new RectangleObject({
topleft: new Vec2(randX, randY),
bottomright: new Vec2((randX + _this.PIXEL_SIZE_X), randY + _this.PIXEL_SIZE_Y)
}))
}
let randX, randY
for (let y = 0; y <= _this.GHOSTS_COUNT; y++) {
if (_this.ghostsArr.length < _this.GHOSTS_COUNT) {
do {
randX = _this.getRndInteger('x', window.innerWidth - _this.PIXEL_SIZE_X * 2)
randY = _this.getRndInteger('y', window.innerHeight - _this.PIXEL_SIZE_Y * 2)
} while (_this.ghostsArr.filter((e) => {
return e.center.x === randX && e.center.y === randY
}).length > 0 || maskArr.filter((e) => {
return e.x == randX && e.y == randY
}).length > 0 || maskArr.filter((e) => {
return e.x + _this.PIXEL_SIZE_X == randX && e.y + _this.PIXEL_SIZE_Y == randY
}).length > 0)
_this.ghostsArr.push(new DiscObject({
center: new Vec2(Math.floor(randX + _this.PIXEL_SIZE_X / 2), Math.floor(randY + _this.PIXEL_SIZE_Y / 2)),
radius: _this.GHOSTS_RADIUS
}))
_this.taggedGhostsArr.push(new DiscObject({
center: new Vec2(-100, -100),
radius: _this.GHOSTS_RADIUS
}))
}
}
const lighting2 = new Lighting({
light: light2,
objects: [..._this.ghostsArr, ...objArr]
})
const darkmask = new DarkMask({
lights: [light2],
color: 'rgba(0,0,0,1)'
})
if (!_this.inGame) {
_this.initDemo()
}
function render() {
light2.position = new Vec2(parseInt(_this.position.x), parseInt(_this.position.y))
light2.angle = parseInt(_this.flashLightAngle)
lighting2.compute(canvas.width, canvas.height)
darkmask.compute(canvas.width, canvas.height)
ctx.fillStyle = "#1e1308"
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.drawImage(wood, 0, 0, window.innerWidth, window.innerHeight)
for (let x = 0; x < _this.ghostsArr.length; x++) {
ctx.beginPath()
_this.ghostsArr[x].path(ctx)
if (_this.taggedGhostsArr[x].center.x === _this.ghostsArr[x].center.x && _this.taggedGhostsArr[x].center.y === _this.ghostsArr[x].center.y) {
ctx.drawImage(ghost_tagged, _this.ghostsArr[x].center.x - _this.GHOSTS_RADIUS, _this.ghostsArr[x].center.y - _this.GHOSTS_RADIUS, _this.GHOSTS_RADIUS * 2, _this.GHOSTS_RADIUS * 2)
} else {
ctx.drawImage(ghost, _this.ghostsArr[x].center.x - _this.GHOSTS_RADIUS, _this.ghostsArr[x].center.y - _this.GHOSTS_RADIUS, _this.GHOSTS_RADIUS * 2, _this.GHOSTS_RADIUS * 2)
}
}
ctx.globalCompositeOperation = "lighter"
lighting2.render(ctx)
ctx.globalCompositeOperation = "source-over"
darkmask.render(ctx)
for (let x = 0; x < objArr.length; x++) {
ctx.fillStyle = "#1e1308"
ctx.fillRect(maskArr[x].x, maskArr[x].y, _this.PIXEL_SIZE_X, _this.PIXEL_SIZE_Y)
}
ctx.fillStyle = "#1e1308"
ctx.fillRect(0, 0, window.innerWidth, 6)
ctx.fillRect(0, window.innerHeight - 6, window.innerWidth, 6)
ctx.fillRect(window.innerWidth - 6, 0, 6, window.innerHeight)
ctx.fillRect(0, 0, 6, window.innerHeight)
}
document.addEventListener('click', (e) => {
if (!_this.inGame || _this.gameOver) return false
for (let x = 0; x < _this.ghostsArr.length; x++) {
let distX = _this.dist(e.clientX, _this.ghostsArr[x].center.x)
let distY = _this.dist(e.clientY, _this.ghostsArr[x].center.y)
if (distX <= _this.GHOSTS_RADIUS - 2 && distY <= _this.GHOSTS_RADIUS - 2) {
if (_this.taggedGhostsArr[x].center.x !== _this.ghostsArr[x].center.x && _this.taggedGhostsArr[x].center.y !== _this.ghostsArr[x].center.y) {
_this.score += 1
}
_this.taggedGhostsArr[x].center.x = _this.ghostsArr[x].center.x
_this.taggedGhostsArr[x].center.y = _this.ghostsArr[x].center.y
}
}
})
requestAnimFrame(function loop() {
requestAnimFrame(loop, canvas)
render()
}, canvas)
}
},
mounted() {
this.initGame()
}
})
Also see: Tab Triggers