Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const canv = document.querySelector("canvas");
- const c = canv.getContext("2d");
- canv.height = window.innerHeight;
- canv.width = window.innerWidth;
- let starArr = [];
- function Stars(x, y, r, color, a) {
- this.x = x;
- this.y = y;
- this.r = r;
- this.color = color;
- this.a = a;
- this.draw = () => {
- c.save();
- c.globalAlpha = this.a;
- c.beginPath();
- c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
- c.fillStyle = this.color;
- c.fill();
- c.restore();
- };
- this.update = () => {
- this.draw();
- };
- }
- function Sun(x, y, r, dx, dy, color, a, blur, blurCol, blurSize) {
- this.x = x;
- this.y = y;
- this.r = r;
- this.dx = dx;
- this.dy = dy;
- this.color = color;
- this.a = a;
- this.blur = blur;
- this.blurCol = blurCol;
- this.blurSize = blurSize;
- this.moveWithWheel = () =>{
- console.log(mouse.deltaY);
- if (mouseWheel.deltaY === 1){
- console.log("MOVE UP");
- this.y += mouseWheel.deltaY;
- }
- else if (mouseWheel.deltaY === -1){
- console.log("MOVE DOWN");
- this.y += mouseWheel.deltaY;
- }
- else {
- this.x += 0;
- }
- mouse.deltaY = 0;
- };
- this.draw = () => {
- c.save();
- if (this.blur === true) {
- c.shadowColor = this.blurCol;
- c.shadowBlur = this.blurSize;
- }
- c.globalAlpha = this.a;
- c.beginPath();
- c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
- c.fillStyle = this.color;
- c.fill();
- c.restore();
- };
- this.update = () => {
- // this.moveWithWheel();
- this.draw();
- };
- }
- function Planet(x, y, r,orbit,radians, dx, dy, color, a, blur, blurCol, blurSize,ramp,rampcol1,rampcol2,dis1,dis2) {
- this.x = x;
- this.y = y;
- this.r = r;
- this.orbit = orbit;
- this.radians = radians;
- this.dx = dx;
- this.dy = dy;
- this.color = color;
- this.a = a;
- this.blur = blur;
- this.blurCol = blurCol;
- this.blurSize = blurSize;
- this.ranp= ramp;
- this.rampcol1 = rampcol1;
- this.rampcol2 = rampcol2;
- this.dis1 = dis1;
- this.dis2 = dis2;
- this.draw = () => {
- c.save();
- if (this.blur === true) {
- c.shadowColor = this.blurCol;
- c.shadowBlur = this.blurSize;
- }
- if(this.ranp ===true){
- let planetRamp = c.createLinearGradient(this.x ,this.y,this.x + this.dis1,this.y + this.dis2);
- planetRamp.addColorStop(0,this.rampcol1);
- planetRamp.addColorStop(1,this.rampcol2);
- c.fillStyle = planetRamp;
- }
- else {
- c.fillStyle = this.color;
- }
- c.globalAlpha = this.a;
- c.beginPath();
- c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
- c.fill();
- c.restore();
- };
- this.update = () => {
- this.radians += this.dx;
- this.x = x + Math.cos(this.radians) * this.orbit;
- this.y = y + Math.sin(this.radians) * this.orbit;
- console.log(Math.cos(this.radians));
- // this.moveWithWheel();
- this.draw();
- };
- }
- function Orbit(x, y, r,color,a,w) {
- this.x = x;
- this.y = y;
- this.r = r;
- this.color = color;
- this.a = a;
- this.a = w;
- this.draw = () => {
- c.save();
- c.strokeStyle = this.color;
- c.globalAlpha = this.a;
- c.strokeWidth = this.w;
- c.strokeWidth = 20;
- c.arc(this.x, this.y, this-r, 0, 2 * Math.PI);
- c.stroke();
- c.restore();
- };
- this.update = () => {
- this.radians += this.dx;
- this.x = x + Math.cos(this.radians) * this.orbit;
- this.y = y + Math.sin(this.radians) * this.orbit;
- console.log(Math.cos(this.radians));
- // this.moveWithWheel();
- this.draw();
- };
- }
- // stars
- for (let i = 0; i < 150; i++) {
- let x, y, r, a;
- x = Math.random() * canv.width;
- y = Math.random() * canv.height;
- r = Math.random() * 1 + 0.1;
- starArr.push(new Stars(x, y, r, "white", 1.0));
- }
- let orbit = new Orbit(200,200,400, "white" , 1, 30);
- //SUN START
- let sunCol = c.createLinearGradient(0,100, 300,200);
- sunCol.addColorStop(0,"#e67e22");
- sunCol.addColorStop(1,"#ffcf4b");
- let sungGlare1 = new Sun(100, 100, 240, 0, 0, "#f39c12", 0.5, false);
- let sungGlare2 = new Sun(100, 100, 260, 0, 0, "#f39c12", 0.3, false);
- let sungGlare3 = new Sun(100, 100, 270, 0, 0, "#f39c12", 0.1, true, "rgba(241, 196, 15, 1.0)", 1000);
- let sun = new Sun(100, 100, 230, 0, 0, sunCol, 1.0,);
- //SUN ENDS
- //PLANETs START
- let planet = new Planet(200,200,35,300,0,0.008,0,"white",1.0,0,0,0,true,"#d3623b","#e74c3c",50,10);
- let planet1Ath = new Planet(200,100,55,500,0,0.003,0,"#ffbcd8",0.1,0,0,0,false,"#0eac51","#006c11\n",50,10);
- let planet1Ath2 = new Planet(200,100,45,500,0,0.003,0,"#ffbcd8",0.3,0,0,0,false,"#0eac51","#006c11\n",50,10);
- let planet1 = new Planet(200,100,40,500,0,0.003,0,"white",1.0,0,0,0,true,"#ea4c88","#ca2c68\n",50,10);
- let planet2Ath = new Planet(200,100,85,800,0,0.001,0,"#39d5ff",0.1,0,0,0,false,"#0eac51","#006c11\n",50,10);
- let planet2Ath2 = new Planet(200,100,75,800,0,0.001,0,"#39d5ff",0.3,0,0,0,false,"#0eac51","#006c11\n",50,10);
- let planet2 = new Planet(200,100,60,800,0,0.001,0,"white",1.0,0,0,0,true,"#22A7F0","#0067b0\n",50,10);
- function main() {
- c.save();
- let grd = c.createRadialGradient(canv.width / 2, canv.height / 2, 5, canv.width / 2,
- canv.height / 2, 1000);
- grd.addColorStop(0, "#05004c");
- grd.addColorStop(1, "#1e003d");
- c.fillStyle = grd;
- c.fillRect(0, 0, canv.width, canv.height);
- c.restore();
- let sunGlare = c.createRadialGradient(canv.width / 2 - 750, canv.height / 2 - 370, 5, canv.width / 2,
- canv.height / 2, 860);
- sunGlare.addColorStop(0, "rgba(241, 137, 45, 0.65)");
- sunGlare.addColorStop(1, "rgba(168, 68, 16, 0.0)");
- c.fillStyle = sunGlare;
- c.fillRect(0, 0, canv.width, canv.height);
- let test = c.createRadialGradient(canv.width / 2 + 750, canv.height / 2 + 70, 5, canv.width / 2,
- canv.height / 2, 760);
- test.addColorStop(0, "rgba(41, 128, 185, 0.2)");
- test.addColorStop(1, "rgba(168, 68, 16, 0.0)");
- c.fillStyle = test;
- c.fillRect(0, 0, canv.width, canv.height);
- for (let k = 0; k < starArr.length; k++) {
- starArr[k].update();
- }
- sungGlare1.update();
- sungGlare2.update();
- sungGlare3.update();
- sun.update();
- planet.update();
- planet1Ath.update();
- planet1Ath2.update();
- planet1.update();
- planet2Ath.update();
- planet2Ath2.update();
- planet2.update();
- requestAnimationFrame(main);
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement