Spiral
How do I make an spiral?
Drag/swipe to rotate. . What is a spiral? How do you make a spiral? This script and codes were developed by Hakim El Hattab on 24 September 2022, Saturday.
Spiral - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Spiral</title> <meta name="viewport" content="width=700"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas></canvas>
<span>drag to rotate</span> <script src="js/index.js"></script>
</body>
</html>
Spiral - Script Codes CSS Codes
body { display: -webkit-box; display: -ms-flexbox; display: flex; height: 100vh; background-color: #111;
}
canvas { margin: auto;
}
span { color: #777; position: absolute; top: 20px; left: 20px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
Spiral - Script Codes JS Codes
var canvas = document.querySelector( 'canvas' );
var context = canvas.getContext( '2d' );
var time = 0, velocity = 0.1, velocityTarget = 0.1, width, height, lastX, lastY;
var MAX_OFFSET = 400;
var SPACING = 4;
var POINTS = MAX_OFFSET / SPACING;
var PEAK = MAX_OFFSET * 0.25;
var POINTS_PER_LAP = 6;
var SHADOW_STRENGTH = 6;
setup();
function setup() { resize(); step(); window.addEventListener( 'resize', resize ); window.addEventListener( 'mousedown', onMouseDown ); document.addEventListener( 'touchstart', onTouchStart );
}
function resize() { width = canvas.width = window.innerWidth; height = canvas.height = window.innerHeight;
}
function step() { time += velocity; velocity += ( velocityTarget - velocity ) * 0.3; clear(); render(); requestAnimationFrame( step );
}
function clear() { context.clearRect( 0, 0, width, height );
}
function render() { var x, y, cx = width/2, cy = height/2; context.globalCompositeOperation = 'lighter'; context.strokeStyle = '#fff'; context.shadowColor = '#fff'; context.lineWidth = 2; context.beginPath(); for( var i = POINTS; i > 0; i -- ) { var value = i * SPACING + ( time % SPACING ); var ax = Math.sin( value/POINTS_PER_LAP ) * Math.PI, ay = Math.cos( value/POINTS_PER_LAP ) * Math.PI; x = ax * value, y = ay * value * 0.35; var o = 1 - ( Math.min( value, PEAK ) / PEAK ); y -= Math.pow( o, 2 ) * 200; y += 200 * value / MAX_OFFSET; y += x / cx * width * 0.1; context.globalAlpha = 1 - ( value / MAX_OFFSET ); context.shadowBlur = SHADOW_STRENGTH * o; context.lineTo( cx + x, cy + y ); context.stroke(); context.beginPath(); context.moveTo( cx + x, cy + y ); } context.lineTo( cx, cy - 200 ); context.lineTo( cx, 0 ); context.stroke();
}
function onMouseDown( event ) { lastX = event.clientX; lastY = event.clientY; document.addEventListener( 'mousemove', onMouseMove ); document.addEventListener( 'mouseup', onMouseUp );
}
function onMouseMove( event ) { var vx = ( event.clientX - lastX ) / 100; var vy = ( event.clientY - lastY ) / 100; if( event.clientY < height/2 ) vx *= -1; if( event.clientX > width/2 ) vy *= -1; velocityTarget = vx + vy; lastX = event.clientX; lastY = event.clientY;
}
function onMouseUp( event ) { document.removeEventListener( 'mousemove', onMouseMove ); document.removeEventListener( 'mouseup', onMouseUp );
}
function onTouchStart( event ) { event.preventDefault(); lastX = event.touches[0].clientX; lastY = event.touches[0].clientY; document.addEventListener( 'touchmove', onTouchMove ); document.addEventListener( 'touchend', onTouchEnd );
}
function onTouchMove( event ) { var vx = ( event.touches[0].clientX - lastX ) / 100; var vy = ( event.touches[0].clientY - lastY ) / 100; if( event.touches[0].clientY < height/2 ) vx *= -1; if( event.touches[0].clientX > width/2 ) vy *= -1; velocityTarget = vx + vy; lastX = event.touches[0].clientX; lastY = event.touches[0].clientY;
}
function onTouchEnd( event ) { document.removeEventListener( 'touchmove', onTouchMove ); document.removeEventListener( 'touchend', onTouchEnd );
}
Developer | Hakim El Hattab |
Username | hakimel |
Uploaded | September 24, 2022 |
Rating | 4.5 |
Size | 2,958 Kb |
Views | 20,240 |
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!
Name | Size |
Flexing pagination arrows | 3,950 Kb |
CSS Spinner Animation | 5,951 Kb |
404 | 3,893 Kb |
Checkwave | 2,735 Kb |
Magnetic | 4,103 Kb |
DOM Tree | 3,349 Kb |
Blob | 6,452 Kb |
Hole | 3,204 Kb |
Ladda | 6,843 Kb |
Waves | 3,771 Kb |
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!
Name | Username | Size |
Jstam.com Home Page | Jstam | 10,558 Kb |
Addthis_button | Esambino | 1,691 Kb |
Bootstrap 4 Gridsystem Demo | Rivella50 | 1,535 Kb |
Count checked checkboxes with jQuery | Mestika | 2,343 Kb |
RPG Style Text Dialogue | Odylic | 2,635 Kb |
CSS Tooltips | Darylldoyle | 2,599 Kb |
Flip test | Madhes | 1,635 Kb |
Video mute | Leon9208 | 2,131 Kb |
Cut and Paste Roll Link | BottomlineInteractive | 2,546 Kb |
CSS Colors | Alexpate | 2,232 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!