Curved warp
How do I make an curved warp?
Short rainbow segments that make a color changing spiral move the mouse around to interact. What is a curved warp? How do you make a curved warp? This script and codes were developed by Kittons on 09 September 2022, Friday.
Curved warp - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>curved warp</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="curves" width="500" height="300" style="width:100%;height:100%"></canvas> <script src="js/index.js"></script>
</body>
</html>
Curved warp - Script Codes CSS Codes
body{ margin: 0; background-color: #000;
}
Curved warp - Script Codes JS Codes
var cv = document.getElementById('curves'); var cvWidth,cvHeight,diaf; var ctx = cv.getContext('2d'); var xMouse = 0; var yMouse = 0; var perc; var radius,outerRadius; var easingValues = [.13,.83,.38,1]; //var easingValues = [.2,1.32,.73,1.12]; var easingOutValues = [.62,.01,.93,.33]; //var easingOutValues = [.2,1.32,.73,1.12]; var colorEasingValues = [.14,.69,.6,.92]; var colorEasingOutValues = [.61,.11,.96,.4]; var colorEasingOutValues = [.85,-0.35,.99,-0.11]; //var colorEasingOutValues = [.76,.1,.87,.22]; //var colorEasingOutValues = [.55,.18,.86,.53]; var colorPerc; //var easingValues = [.36,-0.28,.4,1.56]; var radiusDuration = 1500; var segmentsPerIteration = 20; var outerRadiusGrow = 20; var cvLineWidth = 10; var cvAlpha = .7; var angleOffsetIncrement = 4; function resize(){ cv.width = window.innerWidth; cv.height = window.innerHeight; cvWidth = cv.width; cvHeight = cv.height; diag = Math.sqrt(Math.pow((cvWidth/2),2)+Math.pow((cvHeight/2),2)); ctx.translate(cvWidth/2,cvHeight/2); ctx.lineWidth = cvLineWidth; ctx.globalAlpha = cvAlpha; ctx.lineCap = 'round'; //ctx.globalCompositeOperation = 'overlay'; } function getMousePosition(e) { handleMouseMove(e.pageX,e.pageY); } function getTouchPosition(e) { handleMouseMove(e.targetTouches[0].e,targetTouches[0].pageY); } var currentX = 0,currentY = 0; var xx=0, yy=0; function handleMouseMove(x,y){ xx = (x-cvWidth/2); yy = (y-cvHeight/2); } var segments = []; function Segment(num){ this.num = num; this.cr = colorsRGB[num][0]; this.cg = colorsRGB[num][1]; this.cb = colorsRGB[num][2]; this.ch = colorsHSL[num][0]; this.cs = colorsHSL[num][1]; this.cl = colorsHSL[num][2]; this.color = 'rgb('+this.cr+','+this.cg+','+this.cb+')'; } var rotCount = 0; var cnt = 0; var deg2Rad = Math.PI/180; var angleOffset = 0; var currentMainColor = 0; Segment.prototype.update = function(){ var value = this.num - currentMainColor; if(value < 0){ value = colors.length + value; } ctx.lineWidth = 10 + 20*perc; ctx.strokeStyle = 'hsl('+this.ch+','+this.cs*(1-colorPerc)+'%,'+this.cl+'%)'; radius = (cvWidth+value*100)/9*perc; outerRadius = outerRadiusGrow+radius; var i = 0; while(i<segmentsPerIteration){ var angle = 360*i/(segmentsPerIteration); angle += (this.num*10)+angleOffset/2; var degAngle = angle*deg2Rad; var sinAngle = Math.sin(degAngle); var cosAngle = Math.cos(degAngle); var outerAngle = (angle)*deg2Rad; var sinOuter = Math.sin(outerAngle); var cosOuter = Math.cos(outerAngle); ctx.beginPath(); ctx.moveTo(xMouse+radius*sinAngle,yMouse+radius*cosAngle); ctx.lineTo(xMouse+(outerRadius)*sinOuter,yMouse+(outerRadius)*cosOuter); ctx.stroke(); i+=1; } }; var i; function createSegments(){ var i; for(i=0;i<totalSegments;i+=1){ segments.push(new Segment(i)); } } var colors = ['#B9D22F','#EE7B1F','#D12233','#00AAEA','#DD599F']; var colorsRGB = [[185,210,47],[238,123,31],[209,34,51],[0,170,234],[221,89,159]]; var colorsHSL = [[69,64.4,50.4],[27,85.9,52.7],[354,72,47.6],[196,100,45.9],[328,66,60.8]]; var growFlag = true; var totalSegments = colors.length; createSegments(); var factor = 20; function update(){ xMouse += (xx - xMouse)/factor; yMouse += (yy - yMouse)/factor; for(i=0;i<totalSegments;i+=1){ segments[(i+currentMainColor)%totalSegments].update(); } angleOffset += angleOffsetIncrement; var currentTime = Date.now(); if(!growFlag){ perc = 1 - easingOutFn('',currentTime - startTime,0,1,radiusDuration); colorPerc = 1 - colorEasingOutFn('',currentTime - startTime,0,1,radiusDuration); }else{ perc = easingFn('',currentTime - startTime,0,1,radiusDuration); colorPerc = colorEasingFn('',currentTime - startTime,0,1,radiusDuration); } if(currentTime - startTime > radiusDuration){ startTime = currentTime + (currentTime - startTime) - radiusDuration; growFlag = !growFlag; if(growFlag){ currentMainColor += 1; if(currentMainColor >= colors.length){ currentMainColor = 0; } } } requestAnimationFrame(update); } var getEasingCurve = (function(){ var easingFunctions = {}; return function(aa,bb,cc,dd,encodedFuncName) { if(!encodedFuncName){ encodedFuncName = ('bez_' + aa+'_'+bb+'_'+cc+'_'+dd).replace(/\./g, 'p'); } if(easingFunctions[encodedFuncName]){ return easingFunctions[encodedFuncName]; } var A0, B0, C0; var A1, B1, C1; easingFunctions[encodedFuncName] = function(x, t, b, c, d) { var tt = t/d; x = tt; var i = 0, z; while (++i < 14) { C0 = 3 * aa; B0 = 3 * (cc - aa) - C0; A0 = 1 - C0 - B0; z = (x * (C0 + x * (B0 + x * A0))) - tt; if (Math.abs(z) < 1e-3) break; x -= z / (C0 + x * (2 * B0 + 3 * A0 * x)); } C1 = 3 * bb; B1 = 3 * (dd - bb) - C1; A1 = 1 - C1 - B1; var polyB = x * (C1 + x * (B1 + x * A1)); return c * polyB + b; }; return easingFunctions[encodedFuncName]; } }()); var easingFn = getEasingCurve(easingValues[0],easingValues[1],easingValues[2],easingValues[3]); var easingOutFn = getEasingCurve(easingOutValues[0],easingOutValues[1],easingOutValues[2],easingOutValues[3]); var colorEasingFn = getEasingCurve(colorEasingValues[0],colorEasingValues[1],colorEasingValues[2],colorEasingValues[3]); var colorEasingOutFn = getEasingCurve(colorEasingOutValues[0],colorEasingOutValues[1],colorEasingOutValues[2],colorEasingOutValues[3]); var startTime = Date.now(); update(); resize(); cv.onmousemove = getMousePosition; cv.ontouchmove = getTouchPosition; window.onresize = resize;
Developer | Kittons |
Username | airnan |
Uploaded | September 09, 2022 |
Rating | 3.5 |
Size | 3,581 Kb |
Views | 28,336 |
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 |
After Effects to PIXI.js | 1,866 Kb |
Svg jou jou monster | 2,116 Kb |
Catrim cat | 1,810 Kb |
Shapes | 1,817 Kb |
HTML codepen banner | 1,488 Kb |
Bug Industries - The Lady | 1,924 Kb |
SVG Animated icons | 3,819 Kb |
A christmas loop in svg | 2,227 Kb |
Shapes recolored | 2,268 Kb |
Holy space cows from the strange universe of cyriak | 4,805 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 |
Large canvas mousemove experiment | Jibbon | 2,885 Kb |
SVG Animation | Pollardld | 3,133 Kb |
Importable Clearfix | Corysimmons | 1,411 Kb |
Multi-step GSAP animation | Acacheung | 2,668 Kb |
Vue Transition | Chenming142 | 4,561 Kb |
A Pen by Jay | Jaycode | 3,784 Kb |
404 Error Page | WebSonick | 3,203 Kb |
The Rope | Chribbe | 2,886 Kb |
Siema - add pagination to prototype | Pawelgrzybek | 2,575 Kb |
Weird glowy CSS3 game | Toneworm | 3,684 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!