-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
122 lines (97 loc) · 2.07 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var obj;
let stars = [];
var speed;
let cam;
let arah=0;
let camX= 0.00;
let camY= 0.00;
var button;
function preload() {
obj = loadModel('rocket.obj');
}
function setup() {
createCanvas(800, 600, WEBGL);
colorMode(HSB);
for (var i = 0; i < 50; i++) {
stars[i] = new Star();
}
}
function rotasi(callback){
callback();
}
function draw() {
background(0);
scale(0.3);
ambientMaterial(250);
push();
camera(camX,camY,(height/2)/tan(PI/6), 0, 0, 0, 0, 1, 0);
push();
translate(width/2,height/2);
for (var i = 0; i < 50; i++) {
stars[i].update();
stars[i].show();
}
pop();
push();
normalMaterial();
translate(mouseX,mouseY);
rotateX(70);
rotateZ(10);
rotasi(keyPressed);
model(obj);
}
function Star()
{
this.x = random(-width,width);
this.y = random(-height,height);
this.z = random(width);
this.hu = random(255);
this.pz = this.z;
this.update = function (){
this.z = this.z-7;
if (this.z < 1){
this.z = width;
this.x = random(-width,width);
this.y = random(-height,height);
}
}
this.show = function(){
strokeWeight(2);
stroke(this.hu,255,255,255);
this.sx = map(this.x/this.z,0,1,0,width);
this.sy = map(this.y/this.z,0,1,0,height)
this.r = map(this.z,0,width,20,0);
ellipse(this.sx,this.sy,this.r,this.r);
/*this.px = map(this.x/this.pz,0,0.01,0,width);
this.py = map(this.y/this.pz,0,0.01,0,height);
line(this.px,this.py,this.sx,this.sy);
*/
}
}
function keyPressed() {
switch (keyCode) {
case LEFT_ARROW :
rotateY(arah);
arah+=0.03;
break;
case RIGHT_ARROW :
rotateY(-arah);
arah+=0.03;
break;
}
}
function keyTyped() {
if (key === 'w') {
camY+=50;
} else if (key === 's') {
camY+=-50;
}
else if (key === 'a') {
camX+=-50;
}
else if (key === 'd') {
camX+=50;
}
// uncomment to prevent any default behavior
// return false;
}