This commit is contained in:
Dym Sohin 2023-08-06 23:47:49 +02:00
commit 3cff0a6c3f
7 changed files with 112 additions and 0 deletions

6
index.html Normal file
View File

@ -0,0 +1,6 @@
<link rel='stylesheet' href='./style.css'>
<canvas width='1000' height='1000'></canvas>
<script src='./vendor/zdog.js'></script>
<script defer src='./script.js'></script>

15
meta.kdl Normal file
View File

@ -0,0 +1,15 @@
title "rainbow-star-cluster"
description "random distribution of colored dots in 3D"
media-type "webview"
tags "visualization" "colors"
license "AGPL"
homepage "https://dym.sh/rainbow-star-cluster/"
source "https://source.garden/vis/rainbow-star-cluster/"
mirrors {
codepen "https://codepen.io/dym-sh/pen/abmovpP"
}
log {
init 2019
}

10
readme.md Normal file
View File

@ -0,0 +1,10 @@
# rainbow-star-cluster
> random distribution of colored dots in 3D
## preview
- https://codepen.io/dym-sh/pen/abmovpP/left/?editors=0010
- https://dym.sh/rainbow-star-cluster/
![thumbnail](./th.png)

50
script.js Normal file
View File

@ -0,0 +1,50 @@
const rand = ( min, max ) =>
( undefined == max )
? ( Math.random() * min )
: ( Math.random() * (max - min) + min )
const starCount = 2400
, maxRaduis = 500
let canvas = document.querySelector('canvas')
, starGroup
, stars = [ ]
ill = new Zdog.Illustration
({ element: canvas
, dragRotate: true
})
starGroup = new Zdog.Group({ addTo: ill })
for( let i = 1; i < starCount; i++ )
{ const R = rand( maxRaduis )
, F = rand( 2 * Math.PI )
, T = rand( Math.PI )
, x = R * Math.sin( F ) * Math.cos( T )
, y = R * Math.sin( F ) * Math.sin( T )
, z = R * Math.cos( F )
, stroke = ( maxRaduis - R ) / 25 + 5
, Hue = R * 360 / maxRaduis - 60
, color = `hsl(${Hue}, 100%, 50%)`
stars.push({ shape: new Zdog.Shape(
{ addTo: starGroup
, translate: { x, y, z }
, stroke
, color
})
})
}
const animate = ( ) =>
{ starGroup.rotate.y += 0.001
starGroup.rotate.x -= 0.001
starGroup.rotate.z -= 0.001
ill.updateRenderGraph( )
window.requestAnimationFrame( animate )
}
animate( )

23
style.css Normal file
View File

@ -0,0 +1,23 @@
html
, body
{ height : 100%
; display : block
}
body
{ align-items : center
; background : black
; display : flex
; overflow : hidden
; justify-content : center
; padding : 1rem
}
canvas
{ background : black
; cursor : grab
; display : block
}
canvas:active
{ cursor : grabbing }

BIN
th.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

8
vendor/zdog.js vendored Normal file

File diff suppressed because one or more lines are too long