안녕하세요?? 나는 다시 정상으로 돌아왔다. #100daysofMiva 코딩 챌린지 9일차에는 Nodejs에서 간단한 색상 팔레트 생성기를 작업했습니다. 산책해 보세요...✨
? 색상 팔레트 생성기
확인해 보세요
https://colorpal.onrender.com
이것은 Express.js 및 chroma-js를 사용하여 Node.js로 구축된 색상 팔레트 생성기입니다. 무작위로 생성된 기본 색상의 다양한 색조를 포함하여 매번 아름다운 5색 팔레트를 생성합니다. 빠른 색상 영감을 원하는 UI/UX 디자이너에게 적합합니다! ?
? 특징
- 단일 기본 색상의 변형으로 일치하는 5가지 색상을 생성합니다.
- 각 팔레트에는 고유 ID가 할당되어 사용자가 /palette/:id 경로를 통해 팔레트를 검색할 수 있습니다.
- 서버 측 로직을 위한 Express.js와 색상 조작을 위한 chroma-js로 구축되었습니다.
- 새 팔레트를 동적으로 생성하는 새로 고침 버튼이 포함된 생성된 팔레트를 표시하기 위한 간단하고 우아한 UI.
백엔드?
?️ 사용된 기술
- Node.js 및 Express.js: 라우팅을 처리하는 백엔드 프레임워크
- Chroma.js: 강력한 색상 조작 및 팔레트 생성을 위한 도구입니다.
- HTML/CSS/부트스트랩: 깔끔하고 반응성이 뛰어난 UI를 위한 것입니다.
? 시작하기
1. 리포지토리 복제
git clone https://github.com/Marvellye/colorpal cd colorpal
2. 종속성 설치
npm install
3. 애플리케이션 실행
node app.js
4. 애플리케이션 열기
브라우저에서 앱을 방문하세요:
http://localhost:3000
새로운 5색 팔레트를 생성할 수 있는 인터페이스가 표시됩니다. 새로운 색상 팔레트를 가져오려면 생성 버튼을 누르세요.
5. ID로 팔레트 검색
특정 팔레트를 검색하려면 다음으로 이동하세요.
http://localhost:3000/palette/:id
:id를 보려는 팔레트의 ID로 바꾸세요. 예:
http://localhost:3000/palette/C08552-F3E9DC-5E3023-DAB49D
? 작동 방식
- 팔레트 생성: 생성 버튼을 클릭할 때마다 기본 색상이 무작위로 생성됩니다. 이 베이스를 바탕으로 5가지의 서로 다른 색상 변형(다른 색조)이 생성됩니다.
- 고유 ID: 생성된 각 팔레트에는 색상의 16진수 값으로 만들어진 고유 ID가 있으며, 나중에 팔레트를 검색하는 데 사용할 수 있습니다.
- Chroma.js 사용: chroma-js의 강력한 기능으로 생성된 색상이 시각적으로 매력적이며 다양한 밝기 수준을 제공합니다.
?️ 예시 팔레트
다음은 앱이 생성하는 팔레트 종류의 예입니다.
Base Color: #C08552 Palette: #F3E9DC (Light) #5E3023 (Dark) #DAB49D (Neutral)
프론트엔드?✨
? 컬러 팔레트 표시
이 색상 팔레트 생성기는 5가지 색상 팔레트를 동적으로 생성하여 UI에 표시합니다. 사용자는 생성 버튼을 클릭하여 팔레트와 상호 작용할 수 있으며, 팔레트 ID는 특정 색상 조합을 저장하고 공유하는 데 사용됩니다. 레이아웃 작동 방식은 다음과 같습니다.
? HTML 레이아웃
헤더
<!-- Header --> <header class="p-3 text-center"> <h1 id="Colour-Palette-Generator">Colour Palette Generator</h1> </header>
헤더는 애플리케이션에 대한 깔끔하고 간단한 제목을 제공합니다.
컬러박스
<!-- Colour Boxes --> <section class="color-container"> <div id="box1" class="color-box" style="background-color: #000000;"> <span>#000000</span> </div> <div id="box2" class="color-box" style="background-color: #000000;"> <span>#000000</span> </div> <div id="box3" class="color-box" style="background-color: #000000;"> <span>#000000</span> </div> <div id="box4" class="color-box" style="background-color: #000000;"> <span class="text-white">Hey!</span> </div> <div id="box5" class="color-box" style="background-color: #000000;"> <span class="text-white"></span> </div> </section>
이 섹션에는 색상 상자가 포함되어 있습니다. 각 상자는 생성된 색상 팔레트에 따라 배경색을 동적으로 변경하는 div입니다. 각 div 내부의 범위는 색상의 16진수 값을 표시합니다.
짐을 싣는 사람
<!-- Loader --> <section id="loader" class="loader"> <div class="is-loading"> <h3 id="Generating">Generating...</h3> </div> </section>
이 섹션에는 새 색상 팔레트가 생성될 때 나타나는 로더가 포함되어 있습니다. 색상이 로드된 후 로더가 사라집니다.
보행인
<!-- Footer --> <footer class="d-flex justify-content-between align-items-center"> <button onclick="gen()" class="btn btn-light">Generate</button> <button class="btn text-white" onclick="share(window.location.href)"> <i class="fa-regular fa-share-from-square"></i> </button> <span class="">100daysofMiva-Marvelly</span> </footer>
바닥글에는 색상 생성을 시작하는 생성 버튼과 소셜 미디어 공유를 위한 공유 버튼이 포함되어 있습니다.
? 자바스크립트 기능
동적 색상 생성
const boxes = [ document.getElementById('box1'), document.getElementById('box2'), document.getElementById('box3'), document.getElementById('box4'), document.getElementById('box5') ]; function updateBoxes(colors) { colors.forEach((color, index) => { boxes[index].style.backgroundColor = color; boxes[index].querySelector('span').textContent = color; }); }
이 JavaScript 코드는 새 팔레트가 생성될 때 색상 상자의 색상을 동적으로 업데이트합니다. 색상은 UI의 각 div 요소에 적용됩니다.
팔레트 생성 로직
async function gen() { // Show the loader loader.style.display = 'block'; try { const response = await fetch('/palette'); const data = await response.json(); // Update the boxes with the new colors updateBoxes(data.palette); // Update the URL with the new ID history.pushState({}, '', `/${data.id}`); loader.style.display = 'none'; } catch (error) { console.error('Error fetching palette:', error); loader.style.display = 'none'; } }
gen() 함수는 /palette API 경로에서 새 색상 팔레트를 가져오고, 색상 상자를 업데이트하고, 새 팔레트 ID로 브라우저 URL을 수정합니다.
기능 공유
function share(url) { Swal.fire({ heightAuto: false, title: 'Share this Color Palette!', html: ` <div style="display: flex; justify-content: space-around; font-size: 24px;"> <a href="https://api.whatsapp.com/send?text=%24%7BencodeURIComponent(url)%7D" target="_blank" title="Share on WhatsApp"> <i class="fab fa-whatsapp" style="color: #25D366;"></i> </a> <a href="https://www.facebook.com/sharer/sharer.php?u=%24%7BencodeURIComponent(url)%7D" target="_blank" title="Share on Facebook"> <i class="fab fa-facebook" style="color: #3b5998;"></i> </a> <a href="https://twitter.com/intent/tweet?url=%24%7BencodeURIComponent(url)%7D" target="_blank" title="Share on Twitter"> <i class="fab fa-twitter" style="color: #1DA1F2;"></i> </a> <a href="https://www.instagram.com/?url=%24%7BencodeURIComponent(url)%7D" target="_blank" title="Share on Instagram"> <i class="fab fa-instagram" style="color: #E1306C;"></i> </a> </div> `, showConfirmButton: false, showCloseButton: false, }); }
share() 기능을 사용하면 사용자는 SweetAlert 팝업을 사용하여 WhatsApp, Facebook, Twitter, Instagram, Telegram과 같은 소셜 미디어 플랫폼을 통해 현재 색상 팔레트를 공유할 수 있습니다.
URL-Based Color Loading
// Check if an id is present in the URL const currentPath = window.location.pathname; const paletteId = currentPath.substring(1); if (paletteId) { loadPaletteById(paletteId); } else { gen(); }
This functionality checks if there is a color palette ID in the URL when the page is loaded. If an ID is present, the corresponding palette is loaded. Otherwise, a new palette is generated.
? Issues Encountered
Building this app wasn't without its challenges! Here are some of the problems I encountered and how I solved them:
Dull Color Palettes: Initially, I was getting dull and boring colors. The issue was due to the way I was generating shades from the base color. I switched to using hsl.l (lightness) adjustments for better visual results.
Color Palette Variants: At first, I used random colors that were too different from each other. After realizing that everyone needed variants of the same base color for consistency, I adjusted my approach to generate color scales with different lightness levels.
Invalid Palette IDs: When trying to retrieve a palette by ID, some IDs were invalid or incorrectly formatted. I fixed this by ensuring a strict format for the IDs and adding error handling for invalid IDs.
Hex Values Misplacement: At one point, the hex values were not displaying properly inside the color boxes. This was fixed by ensuring the span elements were correctly updated with the hex values.
Palette Sharing: Creating a robust sharing mechanism for various social media platforms was a bit challenging but ultimately solved using SweetAlert for the UI and share links for each platform.
Dynamic Palette Update: Implementing a smooth update of the UI when a new palette was generated was tricky. By using simple JavaScript and handling the loader display correctly, I ensured a seamless experience for users when generating new palettes.
✨ Future Improvements
- Add support for saving favorite palettes in a database.
- Enhance the UI with animations for palette generation.
- Allow users to download the color palette in various formats like JSON, CSS, or an image.
Check it out
https://colorpal.onrender.com
My GitHub repo
https://github.com/Marvellye/colorpal
위 내용은 색상 팔레트 생성기의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

JavaScript의 최신 트렌드에는 Typescript의 Rise, 현대 프레임 워크 및 라이브러리의 인기 및 WebAssembly의 적용이 포함됩니다. 향후 전망은보다 강력한 유형 시스템, 서버 측 JavaScript 개발, 인공 지능 및 기계 학습의 확장, IoT 및 Edge 컴퓨팅의 잠재력을 포함합니다.

JavaScript는 현대 웹 개발의 초석이며 주요 기능에는 이벤트 중심 프로그래밍, 동적 컨텐츠 생성 및 비동기 프로그래밍이 포함됩니다. 1) 이벤트 중심 프로그래밍을 사용하면 사용자 작업에 따라 웹 페이지가 동적으로 변경 될 수 있습니다. 2) 동적 컨텐츠 생성을 사용하면 조건에 따라 페이지 컨텐츠를 조정할 수 있습니다. 3) 비동기 프로그래밍은 사용자 인터페이스가 차단되지 않도록합니다. JavaScript는 웹 상호 작용, 단일 페이지 응용 프로그램 및 서버 측 개발에 널리 사용되며 사용자 경험 및 크로스 플랫폼 개발의 유연성을 크게 향상시킵니다.

