Skip to content

Commit 7f26166

Browse files
author
Andrea Bianco
committedOct 28, 2014
starting version
1 parent a181dfb commit 7f26166

File tree

6 files changed

+11459
-0
lines changed

6 files changed

+11459
-0
lines changed
 

‎README.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is a readme file

‎lib/.DS_Store

6 KB
Binary file not shown.

‎lib/giocovita.js

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
'use strict';
2+
var PlayGround ={
3+
initGrid : function(N) {
4+
if(N>1){
5+
this.N=N;
6+
for (var i = 0; i < N; i++) {
7+
this.grid[i] = [];
8+
for (var j = 0; j < N; j++) {
9+
this.grid[i][j] = false;
10+
}
11+
12+
}
13+
this.isgridset=true;
14+
return true;
15+
}else {
16+
this.isgridset=false;
17+
return false;
18+
}
19+
20+
},
21+
22+
23+
setSeed : function() {
24+
var h = Math.floor(this.N / 2);
25+
var l=29;
26+
if(h>3){
27+
this.grid[h][h - 1] = true;
28+
this.grid[h][h] = true;
29+
this.grid[h][h + 1] = true;
30+
this.grid[h - 1][h] = true;
31+
this.grid[h + 1][h - 1] = true;
32+
33+
this.grid[h + 10][h - 10] = true;
34+
this.grid[h + 11][h - 10] = true;
35+
this.grid[h + 11][h - 9] = true;
36+
//this.grid[h + 11][h - 11] = true;
37+
this.grid[h + 12][h - 10] = true;
38+
39+
this.grid[l+2][l + 11] = true;
40+
this.grid[l+2][l + 10] = true;
41+
this.grid[l+2][l + 9] = true;
42+
this.grid[l+3][l + 9] = true;
43+
this.grid[l+3][l + 12] = true;
44+
this.grid[l+4][l + 9] = true;
45+
this.grid[l+5][l + 9] = true;
46+
this.grid[l+6][l + 10] = true;
47+
this.grid[l+6][l + 12] = true;
48+
49+
50+
51+
this.isseedset=true;
52+
return true;
53+
}else {
54+
this.isseedset=false;
55+
return false;
56+
}
57+
},
58+
59+
step: function() {
60+
var iminus,iplus,jminus,jplus;
61+
var gridold = [];
62+
for (var i = 0; i < this.grid.length; i++)
63+
gridold[i] = this.grid[i].slice();
64+
65+
var neighbours = 0;
66+
if(this.isgridset && this.isseedset){
67+
for (var i = 0; i < this.N ; i++) {
68+
for (var j = 0; j < this.N ; j++) {
69+
neighbours = 0;
70+
//this.grid[i][j]=false;
71+
//check the neighbours
72+
73+
74+
//periodic boundary condition
75+
if(i===0){
76+
iminus=this.N-1;
77+
78+
iplus=i +1;
79+
}else if(i===this.N-1){
80+
iminus=i - 1;
81+
82+
iplus=0;
83+
}else{
84+
iminus=i - 1;
85+
86+
iplus=i +1;
87+
}
88+
89+
if(j===0){
90+
jminus=this.N-1;
91+
92+
jplus=j +1;
93+
}else if(j===this.N-1){
94+
jminus=j - 1;
95+
96+
jplus=0;
97+
}else{
98+
jminus=j - 1;
99+
100+
jplus=j +1;
101+
}
102+
103+
if (gridold[iminus][jminus]) neighbours++;
104+
if (gridold[i][jminus]) neighbours++;
105+
if (gridold[iplus][jminus]) neighbours++;
106+
107+
if (gridold[iminus][j]) neighbours++;
108+
if (gridold[iplus][j]) neighbours++;
109+
110+
if (gridold[iminus][jplus]) neighbours++;
111+
if (gridold[i][jplus]) neighbours++;
112+
if (gridold[iplus][jplus]) neighbours++;
113+
114+
//cell survives if it has 2 or 3 neighbours
115+
//cell is born if it has 3 neighbours
116+
//Otherwise, a cell dies or remains dead
117+
//if(neighbours>1) console.log(neighbours)
118+
119+
if(neighbours===3){
120+
this.grid[i][j]=true;
121+
//console.log(i,j)
122+
}else if((neighbours === 2) && gridold[i][j] ){ this.grid[i][j]=true;
123+
}else{
124+
this.grid[i][j]=false;
125+
}
126+
}
127+
}
128+
}
129+
}
130+
};
131+
132+
var PlayGround_property = {
133+
N:{
134+
value: 40,
135+
writable:true
136+
},
137+
grid:{
138+
value: [],
139+
writable:true
140+
},
141+
142+
isgridset:{
143+
value: false,
144+
writable:true
145+
},
146+
isseedset:{
147+
value: false,
148+
writable:true
149+
}
150+
151+
}

‎lib/jquery-1.11.1.js

+10,308
Large diffs are not rendered by default.

‎lib/three.min.js

