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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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 id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
void main(void) {
gl_FragColor = vec4(0.4, 0.6, 0.8, .5);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 vertexPosition;
uniform mat4 modelViewMatrix;
uniform mat4 perspectiveMatrix;
void main(void) {
gl_Position = perspectiveMatrix * modelViewMatrix * vec4( vertexPosition, 1.0);
}
</script>
<canvas id="c"></canvas>
@import "compass/css3";
@import "compass/reset";
@import "compass/css3";
body{
overflow: hidden;
}
canvas{
width: 100%;
height: 100%;
}
window.onload = loadScene;
function backingScale(context) {
if ('devicePixelRatio' in window) {
if (window.devicePixelRatio > 1) {
return window.devicePixelRatio;
}
}
return 1;
}
var tempCanvas = document.createElement('canvas');
var tempCtx = tempCanvas.getContext('2d');
var scaleFactor = backingScale(tempCtx);
var canvas, gl,
ratio,
vertices,
velocities,
freqArr,
cw,
ch,
colorLoc,
thetaArr,
velThetaArr,
velRadArr,
boldRateArr,
drawType,
numLines = 80000;
var targetArr = [];
var randomTargetXArr = [], randomTargetYArr = [];
drawType = 2;
/**
* Initialises WebGL and creates the 3D scene.
*/
function Target(rad){
this.x = 0;
this.y = 0;
this.rotate = 0;
this.radius = 0;
this.baseRad = rad;
this.update();
};
Target.prototype = {
freqSpecial : 0.0,
update : function() {
this.rotate_speed = curObject.rotateSpeed + Math.random() * curObject.rotateSpeedRandom;//Math.random(1) * 0.2 + 0.001;
//this.friction = Math.random(1) * 0.8 + 0.1;
this.speed = Math.random(1) * curObject.speed + curObject.speed;
this.step = Math.random() * curObject.stepRandom + curObject.step;
this.freq = curObject.freq + curObject.freqRandom * Math.random() + this.freqSpecial;
this.bold_rate = this.baseRad * (curObject.boldRate + Math.random()*curObject.boldRandom) ;
//console.log(this.)
}
}
var curObject = {
rotateSpeed : 0.000,
rotateSpeedRandom: 0,
speed : 0.03,
speedRandom : 0.0,
step : 0,
stepRandom : 0.0,
freq : 0.01,
freqSpecial : 0.0,
freqRandom : 0.00,
boldRate : 1.0,
boldRandom :0,
update : function(){
onControllerChange(0);
}
};
var onControllerChange = function(value){
for(var ii = 0; ii < targetArr.length; ii++) {
targetArr[ii].update();
}
};
var incNum = 0.02;
var incSign = +1;
var count = 0;
function onChangeTimer(){
curObject.step += incNum * incSign * (count + 1);
curObject.freq += incNum * incSign * (count + 1);
onControllerChange(0);
//count = count + count + 1;
count++;
if(count < 4) setTimeout(onChangeTimer, 500);
else setTimeout(backTimer, 500);
}
circleCount = 1;
function backTimer(){
circleCount++;
if(circleCount > 8){
circleCount = 1;
targetArr = [];
var targetRad = 0.9;
var target = new Target(targetRad);
targetArr.push(target);
}else {
for (var ii = (circleCount - 1) * (circleCount - 1); ii < circleCount * circleCount; ii++) {
var targetRad = 0.9;
var target = new Target(targetRad);
targetArr.push(target);
}
var targetNumber = targetArr.length;
var kankaku = 2.0 / ( circleCount );
for (var xx = 0; xx < circleCount; xx++) {
for (var yy = 0; yy < circleCount; yy++) {
var num = xx + yy * circleCount;
targetArr[num].baseRad = .9 / circleCount;
targetArr[num].x = 1.0 - kankaku * (xx + .5);
targetArr[num].y = 1.0 - kankaku * (yy + .5);
targetArr[num].freqSpecial = (xx + yy) * 0.01;
}
}
}
count = 0;
curObject.step = 0.00; curObject.freq = 0.01;
onControllerChange(0);
setTimeout(onChangeTimer, 300);
}
/*
rotSpeedController.onChange(function(value) {
// Fires on every change, drag, keypress, etc.
console.log("change")
});
*/
function loadScene() {
// Get the canvas element
canvas = document.getElementById("c");
// Get the WebGL context
gl = canvas.getContext("experimental-webgl");
// Check whether the WebGL context is available or not
// if it's not available exit
if (!gl) {
alert("There's no WebGL context available.");
return;
}
// Set the viewport to the canvas width and height
cw = window.innerWidth;
ch = window.innerHeight;
canvas.width = cw;
canvas.height = ch;
gl.viewport(0, 0, canvas.width, canvas.height);
var vertexShaderScript = document.getElementById("shader-vs");
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, vertexShaderScript.text);
gl.compileShader(vertexShader);
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
alert("Couldn't compile the vertex shader");
gl.deleteShader(vertexShader);
return;
}
var fragmentShaderScript = document.getElementById("shader-fs");
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, fragmentShaderScript.text);
gl.compileShader(fragmentShader);
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
alert("Couldn't compile the fragment shader");
gl.deleteShader(fragmentShader);
return;
}
// Create a shader program.
gl.program = gl.createProgram();
gl.attachShader(gl.program, vertexShader);
gl.attachShader(gl.program, fragmentShader);
gl.linkProgram(gl.program);
if (!gl.getProgramParameter(gl.program, gl.LINK_STATUS)) {
alert("Unable to initialise shaders");
gl.deleteProgram(gl.program);
gl.deleteProgram(vertexShader);
gl.deleteProgram(fragmentShader);
return;
}
gl.useProgram(gl.program);
var vertexPosition = gl.getAttribLocation(gl.program, "vertexPosition");
gl.enableVertexAttribArray(vertexPosition);
gl.clearColor(0.1, 0.1, 0.12, 1.0);
gl.clearDepth(1.0);
gl.enable(gl.BLEND);
gl.disable(gl.DEPTH_TEST);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
// ------------------
setup();
// ------------------
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.DYNAMIC_DRAW);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// Define the viewing frustum parameters
// More info: http://en.wikipedia.org/wiki/Viewing_frustum
// More info: https://knol.google.com/k/view-frustum
var fieldOfView = 30.0;
var aspectRatio = canvas.width / canvas.height;
var nearPlane = 1.0;
var farPlane = 10000.0;
var top = nearPlane * Math.tan(fieldOfView * Math.PI / 360.0);
var bottom = -top;
var right = top * aspectRatio;
var left = -right;
// Create the perspective matrix. The OpenGL function that's normally used for this,
// glFrustum() is not included in the WebGL API. That's why we have to do it manually here.
// More info: http://www.cs.utk.edu/~vose/c-stuff/opengl/glFrustum.html
var a = (right + left) / (right - left);
var b = (top + bottom) / (top - bottom);
var c = (farPlane + nearPlane) / (farPlane - nearPlane);
var d = (2 * farPlane * nearPlane) / (farPlane - nearPlane);
var x = (2 * nearPlane) / (right - left);
var y = (2 * nearPlane) / (top - bottom);
var perspectiveMatrix = [
x, 0, a, 0,
0, y, b, 0,
0, 0, c, d,
0, 0, -1, 0
];
// Create the modelview matrix
// More info about the modelview matrix: http://3dengine.org/Modelview_matrix
// More info about the identity matrix: http://en.wikipedia.org/wiki/Identity_matrix
var modelViewMatrix = [
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
];
// Get the vertex position attribute location from the shader program
var vertexPosAttribLocation = gl.getAttribLocation(gl.program, "vertexPosition");
// Specify the location and format of the vertex position attribute
gl.vertexAttribPointer(vertexPosAttribLocation, 3.0, gl.FLOAT, false, 0, 0);
//gl.vertexAttribPointer(colorLoc, 4.0, gl.FLOAT, false, 0, 0);
// Get the location of the "modelViewMatrix" uniform variable from the
// shader program
var uModelViewMatrix = gl.getUniformLocation(gl.program, "modelViewMatrix");
// Get the location of the "perspectiveMatrix" uniform variable from the
// shader program
var uPerspectiveMatrix = gl.getUniformLocation(gl.program, "perspectiveMatrix");
// Set the values
gl.uniformMatrix4fv(uModelViewMatrix, false, new Float32Array(perspectiveMatrix));
gl.uniformMatrix4fv(uPerspectiveMatrix, false, new Float32Array(modelViewMatrix));
animate();
setTimeout(timer, 1500);
}
var count = 0;
var cn = 0;
function animate() {
requestAnimationFrame(animate);
drawScene();
}
function drawScene() {
draw();
gl.lineWidth(2);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.DYNAMIC_DRAW);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//gl.drawArrays( gl.LINES_STRIP, 0, numLines );
gl.drawArrays(gl.LINES, 0, numLines);
//gl.drawArrays( gl.QUAD_STRIP, 0, numLines );
gl.flush();
}
// ===================================
function setup() {
setup00();
setTimeout(onChangeTimer, 300);
}
function draw() {
/*
switch (drawType) {
case 0:
draw0();
break;
case 1:
draw1();
break;
case 2:
draw2();
break;
}
*/
draw00();
}
// ===================================
function setup00() {
vertices = [];
velThetaArr = [];
velRadArr = [];
ratio = cw / ch;
velocities = [];
thetaArr = [];
freqArr = [];
boldRateArr = [];
// -------------------------------
//var minSize = Math.min(window.innerWidth, scale.innerHeight);
var widthScale = window.innerWidth / window.innerHeight;
var height = 340 * scaleFactor;
var X_MAX_NUM = parseInt(window.innerWidth / height);
var Y_MAX_NUM = parseInt(window.innerHeight / height);
// 2 -> window.innerHeight
// ? -> 50
var targetRad = 1.0;
var xPos, yPos;
var target = new Target(targetRad);
target.x = 0;
target.y = 0;
targetArr.push(target);
for(var ii = 0; ii < numLines; ii++){
vertices.push( 0, 0, 1.83);
vertices.push( 0, 0, 1.83);
}
vertices = new Float32Array(vertices);
velocities = new Float32Array(velocities);
}
// -------------------------------
function draw00(){
for(var ii = 0; ii < targetArr.length; ii++ ){
targetArr[ii].rotate += targetArr[ii].rotate_speed;
}
var tRad, tX, tY;
var bp, px, py;
var target;
var side = .5 / window.innerHeight;
for(var ii = 0; ii < numLines * 2; ii += 2){
bp = ii * 3;
target = targetArr[ (ii/2) % targetArr.length];
tRad = Math.cos(target.rotate * 2.321 + target.freq * ii ) * target.bold_rate ;
tX = target.x + Math.cos(target.rotate + target.step * ii) * tRad;
tY = target.y + Math.sin(target.rotate + target.step * ii) * tRad;
px = vertices[bp + 3];
py = vertices[bp + 4];
px += (tX - px) * .3;
py += (tY - py) * .3;
vertices[bp + 3] = px;
vertices[bp + 4] = py;
vertices[bp ] = px-side;
vertices[bp + 1] = py-side;
}
}
Also see: Tab Triggers