68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
/**
|
|
*
|
|
* @source: https://software.mcgoron.com/peter/scattering.js
|
|
*
|
|
* @licstart The following is the entire license notice for the
|
|
* JavaScript code in this file.
|
|
*
|
|
* Copyright (C) 2023 Peter McGoron
|
|
*
|
|
* The JavaScript code in this file is free software: you can
|
|
* redistribute it and/or modify it under the terms of the GNU
|
|
* General Public License (GNU GPL) as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option)
|
|
* any later version. The code is distributed WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
|
*
|
|
* As additional permission under GNU GPL version 3 section 7, you
|
|
* may distribute non-source (e.g., minimized or compacted) forms of
|
|
* that code without the copy of the GNU GPL normally required by
|
|
* section 4, provided you include this license notice and a URL
|
|
* through which recipients can access the Corresponding Source.
|
|
*
|
|
* @licend The above is the entire license notice
|
|
* for the JavaScript code in this page.
|
|
*
|
|
*/
|
|
|
|
let width = 800;
|
|
let height = 600;
|
|
let longestDiag = Math.sqrt(width**2 + height**2);
|
|
|
|
class PlaneWave {
|
|
constructor(x_0, y_0, v, angle) {
|
|
this.x_0 = x_0;
|
|
this.y_0 = y_0;
|
|
this.angle = angle;
|
|
this.v = v;
|
|
}
|
|
|
|
draw() {
|
|
translate(this.x_0, this.y_0);
|
|
rotate(this.angle);
|
|
strokeWeight(2);
|
|
line(-longestDiag, 0, longestDiag, 0);
|
|
resetMatrix();
|
|
}
|
|
|
|
update() {
|
|
this.x_0 = this.x_0 + this.v * deltaTime * Math.sin(this.angle);
|
|
this.y_0 = this.y_0 + -this.v * deltaTime * Math.cos(this.angle);
|
|
}
|
|
}
|
|
|
|
let testWave = new PlaneWave(200, 200, 0.1, Math.PI/4);
|
|
|
|
function setup() {
|
|
frameRate(24);
|
|
createCanvas(800, 600);
|
|
fill(0);
|
|
}
|
|
|
|
function draw() {
|
|
background(200);
|
|
testWave.draw();
|
|
testWave.update();
|
|
}
|