Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const canv = document.querySelector("canvas");
  2. const c = canv.getContext("2d");
  3. canv.height = window.innerHeight;
  4. canv.width = window.innerWidth;
  5.  
  6. let starArr = [];
  7.  
  8. function Stars(x, y, r, color, a) {
  9.     this.x = x;
  10.     this.y = y;
  11.     this.r = r;
  12.     this.color = color;
  13.     this.a = a;
  14.     this.draw = () => {
  15.         c.save();
  16.         c.globalAlpha = this.a;
  17.         c.beginPath();
  18.         c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
  19.         c.fillStyle = this.color;
  20.         c.fill();
  21.         c.restore();
  22.     };
  23.     this.update = () => {
  24.  
  25.         this.draw();
  26.  
  27.     };
  28. }
  29.  
  30.  
  31. function Sun(x, y, r, dx, dy, color, a, blur, blurCol, blurSize) {
  32.     this.x = x;
  33.     this.y = y;
  34.     this.r = r;
  35.     this.dx = dx;
  36.     this.dy = dy;
  37.     this.color = color;
  38.     this.a = a;
  39.     this.blur = blur;
  40.     this.blurCol = blurCol;
  41.     this.blurSize = blurSize;
  42.     this.moveWithWheel = () =>{
  43.  
  44.         console.log(mouse.deltaY);
  45.         if (mouseWheel.deltaY === 1){
  46.             console.log("MOVE UP");
  47.             this.y += mouseWheel.deltaY;
  48.         }
  49.         else if (mouseWheel.deltaY === -1){
  50.             console.log("MOVE DOWN");
  51.             this.y += mouseWheel.deltaY;
  52.  
  53.         }
  54.         else {
  55.             this.x += 0;
  56.         }
  57.         mouse.deltaY = 0;
  58.     };
  59.     this.draw = () => {
  60.         c.save();
  61.         if (this.blur === true) {
  62.             c.shadowColor = this.blurCol;
  63.             c.shadowBlur = this.blurSize;
  64.         }
  65.  
  66.         c.globalAlpha = this.a;
  67.         c.beginPath();
  68.         c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
  69.         c.fillStyle = this.color;
  70.         c.fill();
  71.         c.restore();
  72.     };
  73.     this.update = () => {
  74.  
  75.         // this.moveWithWheel();
  76.         this.draw();
  77.  
  78.     };
  79. }
  80. function Planet(x, y, r,orbit,radians, dx, dy, color, a, blur, blurCol, blurSize,ramp,rampcol1,rampcol2,dis1,dis2) {
  81.     this.x = x;
  82.     this.y = y;
  83.     this.r = r;
  84.     this.orbit = orbit;
  85.     this.radians = radians;
  86.     this.dx = dx;
  87.     this.dy = dy;
  88.     this.color = color;
  89.     this.a = a;
  90.     this.blur = blur;
  91.     this.blurCol = blurCol;
  92.     this.blurSize = blurSize;
  93.     this.ranp= ramp;
  94.     this.rampcol1 = rampcol1;
  95.     this.rampcol2 = rampcol2;
  96.     this.dis1 = dis1;
  97.     this.dis2 = dis2;
  98.     this.draw = () => {
  99.         c.save();
  100.         if (this.blur === true) {
  101.             c.shadowColor = this.blurCol;
  102.             c.shadowBlur = this.blurSize;
  103.         }
  104.         if(this.ranp ===true){
  105.             let planetRamp = c.createLinearGradient(this.x ,this.y,this.x + this.dis1,this.y + this.dis2);
  106.             planetRamp.addColorStop(0,this.rampcol1);
  107.             planetRamp.addColorStop(1,this.rampcol2);
  108.             c.fillStyle = planetRamp;
  109.         }
  110.         else {
  111.             c.fillStyle = this.color;
  112.         }
  113.  
  114.         c.globalAlpha = this.a;
  115.         c.beginPath();
  116.         c.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
  117.  
  118.         c.fill();
  119.         c.restore();
  120.     };
  121.     this.update = () => {
  122.  
  123.         this.radians += this.dx;
  124.         this.x = x +  Math.cos(this.radians) * this.orbit;
  125.         this.y = y +  Math.sin(this.radians) * this.orbit;
  126.         console.log(Math.cos(this.radians));
  127.         // this.moveWithWheel();
  128.         this.draw();
  129.  
  130.     };
  131. }
  132. function Orbit(x, y, r,color,a,w) {
  133.     this.x = x;
  134.     this.y = y;
  135.     this.r = r;
  136.     this.color = color;
  137.     this.a = a;
  138.     this.a = w;
  139.     this.draw = () => {
  140.  
  141.         c.save();
  142.         c.strokeStyle = this.color;
  143.         c.globalAlpha = this.a;
  144.         c.strokeWidth = this.w;
  145.         c.strokeWidth = 20;
  146.         c.arc(this.x, this.y, this-r, 0, 2 * Math.PI);
  147.  
  148.         c.stroke();
  149.         c.restore();
  150.  
  151.     };
  152.     this.update = () => {
  153.  
  154.         this.radians += this.dx;
  155.         this.x = x +  Math.cos(this.radians) * this.orbit;
  156.         this.y = y +  Math.sin(this.radians) * this.orbit;
  157.         console.log(Math.cos(this.radians));
  158.         // this.moveWithWheel();
  159.         this.draw();
  160.  
  161.     };
  162. }
  163.  
  164.  
  165.  
  166.  
  167.  
  168. // stars
  169. for (let i = 0; i < 150; i++) {
  170.     let x, y, r, a;
  171.     x = Math.random() * canv.width;
  172.     y = Math.random() * canv.height;
  173.     r = Math.random() * 1 + 0.1;
  174.     starArr.push(new Stars(x, y, r, "white", 1.0));
  175. }
  176.  
  177. let orbit = new Orbit(200,200,400, "white" , 1, 30);
  178.  
  179.  
  180. //SUN START
  181. let sunCol = c.createLinearGradient(0,100, 300,200);
  182. sunCol.addColorStop(0,"#e67e22");
  183. sunCol.addColorStop(1,"#ffcf4b");
  184. let sungGlare1 = new Sun(100, 100, 240, 0, 0, "#f39c12", 0.5, false);
  185. let sungGlare2 = new Sun(100, 100, 260, 0, 0, "#f39c12", 0.3, false);
  186. let sungGlare3 = new Sun(100, 100, 270, 0, 0, "#f39c12", 0.1, true, "rgba(241, 196, 15, 1.0)", 1000);
  187.  
  188. let sun = new Sun(100, 100, 230, 0, 0, sunCol, 1.0,);
  189. //SUN ENDS
  190.  
  191. //PLANETs START
  192.  
  193. let planet = new Planet(200,200,35,300,0,0.008,0,"white",1.0,0,0,0,true,"#d3623b","#e74c3c",50,10);
  194.  
  195.  
  196. let planet1Ath = new Planet(200,100,55,500,0,0.003,0,"#ffbcd8",0.1,0,0,0,false,"#0eac51","#006c11\n",50,10);
  197. let planet1Ath2 = new Planet(200,100,45,500,0,0.003,0,"#ffbcd8",0.3,0,0,0,false,"#0eac51","#006c11\n",50,10);
  198. let planet1 = new Planet(200,100,40,500,0,0.003,0,"white",1.0,0,0,0,true,"#ea4c88","#ca2c68\n",50,10);
  199.  
  200.  
  201. let planet2Ath = new Planet(200,100,85,800,0,0.001,0,"#39d5ff",0.1,0,0,0,false,"#0eac51","#006c11\n",50,10);
  202. let planet2Ath2 = new Planet(200,100,75,800,0,0.001,0,"#39d5ff",0.3,0,0,0,false,"#0eac51","#006c11\n",50,10);
  203. let planet2 = new Planet(200,100,60,800,0,0.001,0,"white",1.0,0,0,0,true,"#22A7F0","#0067b0\n",50,10);
  204.  
  205.  
  206.  
  207. function main() {
  208.     c.save();
  209.     let grd = c.createRadialGradient(canv.width / 2, canv.height / 2, 5, canv.width / 2,
  210.         canv.height / 2, 1000);
  211.     grd.addColorStop(0, "#05004c");
  212.     grd.addColorStop(1, "#1e003d");
  213.     c.fillStyle = grd;
  214.     c.fillRect(0, 0, canv.width, canv.height);
  215.     c.restore();
  216.  
  217.     let sunGlare = c.createRadialGradient(canv.width / 2 - 750, canv.height / 2 - 370, 5, canv.width / 2,
  218.         canv.height / 2, 860);
  219.     sunGlare.addColorStop(0, "rgba(241, 137, 45, 0.65)");
  220.     sunGlare.addColorStop(1, "rgba(168, 68, 16, 0.0)");
  221.     c.fillStyle = sunGlare;
  222.     c.fillRect(0, 0, canv.width, canv.height);
  223.  
  224.     let test = c.createRadialGradient(canv.width / 2 + 750, canv.height / 2 + 70, 5, canv.width / 2,
  225.         canv.height / 2, 760);
  226.     test.addColorStop(0, "rgba(41, 128, 185, 0.2)");
  227.     test.addColorStop(1, "rgba(168, 68, 16, 0.0)");
  228.     c.fillStyle = test;
  229.     c.fillRect(0, 0, canv.width, canv.height);
  230.  
  231.  
  232.     for (let k = 0; k < starArr.length; k++) {
  233.         starArr[k].update();
  234.  
  235.     }
  236.     sungGlare1.update();
  237.     sungGlare2.update();
  238.     sungGlare3.update();
  239.     sun.update();
  240.  
  241.     planet.update();
  242.  
  243.     planet1Ath.update();
  244.     planet1Ath2.update();
  245.     planet1.update();
  246.  
  247.     planet2Ath.update();
  248.     planet2Ath2.update();
  249.     planet2.update();
  250.  
  251.  
  252.     requestAnimationFrame(main);
  253.  
  254.  
  255. }
  256.  
  257. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement