Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
<style>
2
    .reveal #canvas {
3
      /*position: fixed;*/
4
      width:1348px;
5
      max-width: 100%!important;
6
      height:auto;
7
      max-height:543px;
8
      top: 0;
9
      left: 0;
10
      background:url("/images/einstieg/28-10-FaltradXXS.jpg") no-repeat;
11
      background-size:contain!important;
12
    }
13
    .reveal h1 {
14
      color: var(--bg);
15
       position: relative;
16
      font-size: 20vw;
17
      line-height: 100vh;
18
      margin: 0;
19
      pointer-events: none;
20
    }
21
    .reveal {
22
      width:1348px;
23
      max-width:100%;
24
      background: var(--fg);
25
      display: flex;
26
      justify-content: center;
27
      align-items: center;
28
      overflow: hidden!important;
29
      margin:0 auto;
30
    }
31
    :root {
32
      --fg: #1e1e1e;
33
      --bg: #1e1e1e;
34
    }
35
 
36
 
37
</style>
38
{*https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix-min.js*}
39
<script type="text/javascript" src="/JavaScript/gl_matrix/gl-matrix-min.js"></script>
40
 
41
<div class="home reveal">
42
    <canvas id="canvas"></canvas>
43
 
44
</div>
45
 
46
<script>
47
    const canvas = document.getElementById('canvas');
48
    const ctx = canvas.getContext('2d');
49
    const cellSize = 30;
50
    const maxSize = 30;
51
    let mousePos = vec2.fromValues(innerWidth * 0.25, innerHeight * 0.5);
52
    let numThingsX;
53
    let numThingsY;
54
    let things;
55
 
56
    function drawThing(thing) {
57
      const { pos, radius } = thing;
58
      ctx.fillStyle = '#1e1e1e';
59
      ctx.beginPath();
60
      ctx.arc(pos[0], pos[1], radius, 0, Math.PI * 2);
61
      ctx.fill();
62
    }
63
 
64
    function loop() {
65
      ctx.clearRect(0, 0, innerWidth, innerHeight);
66
      things.forEach(thing => {
67
        const dist = vec2.dist(mousePos, thing.pos);
68
        thing.radius = clamp(dist * dist * 0.0003 - 1, 0, maxSize);
69
        drawThing(thing);
70
      });
71
      // For now I'm turning off the RAF loop because
72
      // there are no ongoing animations.
73
      // window.requestAnimationFrame(loop);
74
    }
75
 
76
    function makeThing(x, y) {
77
      return {
78
        pos: vec2.fromValues(x, y),
79
        radius: 2,
80
      };
81
    }
82
 
83
    function makeThings() {
84
      things = [];
85
      for (let i = 0; i < numThingsY; i += 1) {
86
        for (let j = 0; j < numThingsX; j += 1) {
87
          const thing = makeThing(j * cellSize + cellSize * 0.5, i * cellSize + cellSize * 0.5);
88
          things.push(thing);
89
        }
90
      }
91
    }
92
 
93
    function sizeCanvas() {
94
      const dpr = window.devicePixelRatio || 1;
95
      const canvasRect = canvas.getBoundingClientRect();
96
      canvas.width = canvasRect.width * dpr;
97
      canvas.height = canvasRect.height * dpr;
98
      ctx.scale(dpr, dpr);
99
    }
100
 
101
    function handleResize() {
102
      sizeCanvas();
103
      numThingsX = Math.ceil(innerWidth / cellSize);
104
      numThingsY = Math.ceil(innerHeight / cellSize);
105
      makeThings();
106
    }
107
    window.addEventListener('resize', throttled(handleResize));
108
 
109
    function handleMouseMove(event) {
110
 
111
      console.log(canvas.offsetLeft);
112
      vec2.set(mousePos, event.clientX-canvas.offsetLeft, event.clientY-canvas.offsetTop);
113
      loop();
114
    }
115
    window.addEventListener('mousemove', throttled(handleMouseMove));
116
 
117
    // Kick it off
118
    handleResize();
119
    loop();
120
 
121
    // USEFUL FUNCTIONS ----------
122
    function throttled(fn) {
123
      let didRequest = false;
124
      return param => {
125
        if (!didRequest) {
126
          window.requestAnimationFrame(() => {
127
            fn(param);
128
            didRequest = false;
129
          });
130
          didRequest = true;
131
        }
132
      };
133
    }
134
    function clamp (value, min = 0, max = 1) {
135
      return value <= min ? min : value >= max ? max : value;
136
    }
137
</script>