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.
<!-- Codepen -->
<div class="content">
<div class="title">
<h1>WORMS</h1>
<h3>FUTURISTIC<span>PARTICLES</span></h3>
</div>
</div>
<div class="more-pens">
<a target="_blank" href="https://codepen.io/plasm/" class="white-mode">VIEW OTHER PENS</a>
<a target="_blank" href="https://codepen.io/collection/nZpPbz/" class="white-mode">VIEW OTHER PARTICLES</a>
</div>
<!-- END Codepen -->
=transform($prop)
-webkit-transform: $prop
-moz-transform: $prop
-ms-transform: $prop
-o-transform: $prop
transform: $prop
@import url('https://fonts.googleapis.com/css?family=Catamaran:300,400,500,600,700')
.more-pens
position: fixed
right: 20px
bottom: 20px
z-index: 10
font-family: 'Catamaran', sans-serif
font-size: 12px
a.white-mode, a.white-mode:link, a.white-mode:visited, a.white-mode:active
font-family: 'Catamaran', sans-serif
font-size: 12px
text-decoration: none
background: #212121
padding: 8px 18px
color: #f7f7f7
border-radius: 20px
margin: 0 4px
&:hover
background: #edf3f8
color: #212121
body
margin: 0
padding: 0
overflow: hidden
width: 100%
height: 100%
background: #000000
.content
z-index: 10
position: absolute
left: 0
top: 0
padding: 0
text-align: center
width: 100vw
height: 100vh
.title
z-index: 10
position: absolute
left: 50%
top: 50%
transform: translateX(-50%) translateY(-50%)
font-family: "Montserrat"
text-align: center
width: 100%
h1
position: relative
color: #EEEEEE
font-weight: 800
font-size: 90px
padding: 0
margin: 0
line-height: 1
text-shadow: 0 0 30px #000155
h3
font-weight: 200
font-size: 30px
padding: 0
margin: 0
line-height: 1
color: #EEEEEE
letter-spacing: 2px
text-shadow: 0 0 30px #000155
span
font-weight: 700
class Particles{
static initClass() {
this.prototype.defaults = {
speed: 1.8,
radius: 25,
innerColor: "#444444",
outerColor: "#111111",
aroundColor: "#999999",
innerColorHero: "#CBF6FC",
outerColorHero: "#9CECFA",
aroundColorHero: "#9CECFA",
aroundme: false,
speedAroudme: 3,
offsetAroudme: 0,
hero: false,
onCreate: function(){},
onDead: function(){}
};
}
constructor(canvas, options){
Particles.initClass();
//
this.options = $.extend({}, this.defaults, options );
let timeout,
random,
startAngle,
progress,
direction,
currentRadius,
oldx,
oldy,
x,
y,
w,
h;
// Set default value
this.canvas = canvas;
this.timeout = false;
this.random = Math.random();
this.startAngle = this.random * 360;
this.w = 0;
this.h = 0;
this.progress = 0;
this.direction = 0;
this.currentRadius = 0;
if( this.options.hero )
this.options.offsetAroudme = 20
// Init dimensions
this.getWindowDimensions();
// Initial position
this.x = Math.floor(Math.random() * this.w);
this.y = Math.floor(Math.random() * this.h);
// init Behaviours
this.behaviours();
this.options.onCreate(this.options);
}
behaviours(){
// window.resize event listener
window.addEventListener('resize', function() {
this.getWindowDimensions()
}.bind(this));
}
render(){
// this.getWindowDimensions();
this.drawFirstParticle();
this.drawSecondParticleAroundMe();
this.nextPosition();
this.progress++;
}
drawFirstParticle(){
// Set current dimension radius
this.currentRadius = Math.min(this.progress/2, this.options.radius);
// GRADIENT
let grd = this.canvas.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.currentRadius);
if(this.options.hero == true){
grd.addColorStop(0, this.options.innerColorHero);
grd.addColorStop(1, this.options.outerColorHero);
}else{
grd.addColorStop(0, this.options.innerColor);
grd.addColorStop(1, this.options.outerColor);
}
// Draw first circle
this.canvas.beginPath();
this.canvas.arc(this.x, this.y, this.currentRadius, 0, 2 * Math.PI);
this.canvas.lineWidth = 1;
this.canvas.fillStyle = grd;
this.canvas.fill();
this.canvas.closePath();
return;
}
drawSecondParticleAroundMe(){
if( !this.options.aroundme ) return;
let color = this.options.hero == true ? this.options.aroundColorHero : this.options.aroundColor;;
let angle = (this.progress*this.options.speedAroudme + this.startAngle) * Math.PI / 180;
let x = this.x + Math.cos(angle)*(this.currentRadius-1 + this.options.offsetAroudme);
let y = this.y + Math.sin(angle)*(this.currentRadius-1 + this.options.offsetAroudme);
// this.canvas.beginPath();
// this.canvas.arc(x, y, 1, 0, 2 * Math.PI);
// this.canvas.lineWidth = 1;
// this.canvas.fillStyle = color;
// this.canvas.fill();
// this.canvas.closePath();
if(this.oldx){
this.canvas.beginPath();
this.canvas.moveTo(this.oldx, this.oldy);
this.canvas.lineTo(x, y);
this.canvas.strokeStyle = color;
this.canvas.lineWidth = 1;
this.canvas.stroke();
}
this.oldx = x;
this.oldy = y;
return;
}
nextPosition(){
this.x += Math.cos(this.direction ) * this.options.speed;
this.y += Math.sin(this.direction ) * this.options.speed;
this.direction += Math.random() * 0.7 - 0.32;
return;
}
move(){
this.render()
return this.isInBound();
}
isInBound(){
// console.log(this.w)
if(
this.x < -this.options.radius ||
this.x > this.w + this.options.radius ||
this.y < -this.options.radius ||
this.y > this.h + this.options.radius
){
this.options.onDead(this.options);
return false
}
return true
}
getWindowDimensions(){
this.w = window.innerWidth;
this.h = window.innerHeight;
}
}
var tela = document.createElement('canvas');
$("body").append(tela);
let canvas = tela.getContext('2d');
// ---------------------------
let config = {
maxParticles: 100,
maxHeros: 24,
speedAroudme: 3,
offsetAroudme: 1
}
let dimensions = {
width: 0,
height: 0
}
let heros = 0;
let data_particles =[];
function setWindowSize(){
dimensions.width = $(window).width();
dimensions.height = $(window).height();
tela.width = dimensions.width;
tela.height = dimensions.height;
}
function popolate(num){
for (var i = 0; i < num; i++) {
let isHero = false;
if(heros < config.maxHeros){
isHero = true;
}
data_particles.push(new Particles(canvas, {
speed: .8,
radius: Math.round(18 + (Math.random() * 40)),
aroundme: true,
hero: isHero,
speedAroudme: config.speedAroudme,
offsetAroudme: config.offsetAroudme,
onCreate: function(data){
if( data.hero == true )
heros++;
},
onDead: function(data){
if( data.hero == true )
heros--;
}
}))
}
return data_particles.length
}
function clear(){
canvas.globalAlpha = 0.018;
canvas.fillStyle = '#181719';
canvas.fillRect(0, 0, dimensions.width, dimensions.height);
canvas.globalAlpha = 1;
}
function update(){
clear();
data_particles = data_particles.filter(function(p) {
return p.move()
})
if(data_particles.length < config.maxParticles){
popolate(1)
}
requestAnimationFrame(update)
}
setWindowSize()
popolate(config.maxParticles)
update()
$(window).resize(setWindowSize)
Also see: Tab Triggers