forked from dp50mm/chaos-theory-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strange_attractor.html
122 lines (111 loc) · 3.38 KB
/
strange_attractor.html
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
<!DOCTYPE html>
<html>
<head>
<title>Strange Attractor</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.js'></script>
<style>
.svg-container {
width:800px;
height:600px;
margin-top:100px;
margin-left:auto;
margin-right:auto;
}
</style>
<script>
$(document).ready(function() {
console.log('document ready');
/**
* Strange attractor equations
* Javascript object with the equations as parameters
*/
var equations = {
x: function(x, y, a, interval) {
return x - (a * x) * interval + (a * y) * interval;
},
y: function(x, y, z, b, interval) {
return y + (b * x) * interval - y * interval - (z * x) * interval;
},
z: function(x, y, z, c, interval) {
return z - (c * z) * interval + (x * y) * interval;
}
};
/**
* The parameters for the equations
*/
var parameters = {
iterations: 125000,
a: 2.8,
b: 13.9,
c: 0.6,
interval: 0.005,
fn: 1
};
/**
* Setting up the 3d renderer
*/
var WIDTH = 800;
var HEIGHT = 600;
var VIEW_ANGLE = 5;
var ASPECT = WIDTH/HEIGHT;
var NEAR = 0.1;
var FAR = 10000;
var $container = $('.canvas-container');
var renderer = new THREE.WebGLRenderer({ alpha: true });
var camera = new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
var scene = new THREE.Scene();
scene.add(camera);
camera.position.z = 300;
renderer.setSize(WIDTH,HEIGHT);
$container.append(renderer.domElement);
var lineMaterial = new THREE.LineBasicMaterial({
color: new THREE.Color("rgb(0, 0, 0)")
});
/**
* Variables for computation!
*/
var geometry = new THREE.Geometry();
var x = 0.1;
var y = 0.1;
var z = 0.1;
var newX = x;
var newY = y;
var newZ = z;
var minX = minY = minZ = Number.POSITIVE_INFINITY;
var maxX = maxY = maxZ = Number.NEGATIVE_INFINITY;
var a = parameters.a;
var b = parameters.b;
var c = parameters.c;
var interval = parameters.interval;
/**
* Iterate on the equations.
* This is where the chaotic process happens!
* Output feeds back into input.
*/
for(var i = 0; i < parameters.iterations; i++) {
newX = equations.x(x, y, a, interval);
newY = equations.y(x, y, z, b, interval);
newZ = equations.z(x, y, z, c, interval);
geometry.vertices.push(new THREE.Vector3(newX,newY,newZ));
x = newX;
y = newY;
z = newZ;
}
var line = new THREE.Line(geometry, lineMaterial);
scene.add(line);
console.log(scene);
renderer.render(scene, camera);
});
</script>
</head>
<body>
<div class='canvas-container'>
</div>
</body>
</html>