A Pen by Andi Smithers

Developer
Size
5,449 Kb
Views
18,216

How do I make an a pen by andi smithers?

What is a a pen by andi smithers? How do you make a a pen by andi smithers? This script and codes were developed by Andi Smithers on 21 November 2022, Monday.

A Pen by Andi Smithers Previews

A Pen by Andi Smithers - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>A Pen by Andi Smithers</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <body> <div class = "outer"> <!-- setup the canvas --> <canvas class='main' id='webgl-test'></canvas> </div> <!-- link to google fonts --> <link href='https://fonts.googleapis.com/css?family=Orbitron' rel='stylesheet' type='text/css'> <script id="TestVShader" type="shader-vertex"> attribute vec3 aPosition; void main() { gl_Position = vec4(aPosition.xy, 0, 1); }
</script>
<script id="TestFShader" type="shader-fragment"> #ifdef GL_ES precision highp float; #endif void main() { gl_FragColor = vec4(1,1,0,1); // yellow }
</script>
</body> <script src="js/index.js"></script>
</body>
</html>

A Pen by Andi Smithers - Script Codes CSS Codes

body
{ background:#000000; margin: 0px; padding: 0px; overflow: hidden;
}

A Pen by Andi Smithers - Script Codes JS Codes

/*****************************************************************************
The MIT License (MIT)
Copyright (c) 2014 Andi Smithers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*****************************************************************************/
// conceptualized and written by andi smithers
// constant options
const focalDepth = 80;
const focalPoint = 256;
// special browser profile option
const displayProfile = false;
var profiling = false;
var backgroundColor;
// variables
var centreX;
var centreY;
var mouseX=0;
var mouseY=0;
var frameCount=0;
var context;
var canvas;
var gl;
const alertOnError = false;
// test hedron
var basicShader;
var vboIcoshedron;
var iboIcoshedron;
// initialization
function init()
{ // setup canvas and context canvas = document.getElementById('webgl-test'); // context = canvas.getContext('2d'); gl = canvas.getContext('webgl'); console.log(gl); // set canvas to be window dimensions resize(); // create event listeners canvas.addEventListener('mousemove', mouseMove); canvas.addEventListener('click', mouseClick); canvas.addEventListener('mousedown', mouseDown); canvas.addEventListener('mouseup', mouseUp); canvas.addEventListener("mousewheel", mouseWheel, false); document.addEventListener('keydown', processKeydown, false); window.addEventListener('resize', resize); // initialze variables window.AudioContext = window.AudioContext||window.webkitAudioContext; audioContext = new AudioContext(); initGL();
}
// input functions
function mouseMove(event)
{ var rect = canvas.getBoundingClientRect(); mouseX = event.clientX - rect.left; mouseY = event.clientY - rect.top; if (event.which&1 && dragging) { DragEvent(event); }
}
function mouseDown(event)
{ if (event.which&1) { dragging = true; DragEventStart(event); }
}
function mouseUp(event)
{ if (event.which&1 && dragging) { DragEventDone(event); }
}
function mouseClick()
{
}
function mouseWheel()
{
}
function processKeydown(event)
{
}
function resize()
{ var maxWidth = window.innerWidth; var maxHeight = window.innerHeight; canvas.width = maxWidth; canvas.height = maxHeight; // compute centre of screen centreX = canvas.width/2; centreY = canvas.height/2; // set viewport gl.viewport(0, 0, canvas.width, canvas.height);
}
var fade=0;
function render()
{ var a= fade; fade=(fade+1)%255; backgroundColor = 'rgb('+a+','+a+','+a+')'; //document.getElementById("webgl-test").style.background = backgroundColor; //context.clearRect(0, 0, canvas.width, canvas.height); renderGL();
}
// per frame tick functions
var previousTime = 0;
var currentTime = 0;
var freqHz = 0.016666;
function updateclocks()
{ // compute frequency frameCount++; // compute time between frames currentTime = new Date().getTime(); if (previousTime) freqHz = (currentTime - previousTime)/1000.0; previousTime = new Date().getTime();
}
// movement functions
function update()
{
}
function ProfileItem(name)
{ this.name = name; this.last = 0; this.calls =0; this.total =0; this.maxtime = 0; this.mintime = 0;
}
ProfileItem.prototype.add = function(time)
{ this.last = time; this.calls++; this.total+=time; this.mintime = Math.min(time, this.mintime); this.maxtime = Math.max(time, this.maxtime);
}
ProfileItem.pro
var profileItems = {};
function profile(func)
{ var st = performance.now();// (new Date()).getTime(); func(); var en = performance.now();//(new Date()).getTime(); if (profileItems[func.name]===undefined) profileItems[func.name] = new ProfileItem(func.name); profileItems[func.name].add((en-st));
}
var lastProfileTime = 0;
function profileDump()
{ var time = (new Date).getTime(); if (time-lastProfileTime > 5000) { console.log(profileItems); lastProfileTime = time; } profileDisplay();
}
function profileDisplay()
{ var keys = []; x = 250; y = 50; w = 250; context.font = '12pt Orbitron'; context.fillStyle = '#0000ff'; for(var obj in profileItems) { keys.push(obj); var item = profileItems[obj]; // remove coded profile name var name = item.name.replace("profile",""); name = name.replace("Profile",""); // log line profileColumnStat(name, item.maxtime, item.total/item.calls, item.calls, x, y, w); y+=30; }
}
function profileColumnStat(name, maxVal, avgVal, count, x, y, w)
{ context.textAlign = 'left'; context.fillText(name, x, y); context.fillText("avg: "+avgVal.toFixed(2) + "ms | peek: " + maxVal.toFixed(2)+"ms", x+w, y);
}
function animate()
{ // compute frequency updateclocks(); // movement update update(); // render update render(); // trigger next frame requestAnimationFrame(animate);
}
var icosahedronVerts;
var icosahedronTris;
function buildVerts()
{ icosahedronVerts = new Float32Array([ 0.000, 0.000, 1.000, 0.894, 0.000, 0.447, 0.276, 0.851, 0.447, -0.724, 0.526, 0.447, -0.724, -0.526, 0.447, 0.276, -0.851, 0.447, 0.724, 0.526, -0.447, -0.276, 0.851, -0.447, -0.894, 0.000, -0.447, -0.276, -0.851, -0.447, 0.724, -0.526, -0.447, 0.000, 0.000, -1.000 ]); icosahedronTris = new Uint16Array([ 0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,1, 11,7,6, 11,8,7, 11,9,8, 11,10,9, 11,6,10, 2,1,6, 2,7,3, 3,8,4, 4,9,5, 5,10,1, 6,7,2, 7,8,3, 8,9,4, 9,10,5, 10,6,1 ]);
}
function initGL()
{ buildVerts(); var vs = loadShaderFromScript(gl, "TestVShader"); var fs = loadShaderFromScript(gl, "TestFShader"); basicShader = createShaderProgram(gl, vs, fs); vboIcoshedron = createVertexBuffer(gl, icosahedronVerts); iboIcoshedron = createIndexBuffer(gl, icosahedronTris);
}
function renderGL()
{ gl.clearColor(0.0, 0.60, 0.0, 1.0); // Set clear color to black, fully opaque gl.enable(gl.DEPTH_TEST); // Enable depth testing gl.depthFunc(gl.LEQUAL); // Near things obscure far things gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT); // Clear the color as well as the depth buffer. gl.useProgram(basicShader); setVertexAttrib(gl, basicShader, vboIcoshedron, 3); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, iboIcoshedron); gl.drawElements(gl.TRIANGLES, icosahedronTris.length, gl.UNSIGNED_SHORT, 0);
}
// Load shader from html
function loadShaderFromScript(glc, scriptID)
{ // grab shader from dom var script = document.getElementById(scriptID); // get the body if (script==null) alert("errr. no scriptID: " + scriptID); // get type of shader var shaderType = script.type == "shader-vertex" ? glc.VERTEX_SHADER : glc.FRAGMENT_SHADER; // now load shader as normal string return loadShaderFromString(glc, script.innerHTML, shaderType);
}
// load shader from string
function loadShaderFromString(glc, code, shaderType)
{ var shader = glc.createShader(shaderType); glc.shaderSource(shader, code); glc.compileShader(shader); var result = glc.getShaderParameter(shader, glc.COMPILE_STATUS); if (!result) { var logInfo = glc.getShaderInfoLog(shader); console.log("error compiling " + shaderType + " shader:" + logInfo); console.log("source shader:" + logInfo); shader = null; if (alertOnError) alert("Error compiling shader"); } return shader;
}
//
// create shader for fragment or vertex
//
function createShaderProgram(glc, vertexShader, fragmentShader)
{ var program = glc.createProgram(); glc.attachShader(program, vertexShader); glc.attachShader(program, fragmentShader); glc.linkProgram(program); var result = glc.getProgramParameter(program, glc.LINK_STATUS); if (!result) { var errorString = glc.getProgramInfoLog(program); console.log("error in link: " + errorString); if (alertOnError) alert("error linking"); } return program;
}
function createVertexBuffer(glc, vertexData)
{ var buffer = glc.createBuffer(); glc.bindBuffer(glc.ARRAY_BUFFER, buffer); glc.bufferData(glc.ARRAY_BUFFER, vertexData, glc.STATIC_DRAW); return buffer;
}
function createIndexBuffer(glc, indexData)
{ var buffer = glc.createBuffer(); glc.bindBuffer(glc.ELEMENT_ARRAY_BUFFER, buffer); glc.bufferData(glc.ELEMENT_ARRAY_BUFFER, indexData, glc.STATIC_DRAW); return buffer;
}
function setVertexAttrib(glc, program, buffer, attribsize)
{ glc.bindBuffer(glc.ARRAY_BUFFER, buffer); var attr = glc.getAttribLocation(program, "aPosition"); glc.enableVertexAttribArray(attr); glc.vertexAttribPointer(attr, attribsize, gl.FLOAT, false, 0, 0);
}
// entry point
init();
animate();
A Pen by Andi Smithers - Script Codes
A Pen by Andi Smithers - Script Codes
Home Page Home
Developer Andi Smithers
Username Bolloxim
Uploaded November 21, 2022
Rating 3
Size 5,449 Kb
Views 18,216
Do you need developer help for A Pen by Andi Smithers?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Andi Smithers (Bolloxim) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!