Spilled Paint
How do I make an spilled paint?
Hey guys! So I really love this effect, and I really wish I could get it running smoothly in fullscreen! Any ideas on how to fix it up so it works are really appreciated. . What is a spilled paint? How do you make a spilled paint? This script and codes were developed by Darryl Huffman on 01 January 2023, Sunday.
Spilled Paint - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Spilled Paint</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="display"><div id="expand">+</div></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='https://codepen.io/darrylhuffman/pen/zogYQW.js'></script> <script src="js/index.js"></script>
</body>
</html>
Spilled Paint - Script Codes CSS Codes
html, body { width: 100%; height: 100%;
}
body { overflow: hidden; margin: 0px; padding: 0px; display: flex; background-color: #222;
}
* { transition: all 600ms;
}
#display { max-width: 750px; max-height: 450px; width: 100%; height: 100%; margin: auto; position: relative;
}
#display canvas { width: 100%; height: 100%;
}
#display #expand { position: absolute; width: 30px; right: -30px; bottom: -30px; line-height: 30px; text-align: center; color: #f25757; font-size: 20px; font-weight: bold;
}
#display.full { max-height: 100%; max-width: 100%;
}
#display.full #expand { transform: rotate(45deg); bottom: 0px; right: 0px; color: #222;
}
Spilled Paint - Script Codes JS Codes
$('#expand').click(function(){ $('#display').toggleClass('full'); setTimeout(function(){ setSize(); updateData(); }, 700);
});
var size = { x: $('#display').width(), y: $('#display').height()
};
var res = Math.ceil(size.y / size.y / 2);
var w = Math.ceil(size.x / res);
var h = Math.ceil(size.y / res);
var calch = (h * 1.5), // this is used in the animation, just caching math so I don't need to do it every frame. calcw = (w * 1.5); // ^^
var canvas = $('<canvas/>').attr({width: size.x, height: size.y}).appendTo('#display'), context = canvas.get(0).getContext("2d");
function setSize() { size = { x: $('#display').width(), y: $('#display').height() }; res = Math.ceil(size.y / size.y / 2); w = Math.ceil(size.x / res); h = Math.ceil(size.y / res); calch = (h * 1.5), calcw = (w * 1.5); canvas.attr({width: size.x, height: size.y});
}
var startTime = new Date().getTime();
var currentTime = 0;
noise.seed(8);
//noise.seed(Math.random());
var color;
// Cache colors to reduce work per frame -- Thanks Blake Bowen for this tip and a few others, hopefully performance will improve.
var color1 = [234,242,227,255];
var color2 = [97,232,225,255];
var color3 = [242,87,87,255];
var color4 = [242,232,99,255];
var color5 = [242,205,96,255];
var color6 = [255/2,255/2,255/2];
var imagedata = context.createImageData(size.x, size.y);
var buf = new ArrayBuffer(imagedata.data.length);
var buf8 = new Uint8ClampedArray(buf);
var data = new Uint32Array(imagedata.data.buffer);
function updateData(){ imagedata = context.getImageData(0, 0, size.x, size.y); data = new Uint32Array(imagedata.data.buffer);
}
function draw(){ var now = new Date().getTime(); currentTime = (now - startTime) / 10000; // this variable will start at 0, and then will go up at a slow rate. So 2 seconds into the animation will be like 0.002. // That variable is also responsable for the animation timing. It iterates through the "z" axis of the Perlin Noise. I also move the perlin noise slowly on the x and y axis. for(var y = 0; y < size.y; y++){ for(var x = 0; x < size.x; x++){ var r = noise.simplex3((currentTime + x) / calcw, currentTime + y / calch, currentTime); // Figure out what this pixel looks like in the perlin noise // r will return a number between -1 and +1. So for every .4 in between, I change the color. if(r >= -2 && r < -0.6){ color = color1; } else if(r >= -0.6 && r < -0.2){ color = color2; } else if(r >= -0.2 && r < 0.2){ color = color3; } else if(r >= 0.2 && r < 0.6){ color = color4; } else if(r >= 0.6 && r <= 2){ color = color5; } else { color = color6; } // Set pixel data data[y * size.x + x] = (color[3] << 24) | // alpha (color[2] << 16) | // blue (color[1] << 8) | // green color[0]; // red } } context.putImageData(imagedata, 0, 0); // Push the pixel data to the canvas requestFrame(draw); // Call this funtion again on the next animation frame.
}
window.requestFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); };
})();
draw();
$('#display').on('resize', setSize);

Developer | Darryl Huffman |
Username | darrylhuffman |
Uploaded | January 01, 2023 |
Rating | 4.5 |
Size | 3,894 Kb |
Views | 16,184 |
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 |
Simple SVG Charts | 6,694 Kb |
Spilled Paint v2 | 4,275 Kb |
Pixelot | 3,080 Kb |
Blackhole | 4,946 Kb |
Orbit | 3,173 Kb |
Fur | 2,938 Kb |
BLACKHOLE - A Canvas Experiment | 3,676 Kb |
A Different Clock | 3,613 Kb |
Spilled Galaxy | 2,163 Kb |
A Perfect Orbit | 3,411 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 |
SlideupBoxes | Gavra | 23,772 Kb |
GrcJS | Vino6 | 2,047 Kb |
OnScreenAction | Ozgursagiroglu | 2,647 Kb |
Dribbble Template | ExtremelyGinger | 2,204 Kb |
Spiralator 9000 | AdmiralPotato | 4,671 Kb |
SnappySnippet Test | Elmsoftware | 8,385 Kb |
GLSL Hills | Ykob | 6,991 Kb |
Vue.js Starter | Andymerskin | 1,268 Kb |
Zip Button test | Lje7462 | 1,932 Kb |
Replace url via jquery | Serluk | 1,429 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!