JSFiddle - React, Tailwind, and code Playground

by Tan

HTML

<div id="outer" class="outer">
  <div id="shape" class="shape1"></div>
</div>

CSS

body {margin:0;}

.outer {
  height: 100vh;
  width: 100%;
  background-color: lightgray;
  display: flex;
  justify-content: center;
  align-items: center;
}



.shape1 {background-color:tomato;transition:all 1s ease;width:10px;height:10px;
transform-origin: center;

}

JavaScript

let timeout;

function myFunction() {
  timeout = setTimeout(alertFunc, 1000);
}

function alertFunc() {
var s = document.getElementById('shape');
var ran1 = Math.floor(Math.random() * 300) + 1;
var ran2 = Math.floor(Math.random() * 300) + 1;
var ran3 = Math.floor(Math.random() * 50) + 1;
var ran4 = Math.floor(Math.random() * 360) + 1;

var r1 = Math.floor(Math.random() * 100) + 1;
var r2 = Math.floor(Math.random() * 100) + 1;
var r3 = Math.floor(Math.random() * 100) + 1;
var r4 = Math.floor(Math.random() * 100) + 1;
var r5 = Math.floor(Math.random() * 100) + 1;
var r6 = Math.floor(Math.random() * 100) + 1;
var r7 = Math.floor(Math.random() * 100) + 1;
var r8 = Math.floor(Math.random() * 100) + 1;


s.style.transform = "rotate("+ran4+"deg)";

s.style["boxShadow"] = "-17px 200px 68px 16px rgba(0,0,0,0.05)";

s.style.width = ran1+"px";
s.style.height = ran2+"px";
s.style.borderRadius = r1+"% "+r2+"% "+r1+"% "+r2+"% / "+r3+"% "+r4+"% "+r3+"% "+r4+"%";

ran_col();




myFunction();
}

myFunction();

function ran_col() { //function name
var color = '#'; // hexadecimal starting symbol
var letters = ['0074D9','001f3f','FF851B','3D9970','2ECC40','FFDC00','B10DC9','FF4136']; //Set your colors here
color += letters[Math.floor(Math.random() * letters.length)];
document.getElementById('shape').style.background = color; // Setting the random color on your div element.
}