Sine Cosine in 3D / 3Dでのサイン・コサイン

サイン、コサイン、および push / pop は、3Dでも同様に適用できます。

trigonometry 3D movement WEBGL
3D Math

View Source Code

/*
 * @name Sine Cosine in 3D
 * @arialabel Geometric spheres moving in different spiral shapes in a 3D space
 * @description Sine, cosine and push / pop could be applied in 3D as well.
 */
function setup() {
  // createCanvas(710, 400, WEBGL);
  createCanvas(windowWidth, windowHeight, WEBGL);
}

function draw() {
  background(250);
  rotateY(frameCount * 0.01);

  for (let j = 0; j < 5; j++) {
    push();
    for (let i = 0; i < 80; i++) {
      translate(
        sin(frameCount * 0.001 + j) * 100,
        sin(frameCount * 0.001 + j) * 100,
        i * 0.1
      );
      rotateZ(frameCount * 0.002);
      push();
      sphere(8, 6, 4);
      pop();
    }
    pop();
  }
}

License

Source code is available on GitHub p5.js website legacy.

All examples are licensed under CC BY-NC-SA 4.0.