window.addEventListener("load", windowLoadHandler, false);
let sphereRad = 280; // радиус
let scale = 1; // масштаб
function windowLoadHandler() {
canvasApp();
}
function canvasApp() {
let theCanvas = document.getElementById("sphere");
let sphere_wrap = document.getElementById("sphere-wrap");
let context = theCanvas.getContext("2d");
let displayWidth;
let displayHeight;
let timer;
let wait;
let count;
let numToAddEachFrame;
let particleList;
let recycleBin;
let particleAlpha;
let fLen;
let m;
let projCenterX;
let projCenterY;
let zMax;
let turnAngle;
let turnSpeed;
let sphereCenterX, sphereCenterY, sphereCenterZ;
let particleRad;
let zeroAlphaDepth;
let randAccelX, randAccelY, randAccelZ;
let gravity;
let rgbString;
let p;
let outsideTest;
let nextParticle;
let sinAngle;
let cosAngle;
let rotX, rotZ;
let depthAlphaFactor;
let i;
let theta, phi;
let x0, y0, z0;
init();
window.addEventListener('resize', init, false);
function init() {
wait = 1;
count = wait - 1;
numToAddEachFrame = 8;
rgbString = "rgba(169,195,238,"; // цвет частиц
particleAlpha = 1;
displayWidth = theCanvas.width = sphere_wrap.offsetWidth;
displayHeight = theCanvas.height = sphere_wrap.offsetHeight;
fLen = 320;
projCenterX = displayWidth / 3; // центр сферы по оси X
projCenterY = displayHeight / 2; // центр сферы по оси Y
zMax = fLen - 2;
particleList = {};
recycleBin = {};
randAccelX = 0.1;
randAccelY = 0.1;
randAccelZ = 0.1;
gravity = -0;
particleRad = 2.5; // размер частиц
sphereCenterX = 0;
sphereCenterY = 0;
sphereCenterZ = -3 - sphereRad;
zeroAlphaDepth = -750;
turnSpeed = 2 * Math.PI / 1200; // скорость вращения сферы
turnAngle = 0;
timer = setInterval(onTimer, 10 / 24);
}
function onTimer() {
count++;
if (count >= wait) {
count = 0;
for (i = 0; i < numToAddEachFrame; i++) {
theta...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.