git @ Cat's Eye Technologies Chzrxl / 456279f
Retain original colour scheme with help from a hslToRgb function. Chris Pressey 6 years ago
2 changed file(s) with 31 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1616 </div>
1717
1818 <!-- to run this offline, download this file and change this URL to point to your local copy of pixi.min.js -->
19 <!-- <script src="https://catseye.tc/contrib/pixi.js-v4.8.5/pixi.min.js"></script> -->
20 <script src="pixi.min.js"></script>
19 <script src="https://catseye.tc/contrib/pixi.js-v4.8.5/pixi.min.js"></script>
2120 <script src="../src/chzrxl.js"></script>
2221 <script>
22
23 // hslToRgb function adapted from https://gist.github.com/vahidk/05184faf3d92a0aa1b46aeaa93b07786
24 function hslToRgb(h, s, l) {
25 let c = (1 - Math.abs(2 * l - 1)) * s;
26 let hp = h / 60.0;
27 let x = c * (1 - Math.abs((hp % 2) - 1));
28 let rgb1;
29 if (isNaN(h)) rgb1 = [0, 0, 0];
30 else if (hp <= 1) rgb1 = [c, x, 0];
31 else if (hp <= 2) rgb1 = [x, c, 0];
32 else if (hp <= 3) rgb1 = [0, c, x];
33 else if (hp <= 4) rgb1 = [0, x, c];
34 else if (hp <= 5) rgb1 = [x, 0, c];
35 else if (hp <= 6) rgb1 = [c, 0, x];
36 let m = l - c * 0.5;
37 return (
38 (Math.round(255 * (rgb1[0] + m)) << 16) |
39 (Math.round(255 * (rgb1[1] + m)) << 8) |
40 (Math.round(255 * (rgb1[2] + m)))
41 );
42 }
43
2344 function launch(config) {
2445 var app = new PIXI.Application({
2546 width: config.width,
3354 width: config.width,
3455 height: config.height,
3556 onInitBlob: function(blob) {
57 var colour = hslToRgb(Math.floor(Math.random() * 360), 0.1, 0.5);
58 // or, for a red-purplish gradient: var colour = 0xff0000 + blob.index;
59 var radius = Math.floor(Math.random() * 10) + 5;
60
3661 var graphics = new PIXI.Graphics();
3762 graphics.lineStyle(0);
38 //var style = "hsl(" + Math.floor(Math.random() * 256) + ",10%,50%)";
39 graphics.beginFill(0xff0000 + blob.index);
40 graphics.drawCircle(0, 0, blob.radius);
63 graphics.beginFill(colour);
64 graphics.drawCircle(0, 0, radius);
4165 graphics.endFill();
4266 app.stage.addChild(graphics);
4367 blob.graphics = graphics;
5377 }
5478
5579 launch({
56 width: 800,
57 height: 600,
80 width: 500,
81 height: 500,
5882 container: document.getElementById('container')
5983 });
6084 </script>
44 this.y = config.y;
55 this.pt1 = config.pt1;
66 this.pt2 = config.pt2;
7 this.radius = config.radius;
87 this.rate = config.rate;
98 this.phase = config.phase;
109 this.colour = config.colour;
5655 }
5756 var rate = Math.random() * 100 + 100;
5857 var phase = Math.floor(Math.random() * 110);
59 var radius = Math.floor(Math.random() * 10) + 5;
6058 this.blobs.push(new Blob().init({
6159 index: i,
6260 x: x,
6563 pt2: pt2,
6664 rate: rate,
6765 phase: phase,
68 radius: radius,
6966 colour: 0xff0000 + i,
7067 blobs: this.blobs,
7168 onInitBlob: this.onInitBlob