/* Copyright 2019 gr@gr5.org All Rights Reserved This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ You are free to copy and modify this program but you must keep the 2 lines of text above. The color implementation is a triangle wave instead of a sine wave. This could be more realistic and just as fast to calculate if there was a small lookup table. Calculing a sin() function for the 100k or so voxels is probably too much but a lookup would be quick. */ xtilt = 12; z8 = -3; // z8 zernike term aka Spherical Aberration pixel_size=.45; // lowering this increases resolution but slows down calculations step_size = pixel_size * 0.7; pixel_height = pixel_size; mag = z8*sqrt(5)/2; tilt = xtilt/50; // 50x50 grid echo("Approximate number of voxels: ", 101*101/step_size/step_size); for(x=[-50: step_size:50]) for(y=[-50: step_size:50]) { rr = sqrt(x*x+y*y)/50; // radial distance from center if (rr < 1) // diameter is 50 - draw nothing outside this radius { z = mag*(6*rr*rr*rr*rr - 6*rr*rr +1) + // spherical aberration x * tilt; // xtilt color([ 2*(abs(.5 - (z-floor(z)))), 0, 0]) // color is triangle wave. Not sine wave - close enough. translate([x, y, z]) // where to place the voxel cube([pixel_size,pixel_size,pixel_height]); // creates a tiny voxel } } // reference octagon difference() { color([0.5,0.2,0.2]) // mud color cylinder(h=0.1, d=150, $fn=8); translate([0,0,-1]) cylinder(h=2, d=100, $fn=50); }