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.
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/latest/easing/EasePack.min.js"></script>
<div id="webgl_canvas"></div>
body {
overflow:hidden;
margin:0;
background-color:#221f26;
}
// Animation with code #9 by Oleg Pashkovsky
// more animations on pshkvsky.com
window.addEventListener("load", function () {
var r=3;
var s_r=r/20+Math.sin(0)*r/20;
var num_of_corners=0;
var obj_resolution=360;
var _w=window.innerWidth;
var _h=window.innerHeight;
var aspect = _w/ _h;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 65, _w/_h, 0.1, 1000 );
camera.position.z = 10;
var renderer = new THREE.WebGLRenderer({ antialias: true } );
renderer.setClearColor(new THREE.Color(0x221f26, 1.0));
renderer.setSize( _w, _h );
document.getElementById("webgl_canvas").appendChild( renderer.domElement );
var group = new THREE.Object3D();
var sub_group = new THREE.Object3D();
var all_vertices=[];
var all_sub_vertices=[];
var objects=[];
var sub_objects=[];
var num=7;
var dstnc=0.4;
var border=0.04;
// generate bottom layer of mesh
for(var i=0;i<num;i++){
var obj=create_mesh(0x66b8c6,1,all_vertices);
objects.push(obj);
sub_group .add(obj);
obj.position.y=-(-num/2*dstnc+ dstnc*i);
obj.position.z=-(-num/2*dstnc+ dstnc*i+0.1);
obj.rotation.y =Math.PI/180*180;
}
// generate top layer of mesh
for(var i=0;i<num;i++){
var obj=create_mesh(0x221f26,1-border,all_sub_vertices);
sub_objects.push(obj);
group .add(obj);
obj.position.y=-(-num/2*dstnc+ dstnc*i);
obj.rotation.y =Math.PI/180*180;
obj.position.z=-(-num/2*dstnc+ dstnc*i);
}
group.rotation.x = sub_group.rotation.x = Math.PI/180*340;
scene.add(group);
scene.add(sub_group);
function create_mesh(clr,r_coof,ver_arr){
var geometry = new THREE.BufferGeometry();
var points=generate_points(r,s_r,5);
var vertices = give_me_vertices(points);
ver_arr.push(vertices);
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
var material = new THREE.MeshBasicMaterial( { color: clr } );
var mesh = new THREE.Mesh( geometry, material );
mesh.anim_shape=5;
mesh.anim=-1;
mesh.r_coof=r_coof;
return mesh;
}
function generate_points(r,s_r,anim_shape){
var points=[];
for (var i = 0; i <= obj_resolution; i++) {
var angle=Math.PI/180*i;
var addx=0;
var addy=0;
addx=s_r*Math.sin(angle*anim_shape);
addy=s_r*Math.sin(angle*anim_shape);
var x = (r+addx) * Math.cos(angle);
var y = (r+addy) * Math.sin(angle);
var z=0;
points.push([x,y,z]);
}
return points;
}
function give_me_vertices(points){
var vertexPositions=[];
var center_point=[0,0,0];
for (var i = 0; i < points.length-1; i++) {
vertexPositions.push(points[i],center_point,points[i+1]);
}
vertexPositions.push(points[ points.length-1],center_point,points[0]);
vertexPositions.push(points[1],center_point,points[2]);
vertices = new Float32Array( vertexPositions.length * 3 );
for ( var i = 0; i < vertexPositions.length; i++ )
{
vertices[ i*3 + 0 ] = vertexPositions[i][0];
vertices[ i*3 + 1 ] = vertexPositions[i][1];
vertices[ i*3 + 2 ] = vertexPositions[i][2];
}
return vertices;
}
function update_vertices(points,my_arr){
var vertexPositions=[];
var center_point=[0,0,0];
for (var i = 0; i < points.length-1; i++) {
vertexPositions.push(points[i],center_point,points[i+1]);
}
vertexPositions.push(points[ points.length-1],center_point,points[0]);
vertexPositions.push(points[1],center_point,points[2]);
for ( var i = 0; i < vertexPositions.length; i++ ){
my_arr[ i*3 + 0 ] = vertexPositions[i][0];
my_arr[ i*3 + 1 ] = vertexPositions[i][1];
my_arr[ i*3 + 2 ] = vertexPositions[i][2];
}
}
var last_anim=false;
var delay_time=0.3;
var anim_time=2.12;
var rot_angle=90;
function tween(){
num_of_corners++;
if(num_of_corners>10) num_of_corners=3;
num_of_corners=Math.floor(Math.random()*9)+3;
for (var k = objects.length-1; k >= 0; k--) {
var prev_rot=Math.PI/180*(rot_angle+(k));
var new_rot=prev_rot+Math.PI/180*(rot_angle);
var l_delay=delay_time*(k);
anim_delay(l_delay,k,prev_rot,new_rot);
}
setTimeout(tween,anim_time*1000);
function anim_delay(l_delay,k,prev_rot,new_rot){
setTimeout(re_anim,l_delay*1000);
function re_anim(){
objects[k].anim_shape=num_of_corners;
sub_objects[k].anim_shape=num_of_corners;
TweenMax.fromTo(objects[k].rotation,anim_time*2,{z:prev_rot},{ease:Sine.EaseInOut,z:new_rot});
TweenMax.fromTo(objects[k],anim_time/2,{anim:-1},{ease:Sine.EaseOut,anim:1,onCompleteParams:[objects[k]],onComplete:tweenBack});
TweenMax.fromTo(sub_objects[k].rotation,anim_time*2,{z:prev_rot},{ease:Sine.EaseInOut,z:new_rot});
TweenMax.fromTo(sub_objects[k],anim_time/2,{anim:-1},{ease:Sine.EaseOut,anim:1,onCompleteParams:[sub_objects[k]],onComplete:tweenBack});
}
}
function tweenBack(obj){
TweenMax.fromTo(obj,anim_time/2,{anim:1},{ease:Sine.EaseIn,anim:-1});
}
}
var counter=0;
var loop = function loop() {
requestAnimationFrame(loop);
for (var k = 0; k < objects.length; k++) {
var time=(counter+k)/60;
var time_sin=Math.sin(time*4);
var obj=objects[k];
var rad=r*obj.r_coof;
s_r=rad/15+obj.anim*rad/15;
var points=generate_points(rad,s_r,obj.anim_shape);
update_vertices(points, all_vertices[k]);
obj.geometry.attributes.position.needsUpdate = true;
obj=sub_objects[k];
rad=r*obj.r_coof;
s_r=rad/15+obj.anim*rad/15;
var points=generate_points(rad,s_r,obj.anim_shape);
update_vertices(points,all_sub_vertices[k]);
obj.geometry.attributes.position.needsUpdate = true;
}
renderer.render(scene, camera);
counter++;
};
loop();
tween();
}, false);
Also see: Tab Triggers