xxxxxxxxxx
let starVectors = [];
let starArcCosD = [];
let starArcSinD = [];
let starColorIndices = [];
let starStrokeWeights = [];
let starBrightnessScale = 2;
let starMinStroke = 2;
var box1;
let starCycleLength = 240;
let modelEarthRad = 5;
let starList = [];
let starCount = 300;
let skyBoxSize = 20;
let debug = false;
let drawRealStars = false;
let drawRealStarArcs = true;
let realStarMax = 300;
// North Pole
// let viewerLatitude = 0.5*3.1415926535897;//30.274693*3.1415926535897/180;
// let viewerLongitude = 0;//-97.740436*3.1415926535897/180;
// 64.174392,-51.7379282 (Nuuk, Greenland)
// let viewerLatitude = 64.174392*3.1415926535897/180;
// let viewerLongitude = -51.7379282*3.1415926535897/180;
//61.177143,-150.129248 (Anchorage Intl. Airport)
// let viewerLatitude = 61.177143*3.1415926535897/180;
// let viewerLongitude = -150.129248*3.1415926535897/180;
//30.274693, -97.740436 (Texas Capitol)
let viewerLatitude = 30.274693*3.1415926535897/180;
let viewerLongitude = -97.740436*3.1415926535897/180;
//Null Island (0,0)
// let viewerLatitude = 0;
// let viewerLongitude = 0;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
ellipseMode(RADIUS);
rectMode(CORNERS);
// strokeCap(PROJECT);// Not yet implemented in WEBGL
perspective(PI*1/3, width/height, 0.1, 5000);
noiseDetail(3, 0.25);
img = loadImage('Kitty1B.png');
camDist = 30;
cameraPitch = PI/7;
angle = PI*5/3;
deviation = 0.0;
lapseAngle = PI*0.1;
box1 = new Box(-10,-10,-10,10,10,10);
hourVal = random(-PI,PI);
skyRotationRate = 0.001;
noiseScale = 0;
arcDetail = ceil(min(lapseAngle*30,50));
viewerCoordinate = new p5.Vector(modelEarthRad);
starList.forEach(s => {
let vCoord = new p5.Vector(cos(s.rAsc)*cos(s.decl), -sin(s.decl), -sin(s.rAsc)*cos(s.decl));
vCoord.mult(skyBoxSize); starVectors.push(vCoord);
let oldColor = spectralPalette.find((elem,index) => elem.spectralType === s.spec).hexColor;
[newColor, newStrokeWeight] = getStarDrawParamsFrom(oldColor, s.vMag, starBrightnessScale, starMinStroke);
starColorIndices.push(newColor);
starStrokeWeights.push(newStrokeWeight);
starArcCosD.push(skyBoxSize*(1+(s.vMag+1.46)*0.01)*cos(s.decl));
starArcSinD.push(-skyBoxSize*(1+(s.vMag+1.46)*0.01)*sin(s.decl));
});
}
function draw() {
background(0);
let noiseXConst = cos(frameCount*TAU/starCycleLength);
let noiseYConst = sin(frameCount*TAU/starCycleLength);
hourVal += skyRotationRate;
let cameraAngle = angle;
angle += deviation;
let p = new p5.Vector(0, 0, 0);
let c = new p5.Vector(
camDist*cos(cameraPitch)*sin(-cameraAngle),
camDist*sin(-cameraPitch),
camDist*cos(cameraPitch)*cos(-cameraAngle)
);
let u = new p5.Vector(0, 1, 0);
noFill();
if (debug) {
vectorCamera(c, p, u);// camera offset
stroke(255,0,0);
line(0,0,0,5,0,0);
stroke(0,255,0);
line(0,0,0,0,5,0);
stroke(0,0,255);
line(0,0,0,0,0,5);
} else {
vectorCamera(p, c, u);// camera centered
}
if (drawRealStars || drawRealStarArcs) {
push();
rotateX(HALF_PI-viewerLatitude);// rotate the sky so the North pole is at (0,1,0)
rotateY(-viewerLongitude);
noFill();
rotateX(-HALF_PI);// rotate the sky so the North pole aligns with the stars
for (let i = 0; i < realStarMax; i++) {
push();
translate(0,0,starArcSinD[i]);
rotateZ(noiseScale*noise(noiseXConst+i+10.5,noiseYConst+i+30.5)+starList[i].rAsc-hourVal);
stroke(starColorIndices[i]);
if (drawRealStarArcs) {
strokeWeight(starStrokeWeights[i]*0.5);
arc(0, 0, starArcCosD[i], starArcCosD[i], 0, lapseAngle, OPEN, arcDetail);
// point(starArcCosD[i],0,0);
// point(starArcCosD[i]*cos(lapseAngle),starArcCosD[i]*sin(lapseAngle),0);
}
if (drawRealStars) {
strokeWeight(starStrokeWeights[i]);
point(starArcCosD[i],0,0);
}
pop();
}
pop();
}
// noFill();
// stroke(40);
// strokeWeight(1);
// rect(-10,-10,10,10);
if (!debug) {
push();
translate(0,0.1,0);
rotateX(-HALF_PI);
fill(40);
ellipse(0,0,skyBoxSize,skyBoxSize,20);
pop();
}
stroke(40);
push();
translate(0,modelEarthRad+0.1,0);
rotateX(HALF_PI-viewerLatitude);
sphere(modelEarthRad);
pop();
if (debug) {
push();
rotateX(HALF_PI-viewerLatitude);
rotateY(-hourVal);
sphere(skyBoxSize);
pop();
}
/*
push();
// noStroke();
fill(255);
vectorTranslate(c);
box1.show();
pop();
/**/
// texture(img);
// push();
// translate(c);
// rotateX(-cameraPitch);
// let scaleImg = 1.43;
// rect(-64*scaleImg,-36*scaleImg,128*scaleImg,72*scaleImg);
// pop();
}
function keyPressed() {
// if (key === 's') {
// saveGif('mySketch', 240, {units: 'frames'});
// }
}