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

feat: add Random Gradient Generator tool #2002

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
17 changes: 17 additions & 0 deletions Projects/Random Gradient Generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Random Gradient Generator

The Random Gradient Generator is a simple web tool designed to help you quickly create and integrate vibrant background gradients into your web projects. Whether you're designing a website, building a web application, or experimenting with CSS styling, this tool simplifies the process of adding beautiful gradients to your designs.

## Features

- Generate random linear gradients with a single click.
- Preview the generated gradient in real-time.
- Copy the generated gradient CSS code to your clipboard with one click.

## How to Use

1. **Generate a Gradient**: Click the "Generate Gradient" button to create a new random gradient.
2. **Preview the Gradient**: The gradient will be displayed in the preview box.
3. **Copy the Gradient Code**: Click the "Copy" button to copy the generated CSS code from the input field.
4. **Use the Gradient**: Paste the copied CSS code into your HTML or CSS file to apply the gradient to your webpage.

19 changes: 19 additions & 0 deletions Projects/Random Gradient Generator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!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>
<div class="container">
<h1>Random Gradient Generator</h1>
<button id="generate-btn">Generate Gradient</button>
<div class="gradient-preview" id="gradient-preview"></div>
<input type="text" id="gradient-code" readonly>
<button id="copy-btn">Copy</button>
</div>
<script src="script.js"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions Projects/Random Gradient Generator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function getRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}

function generateGradient() {
const color1 = getRandomColor();
const color2 = getRandomColor();
const gradient = `linear-gradient(to right, ${color1}, ${color2})`;
document.getElementById('gradient-preview').style.background = gradient;
document.getElementById('gradient-code').value = `background: ${gradient};`;
}

function copyToClipboard() {
const copyText = document.getElementById('gradient-code');
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
document.execCommand('copy');
alert('Copied to clipboard: ' + copyText.value);
}

document.getElementById('generate-btn').addEventListener('click', generateGradient);
document.getElementById('copy-btn').addEventListener('click', copyToClipboard);

generateGradient();
39 changes: 39 additions & 0 deletions Projects/Random Gradient Generator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}

.container {
text-align: center;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}

.gradient-preview {
width: 300px;
height: 150px;
margin: 20px auto;
border-radius: 10px;
border: 1px solid #ddd;
}

input {
width: 80%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
}