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.
<head>
<script id="shader-vertex-custoline" type="x-shader/x-vertex">
uniform float time;
varying vec3 vNormal;
uniform float normalRatioRange;
uniform float zoom;
varying float positionX;
varying float vari;
varying float timevariance;
varying float positionZ;
void main() {
timevariance = 1000.0;
vari = 2000.0;
float id;
vNormal = normal;
positionX = position.x;
positionZ = position.z;
vec3 newpos = vec3(position.x, position.y , position.z );
gl_Position = projectionMatrix * modelViewMatrix * vec4( normal * normalRatioRange + newpos, zoom);
}
</script>
<script id="shader-fragment-custoline" type="x-shader/x-fragment">
varying vec3 vNormal;
uniform float time;
varying float positionX;
varying float vari;
varying float timevariance;
varying float baseColor;
uniform float alpha;
void main() {
float timeVary = time - 2.0;
if(positionX < timeVary*timevariance -vari*4.0){
gl_FragColor = vec4(0.0,
0.0,
0.0,
0.0);
}
else if(positionX < timeVary*timevariance -vari*3.0){
gl_FragColor = vec4(0.5,
0.5,
0.5,
0.2);
}
else if(positionX < timeVary*timevariance -vari){
if(vNormal.x > 0.8){
gl_FragColor = vec4(1.0,
0.5,
0.0,
alpha);
}
else if(vNormal.y > 0.7){
gl_FragColor = vec4(1.0,
0.3,
0.0,
alpha);
}
else if(vNormal.z > 0.8){
gl_FragColor = vec4(1.0,
0.7,
0.0,
alpha);
}
else {
gl_FragColor = vec4(0.15,
0.15,
0.15,
0.7);
}
}
else if(positionX < timeVary*timevariance){
gl_FragColor = vec4(1.0,
1.0,
1.0,
0.2);
}
else{
gl_FragColor = vec4(0.0,
0.0,
0.0,
0.0);
}
}
</script>
<script id="shader-fragment-custoline2" type="x-shader/x-fragment">
varying vec3 vNormal;
uniform float time;
varying float positionX;
varying float vari;
varying float timevariance;
uniform float alpha;
void main() {
float timeVary = time - 2.0;
if(positionX < timeVary*timevariance -vari*4.0){
gl_FragColor = vec4(0.5,
0.5,
0.5,
0.0);
}
else if(positionX < timeVary*timevariance -vari*3.0){
gl_FragColor = vec4(0.7,
0.7,
0.7,
0.2);
}
else if(positionX < timeVary*timevariance -vari){
if(vNormal.x > 0.8){
gl_FragColor = vec4(0.5,
0.7,
0.0,
alpha);
}
else if(vNormal.y > 0.7){
gl_FragColor = vec4(0.3,
0.7,
0.0,
alpha);
}
else if(vNormal.z > 0.8){
gl_FragColor = vec4(0.7,
0.7,
0.0,
alpha);
}
else {
gl_FragColor = vec4(0.15,
0.15,
0.15,
0.7);
}
}
else if(positionX < timeVary*timevariance){
gl_FragColor = vec4(1.0,
1.0,
1.0,
0.2);
}
else{
gl_FragColor = vec4(1.0,
1.0,
1.0,
0.0);
}
}
</script>
<script id="shader-fragment-custoline3" type="x-shader/x-fragment">
varying vec3 vNormal;
uniform float time;
varying float positionX;
varying float vari;
varying float timevariance;
uniform float alpha;
void main() {
float timeVary = time - 2.0;
if(positionX < timeVary*timevariance -vari*4.0){
gl_FragColor = vec4(0.5, 0.5,0.5, 0.0);
}
else if(positionX < timeVary*timevariance -vari*3.0){
gl_FragColor = vec4(0.7,0.7,0.7,0.2);
}
else if(positionX < timeVary*timevariance -vari){
if(vNormal.x > 0.8){
gl_FragColor = vec4(0.5,0.0,0.7,alpha);
}
else if(vNormal.y > 0.7){
gl_FragColor = vec4(0.3,0.0,0.6,alpha);
}
else if(vNormal.z > 0.8){
gl_FragColor = vec4(0.6,0.0,0.6, alpha);
}
else {
gl_FragColor = vec4(0.15,0.15,0.15,0.7);
}
}
else if(positionX < timeVary*timevariance){
gl_FragColor = vec4(1.0,1.0,1.0,0.2);
}
else{
gl_FragColor = vec4(0.0,0.0,0.0,0.0);
}
}
</script>
</head>
<body>
<div id='container'>
</div>
<img class="icons" id="linkedin" src="http://experiments.crma.ninja/repos/samuel-honigstein/images/linkedin.png">
<img class="icons" id="facebook" src="http://experiments.crma.ninja/repos/samuel-honigstein/images/facebook.png">
<img class="icons" id="twitter" src="http://experiments.crma.ninja/repos/samuel-honigstein/images/twitter.png">
<img class="icons" id="plus" src="http://experiments.crma.ninja/repos/samuel-honigstein/images/plus.png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r69/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.js"></script>
<script type="text/javascript">
</script>
</body>
</html>
html {
height: 100%;
overflow: hidden;
}
body {
height: 100%;
overflow: hidden;
background-color: black;
font-family: 'gotham', sans-serif;
}
.icons {
position: absolute;
width: 40px;
height: 40px;
bottom: 90px;
cursor: pointer;
z-index: 3000;
}
#facebook {
right: 60px;
}
#twitter {
right: 120px;
}
#linkedin {
right: 180px;
}
#plus {
right: 240px;
}
#container {
width: 100%;
height: 100%;
}
#container canvas {
background-color: white;
}
class window.App
container : null
stats : null
camera : null
scene : null
renderer : null
windowHalfX : null
windowHalfY : null
mesh : null
clock : null
uniforms : {}
buffer : null
positionBuff1 : []
positionBuff2 : []
positionBuff3 : []
extrudeSettings : null
geometry : null
shape : null
isBuild1 : false
isBuild2 : false
rd : 0
randomPoints : []
count : 0
inBuild : 0
composer : null
meshes : []
gui : null
cameraLookatVector : null
optionsLine : {
normalRatioRange : 10.0,
zoom : 1,
baseColor : 0.8,
alpha : 1.0
}
constructor: ->
@container = document.getElementById('container')
@windowHalfX = window.innerWidth / 2;
@windowHalfY = window.innerHeight / 2;
@camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 1, 2000 );
@camera.position.z = 450;
@scene = new THREE.Scene();
# @ambient = new THREE.AmbientLight( 0xff0000 );
# @scene.add( @ambient );
@renderer = new THREE.WebGLRenderer({antialias : true});
@renderer.setSize( window.innerWidth, window.innerHeight );
@container.appendChild( @renderer.domElement );
window.addEventListener( 'resize', @onWindowResize, false );
@cameraLookatVector = new THREE.Vector3( 0, 0, -300 )
@uniformsline =
normalRatioRange:
type: "f"
value: @optionsLine.normalRatioRange
zoom:
type: "f"
value: @optionsLine.zoom
time:
type: "f"
value: 0.0
alpha:
type: "f"
value: 0.85
baseColor:
type: "c"
value: new THREE.Color(@optionsLine.baseColor)
@uniformsline2 =
normalRatioRange:
type: "f"
value: @optionsLine.normalRatioRange
zoom:
type: "f"
value: @optionsLine.zoom
time:
type: "f"
value: 0.0
alpha:
type: "f"
value: 0.85
baseColor:
type: "c"
value: new THREE.Color(@optionsLine.baseColor)
@uniformsline3 =
normalRatioRange:
type: "f"
value: @optionsLine.normalRatioRange
zoom:
type: "f"
value: @optionsLine.zoom
time:
type: "f"
value: 0.0
alpha:
type: "f"
value: 0.85
baseColor:
type: "c"
value: new THREE.Color(@optionsLine.baseColor)
@clock1 = new THREE.Clock(false)
@clock2 = new THREE.Clock(false)
@clock3 = new THREE.Clock(false)
fb = document.getElementById('facebook');
twt = document.getElementById('twitter');
lin = document.getElementById('linkedin');
plus = document.getElementById('plus');
fb.addEventListener('click', ()=>
window.open("https://www.facebook.com/Pierre.de.miel", '_blank');
, false)
twt.addEventListener('click', ()=>
window.open("https://twitter.com/Samsyyyy", '_blank');
, false)
lin.addEventListener('click', ()=>
window.open("https://www.linkedin.com/profile/view?id=182449324&trk=nav_responsive_tab_profile", '_blank');
, false)
plus.addEventListener('click', ()=>
window.open("http://experiments.crma.ninja/repos/samuel-honigstein/", '_blank');
, false)
@initGUI()
window.addEventListener( 'resize', @onWindowResize, false );
window.addEventListener( 'mousemove', @onDocumentMouseMove, false );
@buildPlanes()
@buildPlanes()
setInterval( ()=>
@removeAndReAdd()
,12500)
######
@animate()
onCLick:(e) =>
if @count == 0
###@scene.remove(@plane_mesh)###
### @isBuild = false###
@randomPoints = []
@randomPoints.push( new THREE.Vector3( -2000, THREE.Math.randFloat( -800, 800 ),0) );
ratio = 90
if(@count%2 == 0)
@rd = THREE.Math.randFloat( -ratio*4, ratio*5 )
else
@rd = 0
wdby2 = window.innerWidth / 2
hdby2 = window.innerHeight / 2
@randomPoints.push( new THREE.Vector3( e.clientX - wdby2, window.innerHeight - e.clientY - hdby2, @rd ) );
@count++
if @count > 3
@randomPoints.push( new THREE.Vector3( 2000, THREE.Math.randFloat( -800, 800 ), 0 ))
@buildPlanes()
initPostProcessing:()=>
renderModel = new THREE.RenderPass(@scene, @camera);
copyPass = new THREE.ShaderPass(THREE.CopyShader);
composer = new THREE.EffectComposer(@renderer);
composer.addPass(renderModel);
composer.addPass(copyPass);
copyPass.renderToScreen = true;
@toggleEffects();
toggleEffects:()=>
@composer = new THREE.EffectComposer(@renderer);
@composer.addPass(new THREE.RenderPass(@scene, @camera));
effectFXAA = new THREE.ShaderPass(THREE.FXAAShader);
width = window.innerWidth || 2;
height = window.innerHeight || 2;
effectFXAA.uniforms['resolution'].value.set(1 / width, 1 / height);
@composer.addPass(effectFXAA);
effectFilm = new THREE.FilmPass(0.1, 0.125, 2048, false);
@composer.addPass(effectFilm);
effectBloom = new THREE.BloomPass(.8);
@composer.addPass(effectBloom);
vignettePass = new THREE.ShaderPass(THREE.VignetteShader);
vignettePass.uniforms["darkness"].value = 1.1;
vignettePass.uniforms["offset"].value = 1;
vignettePass.renderToScreen = true;
@composer.addPass(vignettePass);
initGUI: =>
@gui = new dat.GUI();
@gui.values = {}
@gui.values.normalRatioRange = @gui.add(@optionsLine,'normalRatioRange',-10,50).step(0.5);
@gui.values.normalRatioRange.onChange (value) =>
@uniformsline.normalRatioRange.value = value
@uniformsline2.normalRatioRange.value = value
@uniformsline3.normalRatioRange.value = value
buildPlanes:()=>
id = @inBuild % 3
@inBuild++
if id == 0
ratio = 8
else ratio = 6
@shape = new THREE.Shape();
@shape.moveTo(10 * ratio, ratio * 0);
@shape.lineTo(12.5 * ratio, ratio * 2.5);
@shape.lineTo(12.5 * ratio, ratio * 5);
@shape.lineTo(10 * ratio, ratio * 7.5);
@shape.lineTo(7.5 * ratio, ratio * 7.5);
@shape.lineTo(5 * ratio, ratio * 5);
@shape.lineTo(5 * ratio, ratio * 2.5);
@shape.lineTo(7.5 * ratio, ratio * 0);
@shape.lineTo(10 * ratio, ratio * 0);
@randomPoints = []
range = 5
ratio = 90
wdby2 = window.innerWidth / 2
hdby2 = window.innerHeight / 2
@randomPoints.push( new THREE.Vector3( -2000, THREE.Math.randFloat( -800, 800 ),0) );
i = 0
rd = 0
count = 5
while i < count
if(i%2 == 0)
@rd = THREE.Math.randFloat( 0, ratio*6 )
else
@rd = 0
@randomPoints.push( new THREE.Vector3(THREE.Math.randFloat( (window.innerWidth / count) * i, (window.innerWidth / count) *i+1 ) - wdby2 , window.innerHeight - THREE.Math.randFloat( 0, window.innerHeight ) - hdby2, @rd ) );
i++
@randomPoints.push( new THREE.Vector3( 2000, THREE.Math.randFloat( -800, 800 ), 0 ))
randomSpline = new THREE.SplineCurve3( @randomPoints );
@extrudeSettings = {
steps : 800,
bevelEnabled : true,
extrudePath : randomSpline,
bevelThickness : 20,
bevelSize : 20,
bevelSegments : 20
};
@groundMaterial = new THREE.MeshLambertMaterial( {shading: THREE.FlatShading , ambient: 0xffffff, color: 0xff0000, specular: 0x050505, transparent : true, opacity : 0.8 } )
geometry = new THREE.ExtrudeGeometry( @shape, @extrudeSettings );
@buffer = new THREE.BufferGeometry();
@buffer.fromGeometry(geometry)
if id == 0
@clock1 = new THREE.Clock(true)
@plane_material1 = new THREE.ShaderMaterial({
vertexShader : document.getElementById('shader-vertex-custoline').textContent,
fragmentShader : document.getElementById('shader-fragment-custoline').textContent,
transparent : true,
uniforms : @uniformsline,
side : THREE.DoubleSide
});
@materials = [
@groundMaterial,
@plane_material1
]
@isBuild1 = true
@positionBuff1 = @buffer.attributes.position
else if id == 1
@clock2 = new THREE.Clock(true)
@plane_material2 = new THREE.ShaderMaterial({
vertexShader : document.getElementById('shader-vertex-custoline').textContent,
fragmentShader : document.getElementById('shader-fragment-custoline2').textContent,
transparent : true,
uniforms : @uniformsline2,
side : THREE.DoubleSide
});
@materials = [
@groundMaterial,
@plane_material2
]
@isBuild2 = true
@positionBuff2 = @buffer.attributes.position
else
@clock3 = new THREE.Clock(true)
@plane_material3 = new THREE.ShaderMaterial({
vertexShader : document.getElementById('shader-vertex-custoline').textContent,
fragmentShader : document.getElementById('shader-fragment-custoline3').textContent,
transparent : true,
uniforms : @uniformsline3,
side : THREE.DoubleSide
});
@materials = [
@groundMaterial,
@plane_material3
]
@isBuild3 = true
@positionBuff3 = @buffer.attributes.position
@plane_mesh = THREE.SceneUtils.createMultiMaterialObject( @buffer, @materials );
@meshes.push(@plane_mesh)
@scene.add( @plane_mesh );
ChangeAnim:()=>
lght = 45
first = @positionBuff1.array.subarray(lght, @positionBuff1.length);
second = @positionBuff1.array.subarray(0, lght);
@positionBuff1.array = @Float32Concat(first,second);
###@plane_mesh.children[1].geometry.computeBoundingBox();###
ChangeAnim2:()=>
lght = 45
first = @positionBuff2.array.subarray(lght, @positionBuff2.length);
second = @positionBuff2.array.subarray(0, lght);
@positionBuff2.array = @Float32Concat(first,second);
###@plane_mesh.children[1].geometry.computeBoundingBox();###
ChangeAnim3:()=>
lght = 45
first = @positionBuff3.array.subarray(lght, @positionBuff3.length);
second = @positionBuff3.array.subarray(0, lght);
@positionBuff3.array = @Float32Concat(first,second);
###@plane_mesh.children[1].geometry.computeBoundingBox();###
Float32Concat:(first,second)=>
firstLength = first.length
result = new Float32Array(firstLength + second.length);
result.set(first);
result.set(second, firstLength);
return result;
removeAndReAdd:()=>
@scene.remove(@meshes[0])
@scene.remove(@meshes[1])
@meshes = []
@isBuild3 = false
@isBuild2 = false
@isBuild1 = false
@buildPlanes()
setTimeout( ()=>
@buildPlanes()
,500)
onDocumentMouseMove:(event)=>
event.preventDefault();
@camera.position.x = ( event.clientX / window.innerWidth ) * 700 - 350;
@camera.position.y = - ( event.clientY / window.innerHeight ) * 700 + 350;
animate: =>
requestAnimationFrame( @animate );
if @isBuild1
@.plane_material1.uniforms['time'].value = @clock1.getElapsedTime();
@ChangeAnim()
if @isBuild2
@.plane_material2.uniforms['time'].value = @clock2.getElapsedTime();
@ChangeAnim2()
if @isBuild3
@.plane_material3.uniforms['time'].value = @clock3.getElapsedTime();
@ChangeAnim3()
# @.groundMaterial.uniforms['time'].value = @clock.getElapsedTime();
# @mesh.rotation.x += 0.005;
# @mesh.rotation.y += 0.01;
if @meshes[0]
@meshes[0].children[1].geometry.attributes.position.needsUpdate = true;
if @meshes[1]
@meshes[1].children[1].geometry.attributes.position.needsUpdate = true;
@renderer.setClearColor(0x000000, 1);
@renderer.render( @scene, @camera );
@camera.lookAt(@cameraLookatVector);
onWindowResize:=>
@camera.aspect = window.innerWidth / window.innerHeight;
@camera.updateProjectionMatrix();
@renderer.setSize( window.innerWidth, window.innerHeight );
App = new window.App();
App.init();
Also see: Tab Triggers