Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Gradient Generator #1987

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Projects/Random-Gradient-Generator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Gradient Generator</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<header>Random Gradient Generator</header>
<div id="gradient" class="gradient">
<button id="generateButton">Generate Gradient</button>
<div class="input-container">
<input type="text" id="gradientCode" readonly>
<button id="copyButton" class="copy-button">Copy</button>
</div>
</div>

<script src="script.js"></script>
</body>

</html>
34 changes: 34 additions & 0 deletions Projects/Random-Gradient-Generator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
document.addEventListener("DOMContentLoaded", function() {
const gradientDiv = document.getElementById("gradient");
const generateButton = document.getElementById("generateButton");
const gradientCodeInput = document.getElementById("gradientCode");
const copyButton = document.getElementById("copyButton");

// Function to generate a random color
function generateRandomColor() {
return '#' + Math.floor(Math.random() * 16777215).toString(16);
}

// Function to generate random gradient and set as background
function generateRandomGradient() {
const color1 = generateRandomColor();
const color2 = generateRandomColor();
const gradientDirection = Math.random() < 0.5 ? "to right" : "to left"; // Random gradient direction
const gradient = `linear-gradient(${gradientDirection}, ${color1}, ${color2})`;
gradientDiv.style.background = gradient;
gradientCodeInput.value = `background: ${gradient};`;
}

// Event listener for the button click
generateButton.addEventListener("click", generateRandomGradient);

// Event listener for the copy button click
copyButton.addEventListener("click", function() {
gradientCodeInput.select();
document.execCommand("copy");
});

// Initial random gradient
generateRandomGradient();
});

86 changes: 86 additions & 0 deletions Projects/Random-Gradient-Generator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
* {
padding: 0;
margin: 0;
}
header {
height: 5rem;
display: flex;
justify-content: center;
align-items: center;
font-size: xx-large;
color: white;
background-color: #222;
}
.gradient {
width: 100%;
height: calc(100vh - 5rem);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

button {
margin-bottom: 20px;
padding: 20px 20px;
font-size: 16px;
background-color: #222;
color: #fff;
border: none;
border-radius: 1rem;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #515151;
color: #fff;
}

.input-container {
position: relative;
margin-bottom: 20px;
}

.input-container input[type="text"] {
width: 400px;
height: 4rem;
background-color: #717171;
color: #fff;
padding: 10px;
font-size: 20px;
border: 1px solid #ccc;
border-radius: 50rem;
outline: none;
}

.input-container input[type="text"]:focus {
border-color: #222;
}

.copy-button {
height: 4rem;
width: 4rem;
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
padding: 6px 12px;
font-size: 14px;
background-color: #222;
color: white;
border: none;
border-radius: 50rem;
cursor: pointer;
transition: background-color 0.3s;
}

.copy-button:hover {
background-color: #515151;
}
/* Media Query for responsiveness */
@media screen and (max-width: 768px) {
.input-container input[type="text"] {
width: 90%; /* Adjusted width for smaller screens */
}
}