+827
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/visual3d.js

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
'use strict';
2+
var visualGlob ={
3+
//N of boards, size of the cube, string with the ID of the container
4+
preInit: function(N_in,step) {
5+
6+
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 10, 5000);
7+
8+
this.camera.position.x = 200;
9+
this.camera.position.y = 500;
10+
// Grid
11+
var size = N_in * Math.floor(step/2);
12+
//var step = 50;
13+
14+
this.linegeometry = new THREE.Geometry();
15+
16+
for (var i = -size; i <= size; i += step) {
17+
this.linegeometry.vertices.push(new THREE.Vector3(-size, 0, i));
18+
this.linegeometry.vertices.push(new THREE.Vector3(size, 0, i));
19+
20+
this.linegeometry.vertices.push(new THREE.Vector3(i, 0, -size));
21+
this.linegeometry.vertices.push(new THREE.Vector3(i, 0, size));
22+
}
23+
24+
this.linematerial = new THREE.LineBasicMaterial({
25+
color: 0x000000,
26+
opacity: 0.2
27+
});
28+
// Cubes
29+
this.cubegeometry = new THREE.BoxGeometry(step, step, step);
30+
this.cubematerial = new THREE.MeshLambertMaterial({
31+
color: 0xffffff,
32+
shading: THREE.FlatShading,
33+
overdraw: true
34+
});
35+
36+
37+
38+
39+
40+
// Lights
41+
42+
this.ambientLight = new THREE.AmbientLight(Math.random() * 0x10);
43+
this.directionalLight = new THREE.DirectionalLight(Math.random() * 0xffffff);
44+
this.directionalLight.position.x = Math.random() - 0.5;
45+
this.directionalLight.position.y = Math.random() - 0.5;
46+
this.directionalLight.position.z = Math.random() - 0.5;
47+
this.directionalLight.position.normalize();
48+
this.renderer = new THREE.WebGLRenderer();
49+
this.renderer.setClearColor(0xeeeeee, 1);
50+
this.renderer.setSize(window.innerWidth, window.innerHeight);
51+
52+
53+
54+
55+
},
56+
57+
buildScene: function(board,step) {
58+
this.scene = new THREE.Scene();
59+
var sceneline = new THREE.Line(this.linegeometry, this.linematerial,THREE.LinePieces);
60+
this.scene.add(sceneline);
61+
var halfStep=Math.floor(step/2);
62+
for (var i = 0; i < board.N; i++) {
63+
for (var j = 0; j < board.N; j++) {
64+
if (board.grid[i][j] === true) {
65+
var cube = new THREE.Mesh(this.cubegeometry, this.cubematerial);
66+
cube.scale.y = 1;
67+
68+
cube.position.x = i * step - board.N *halfStep + halfStep
69+
cube.position.y = halfStep;
70+
cube.position.z = j * step - board.N *halfStep + halfStep;
71+
72+
this.scene.add(cube);
73+
}
74+
}
75+
}
76+
this.scene.add(this.ambientLight);
77+
this.scene.add(this.directionalLight);
78+
},
79+
80+
81+
82+
render: function(timeFrame,board) {
83+
84+
if (Date.now() - this.lastStep > timeFrame) {
85+
//console.log(this.lastStep);
86+
board.step();
87+
this.lastStep = Date.now();
88+
89+
this.buildScene(board,50);
90+
91+
}
92+
var timer = Date.now() * 0.00005;
93+
94+
timer += this.mouseX * 0.001;
95+
96+
this.camera.position.x = Math.cos(timer) * 2000;
97+
this.camera.position.z = Math.sin(timer) * 2000;
98+
this.camera.position.y += (-this.mouseY - this.camera.position.y) * 1 + 1000;
99+
this.camera.lookAt(this.scene.position);
100+
101+
this.directionalLight.position.x = this.camera.position.x;
102+
this.directionalLight.position.y = this.camera.position.y;
103+
this.directionalLight.position.z = this.camera.position.z;
104+
this.directionalLight.position.normalize();
105+
106+
this.renderer.render(this.scene, this.camera);
107+
}
108+
109+
}
110+
111+
var visualGlob_property = {
112+
container :{
113+
value: {},
114+
writable: true
115+
},
116+
camera:{
117+
value: {},
118+
writable: true
119+
},
120+
scene :{
121+
value: {},
122+
writable: true
123+
},
124+
renderer :{
125+
value: {},
126+
writable: true
127+
},
128+
directionalLight :{
129+
value: {},
130+
writable: true
131+
},
132+
cubegeometry :{
133+
value: {},
134+
writable: true
135+
},
136+
cubematerial :{
137+
value: {},
138+
writable: true
139+
},
140+
linegeometry :{
141+
value: {},
142+
writable: true
143+
},
144+
linematerial :{
145+
value: {},
146+
writable: true
147+
},
148+
ambientLight :{
149+
value: {},
150+
writable: true
151+
},
152+
lastStep :{
153+
value: 0,
154+
writable: true
155+
},
156+
mouseX:{
157+
value: 0,
158+
writable: true
159+
},
160+
mouseY:{
161+
value: 0,
162+
writable: true
163+
},
164+
windowHalfX:{
165+
value: window.innerWidth / 2,
166+
writable: true
167+
},
168+
windowHalfY:{
169+
value: window.innerHeight / 2,
170+
writable: true
171+
},
172+
}

0 commit comments

Comments
 (0)
Please sign in to comment.