Python은 데이터 과학 및 기계 학습에 더 적합한 반면 JavaScript는 프론트 엔드 및 풀 스택 개발에 더 적합합니다. 1. Python은 간결한 구문 및 풍부한 라이브러리 생태계로 유명하며 데이터 분석 및 웹 개발에 적합합니다. 2. JavaScript는 프론트 엔드 개발의 핵심입니다. Node.js는 서버 측 프로그래밍을 지원하며 풀 스택 개발에 적합합니다.

JavaScript는 이미 최신 브라우저에 내장되어 있기 때문에 설치가 필요하지 않습니다. 시작하려면 텍스트 편집기와 브라우저 만 있으면됩니다. 1) 브라우저 환경에서 태그를 통해 HTML 파일을 포함하여 실행하십시오. 2) Node.js 환경에서 Node.js를 다운로드하고 설치 한 후 명령 줄을 통해 JavaScript 파일을 실행하십시오.

쿼츠 타이머를 사용하여 작업을 예약 할 때 미리 쿼츠에서 작업 알림을 보내는 방법 작업의 실행 시간은 CRON 표현식에 의해 설정됩니다. 지금...

JavaScript 프로그래밍에서 JavaScript의 프로토 타입 체인에서 함수 매개 변수를 얻는 방법 프로토 타입 체인의 기능 매개 변수를 이해하고 조작하는 방법은 일반적이고 중요한 작업입니다 ...

WeChat 애플릿 웹 뷰에서 vue.js를 사용하는 동적 스타일 변위 실패가 vue.js를 사용하는 이유를 분석합니다.

동시 링크에 대한 요청을 여러 링크와 순서대로 판단하여 결과를 반환하는 방법은 무엇입니까? 탬퍼 몬키 스크립트에서는 종종 여러 체인을 사용해야합니다 ...


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

뜨거운 주제



