Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·151 lines (125 loc) · 4.32 KB
/
Copy pathscript.js
File metadata and controls
executable file
·151 lines (125 loc) · 4.32 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var refresh = 60000; // 1 min, the fastest current.json will update
var stonksplainerVisible = false;
var threshholds = {
"NONE": [-Infinity, 0],
"LOW": [0.01, 0.7],
"MEDIUM": [0.71, 1],
"HIGH": [1.01, 1.5],
"INSANE": [1.51, Infinity]
};
var shakes = {
"NONE": "",
"LOW": "shake-little",
"MEDIUM": "shake",
"HIGH": "shake-hard",
"INSANE": "shake-crazy"
}
var endpoint = "current.json";
var getChangeScale = function(changePercent){
var pct = Math.abs(changePercent);
for(th in threshholds){
if(pct >= threshholds[th][0] && pct <= threshholds[th][1]){
return th;
}
}
throw "AHHHHH WHAT THE FUUUUUUCK: " + changePercent;
}
var fixHeights = function(){
$("html, body").css("height", window.innerHeight);
$("#stonksman").css("top", window.innerHeight);
}
var fetchStonks = function(){
$.getJSON(endpoint, function(data){
updateStonks(data.percent_change.toFixed(2));
});
}
var updateStonks = function(changePercent){
var stonksClass = (changePercent >= 0 ? "good" : "bad") + "-stonks",
scale = getChangeScale(changePercent),
shakeClass = shakes[scale];
console.log("change: " + changePercent + "%");
console.log("this is " + scale + " amounts of " + stonksClass);
if($("body").hasClass("init")){
// first load
$("#spokestonks").text("stonks");
$("#stonksman").hide();
$("body").addClass(stonksClass);
$("body.init canvas").addClass("animated").addClass("bounceOutUp");
$("body.init canvas").on("animationend", function() {
space.stop();
space.removeAll();
$("body.init canvas").remove();
$("body").removeClass("init");
$("#stonksman").addClass("animated").addClass("rollIn");
$("#stonksman").show();
$("#stonksman").on("animationend", function() {
$("#stonksman").removeClass().addClass(shakeClass).addClass("shake-constant");
});
});
window.setInterval(fetchStonks, refresh);
}else{
$("body").removeClass().addClass(stonksClass);
$("#stonksman").removeClass().addClass(shakeClass).addClass("shake-constant");
}
}
$(window).resize(function(){ fixHeights(); });
$(document).ready(function(){
$.ajaxSetup({ cache: false });
fixHeights();
// make sure we have a second (or two) to load everything first
window.setTimeout(fetchStonks, 2000);
// Pts is fucking amazing and it is a crime to use it for this horseshit
// example from: https://ptsjs.org/demo/?name=create.noisePts
Pts.quickStart( "body.init", "#ffffff" );
let noiseLine = [];
let noiseGrid = [];
space.add({
start: (bound) => {
// Create a line and a grid, and convert them to `Noise` points
let ln = Create.distributeLinear( [new Pt(0, space.center.y), new Pt(space.width, space.center.y)], 30 );
let gd = Create.gridPts( space.innerBound, 20, 20 );
noiseLine = Create.noisePts( ln, 0.1, 0.1 );
noiseGrid = Create.noisePts( gd, 0.05, 0.1, 20, 20 );
},
animate: (time, ftime) => {
// Use pointer position to change speed
let speed = space.pointer.$subtract( space.center ).divide( space.center ).abs();
// Generate noise in a grid
noiseGrid.map( (p) => {
p.step( 0.01*speed.x, 0.01*(1-speed.y) );
form.fillOnly("#123").point( p, Math.abs( p.noise2D() * space.size.x/18 ) );
});
// Generate noise in a line
let nps = noiseLine.map( (p) => {
p.step( 0.01*(1-speed.x), 0.05*speed.y );
return p.$add( 0, p.noise2D()*space.center.y );
});
// Draw wave
nps = nps.concat( [space.size, new Pt( 0, space.size.y )] );
form.fillOnly("rgba(0,140,255,.65)").polygon( nps );
form.fill("#fff").points( nps, 2, "circle");
}
});
space.play();
$("#stonksplain").click(function(eo){
eo.preventDefault();
if(stonksplainerVisible){
return false;
}
stonksplainerVisible = true;
$("#stonksplainer").removeClass().addClass("animated").addClass("lightSpeedIn").show();
});
$("p#close > a").click(function(eo){
eo.preventDefault();
if(!stonksplainerVisible){
return false;
}
$("#stonksplainer").removeClass().addClass("animated").addClass("hinge");
$("#stonksplainer").on("animationend", function(){
$("#stonksplainer").removeClass();
$("#stonksplainer").hide();
stonksplainerVisible = false;
$("#stonksplainer").unbind();
});
});
});