-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavy-cactus.html
135 lines (105 loc) · 3.97 KB
/
wavy-cactus.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
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
background: transparent;
}
body {
/* background: black; */
text-align: center;
}
canvas {
height: 100%;
/* width: 100%; */
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.6.2/pixi.js"></script>
</head>
<body>
<script>
let PORTRAIT = 'PORTRAIT';
let LANDSCAPE = 'LANDSCAPE';
function WavyCactus() {
this.loader = new PIXI.loaders.Loader();
this.loader.add('cactus', 'assets/svg/spritesheet.json');
this.loader.load(this.onLoaderLoad.bind(this));
};
WavyCactus.prototype.onLoaderLoad = function(loader, resources) {
this.texture = resources.cactus.textures['Cactus-Left-Small.png'];
this.baseTexture = this.texture.baseTexture;
this.app = new PIXI.Application({
width: this.baseTexture.width,
height: this.baseTexture.height,
transparent: true
});
document.body.appendChild(this.app.view);
this.app.view.width = this.baseTexture.width;
var count = 0;
var segments = 20;
// this.ropeLength = this.canvas.offsetHeight / segments;
this.ropeLength = this.baseTexture.height / segments;
var points = [];
for (var i = 0; i < segments; i++) {
points.push(new PIXI.Point(0, i * this.ropeLength));
}
this.strip = new PIXI.mesh.Rope(this.texture, points);
this.container = new PIXI.Container();
// this.container.x = this.canvas.offsetWidth / 2;
// this.container.y = this.canvas.offsetHeight / 2;
this.container.x = this.baseTexture.width / 2;
this.container.y = this.baseTexture.height / 2;
// var scaleX = this.canvas.offsetWidth / this.baseTexture.width;
// var scaleX = this.baseTexture.width / this.canvas.offsetWidth;
// var scaleY = scaleX * (this.baseTexture.width / this.baseTexture.height);
// console.log(scaleX);
this.container.scale.set(0.5, 1);
this.app.stage.addChild(this.container);
this.container.addChild(this.strip);
this.app.ticker.add(function() {
count += 0.05;
// make the snake
for (var i = 0; i < points.length; i++) {
points[i].y = Math.sin((i * 0.5) + count) * 2;
points[i].x = i * this.ropeLength + Math.cos((i * 0.3) + count) * 3;
}
}.bind(this));
this.container.x = 0;
// this.container.y = this.canvas.offsetHeight / 2;
this.container.y = this.baseTexture.height / 2;
// setTimeout(function() {
// this.resize();
// }.bind(this), 500);
window.onresize = function(e) {
// this.resize();
}.bind(this);
};
WavyCactus.prototype.resize = function() {
// let orientation = this.getCanvasOrientation();
// if LANDSCAPE we limit the cactus by it's height
// if (orientation === LANDSCAPE) {
// console.log(LANDSCAPE);
// this.container.scale.set(this.canvas.offsetHeight / this.baseTexture.height);
// // this.container.scale.set(this.canvas.offsetWidth / this.baseTexture.width);
// }
// // if PORTRAIT we limit the cactus by it's width
// else {
// console.log(PORTRAIT);
// this.container.scale.set(this.canvas.offsetHeight / this.baseTexture.height);
// // this.container.scale.set(this.canvas.offsetWidth / this.baseTexture.width);
// }
};
// WavyCactus.prototype.getCanvasOrientation = function() {
// return this.canvas.offsetWidth / this.canvas.offsetHeight > 1 ? LANDSCAPE : PORTRAIT;
// };
window.onload = function() {
window.cactus = new WavyCactus();
};
</script>
</body>
</html>