Animated Globe
A globe component styled with customizations, created using the Cobe library for interactive, 3D globe visuals
A globe component styled with customizations, created using the Cobe library for interactive, 3D globe visuals
To Get the sparkle code Please Click That Link here
npm install cobe
1'use client';2import React, { useEffect, useRef, useState } from 'react';3import createGlobe from 'cobe';4import { cn } from '@/lib/utils';5interface EarthProps {6className?: string;7theta?: number;8dark?: number;9scale?: number;10diffuse?: number;11mapSamples?: number;12mapBrightness?: number;13baseColor?: [number, number, number];14markerColor?: [number, number, number];15glowColor?: [number, number, number];16}17const Earth: React.FC<EarthProps> = ({18className,19theta = 0.25,20dark = 1,21scale = 1.1,22diffuse = 1.2,23mapSamples = 40000,24mapBrightness = 6,25baseColor = [0.4, 0.6509, 1],26markerColor = [1, 0, 0],27glowColor = [0.2745, 0.5765, 0.898],28}) => {29const canvasRef = useRef<HTMLCanvasElement>(null);3031useEffect(() => {32let width = 0;33const onResize = () =>34canvasRef.current && (width = canvasRef.current.offsetWidth);35window.addEventListener('resize', onResize);36onResize();37let phi = 0;3839onResize();40const globe = createGlobe(canvasRef.current!, {41devicePixelRatio: 2,42width: width * 2,43height: width * 2,44phi: 0,45theta: theta,46dark: dark,47scale: scale,48diffuse: diffuse,49mapSamples: mapSamples,50mapBrightness: mapBrightness,51baseColor: baseColor,52markerColor: markerColor,53glowColor: glowColor,54opacity: 1,55offset: [0, 0],56markers: [57// longitude latitude58],59onRender: (state: Record<string, any>) => {60// Called on every animation frame.61// `state` will be an empty object, return updated params.\62state.phi = phi;63phi += 0.003;64},65});6667return () => {68globe.destroy();69};70}, []);7172return (73<div74className={cn(75'flex items-center justify-center z-[10] w-full max-w-[350px] mx-auto',76className77)}78>79<canvas80ref={canvasRef}81style={{82width: '100%',83height: '100%',84maxWidth: '100%',85aspectRatio: '1',86}}87/>88</div>89);90};9192export default Earth;
Prop | Type | Default | Description |
---|---|---|---|
className | string | undefined | Optional CSS class for styling the Earth component. |
theta | number | 0.25 | Controls the rotational angle of the Earth. |
dark | number | 1 | Controls the darkness level of the Earth. |
scale | number | 1.1 | Controls the scaling factor of the Earth. |
diffuse | number | 1.2 | Controls the diffuse light intensity of the Earth. |
mapSamples | number | 40000 | The number of samples used for the map texture. |
mapBrightness | number | 6 | The brightness of the map texture. |
baseColor | [number, number, number] | [0.4, 0.6509, 1] | The base color of the Earth as an RGB array. |
markerColor | [number, number, number] | [1, 0, 0] | The color of the markers on the Earth as an RGB array. |
glowColor | [number, number, number] | [0.2745, 0.5765, 0.898] | The color of the glow effect on the Earth as an RGB array. |