Skip to content

Instantly share code, notes, and snippets.

@harmoniemand
Last active October 25, 2021 17:54
Show Gist options
  • Save harmoniemand/5f5558ffd159f082f3fd4c916c60a7cb to your computer and use it in GitHub Desktop.
Save harmoniemand/5f5558ffd159f082f3fd4c916c60a7cb to your computer and use it in GitHub Desktop.
/*
simple wave interference script for openjscad, takes a while to render
https://openjscad.com/
*/
function main() {
var wave_origins = [
[0, 0],
[50, 50],
// [100, 100]
];
var render_area = [100, 100];
var amp = 0.5;
var freq = 30;
var offset = 2;
var field = [];
var cubes = [];
for (var x = 0; x < render_area[0]; x++) {
for (var y = 0; y < render_area[1]; y++) {
var height = 0;
for (var o = 0; o < wave_origins.length; o++) {
var dist_x = x - wave_origins[o][0];
var dist_y = y - wave_origins[o][1];
height = height + cos(freq * (sqrt((dist_x * dist_x) + (dist_y * dist_y))));
}
var c = cube({ size: [0.1, 0.1, (height * amp) + offset] }).translate([x * 0.1, y * 0.1, 0]);
cubes.push(c);
}
}
return cubes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment