code a space scene in js

Solutions on MaxInterview for code a space scene in js by the best coders in the world

showing results for - "code a space scene in js"
Emily
16 Jan 2020
1//{
2var OuterSpace = function(){
3var s = 300;
4var v = 100;
5var n = 200;
6var w = 10;
7var r = 30;
8var U = 100;
9var keys = [];
10keyPressed = function(){
11    keys[keyCode] = true;
12};
13keyReleased = function(){
14    keys[keyCode] = false;
15};
16
17var Background = function(){
18var color1 = color(122, 122, 122);
19var color2 = color(31, 34, 46);
20for (var i = 0; i < width; i++) {
21    stroke(lerpColor(color1, color2, i / width));
22    line(-5, i, 600, i);
23}
24
25};
26var MovingStars = function(){
27noStroke();
28fill(184, 184, 184);
29ellipse(v,random(200,400),w,15);
30ellipse(s,random(200,501),w,15);
31ellipse(v,random(200,300),w,15);
32ellipse(s,random(229,200),w,15);
33ellipse(v,random(360,250),w,15);
34ellipse(s,random(200,20),w,15);
35ellipse(v,random(200,0),w,15);
36ellipse(s,random(552,200),w,15);
37ellipse(v,random(200,200),w,15);
38ellipse(s,random(200,200),15,15);
39ellipse(v,random(430,200),15,15);
40ellipse(s,random(278,200),15,15);
41ellipse(v,random(200,200),15,15);
42ellipse(s,random(200,200),15,15);
43ellipse(v,random(200,200),15,15);
44ellipse(s,random(200,200),15,15);
45ellipse(v,random(200,200),15,15);
46ellipse(s,random(200,200),15,15);
47ellipse(v,random(200,200),15,15);
48ellipse(s,random(200,200),15,15);
49};
50var Stars = function(){
51for(var s = 0; s < 400; s++){
52        fill(255, 255, 255);
53        ellipse(random(0, 400), random(0, 400), 5, 5);
54}
55};
56draw = function() {
57    s-=0.87;
58    v-=0.87;
59    n-=0.87;
60    w+=0.03;
61    if(mouseIsPressed){
62        Program.restart();
63    }
64  
65Background();
66MovingStars();
67Stars();
68};
69};
70mouseClicked = function() {
71    OuterSpace();
72};
73//}
74
75//All the code
76