You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB
JavaScript

/* Copyright (C) 2024 Sebastián Santisi <ssantisi@fi.uba.ar>, CSC-CONICET
Based on https://codepen.io/okada-web/pen/OJydGzy?editors=0010
*/
import * as THREE from 'three';
class ArgentinianFlag extends THREE.Group {
constructor(height) {
super();
var geometry = new THREE.PlaneGeometry(3,2,30,20);
var colors = new three.BufferAttribute(new Float32Array(geometry.attributes.position.array.length), 3);
geometry.setAttribute('color', colors);
for(var i = 0; i < colors.count; i++)
if(i < 31 * 7 || i >= 31 * 14)
colors.setXYZ(i, 117/255, 170/255, 219/255);
else
colors.setXYZ(i, 1, 1, 1);
var material = new THREE.MeshStandardMaterial({side:THREE.DoubleSide, vertexColors: true});
this.mesh = new THREE.Mesh(geometry,material);
this.mesh.castShadow = true;
this.mesh.receiveShadow = true;
this.mesh.rotateX(Math.PI/2);
var scale = height / 3;
this.mesh.position.x = 1.5 * scale;
this.mesh.position.z = 1 * scale;
this.mesh.scale.setScalar(scale);
this.add(this.mesh);
}
animate() {
var hor = 0.3;
var speed = 0.1;
var ver = 0.1;
var swing = 0.5;
var pos = this.mesh.geometry.attributes.position;
const time = Date.now() * speed / 50;
for (let y=0; y<20+1; y++) {
for (let x=0; x<30+1; x++) {
const index = x + y * (30+1);
const vertex = pos[index];
pos.setZ(index, Math.sin(hor * x + ver * y - time) * swing * x / 40);
}
}
pos.needsUpdate = true;
}
}
export { ArgentinianFlag };