/** Transforms.pde (part of NoiseGrid) Dave Bollinger http://www.davebollinger.com */ /** * transforms are responsible for translating to specified coordinates, then * performing whatever noise-based transform is called for, then unapplying * that transform. */ public class BaseTransform { PApplet applet; public BaseTransform(PApplet applet) { this.applet = applet; } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); translate(screenx, screeny); } public void unapply() { popMatrix(); } } public class TranslateTransform extends BaseTransform { public TranslateTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); screenx += (value-0.5) * 2f * xscale; screeny += (value-0.5) * 2f * yscale; translate(screenx, screeny); scale(xscale, yscale); } } public class RotateTransform extends BaseTransform { public RotateTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); translate(screenx, screeny); scale(xscale, yscale); rotate(value*TWO_PI); } } public class ScaleTransform extends BaseTransform { public ScaleTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); translate(screenx, screeny); scale(xscale, yscale); scale(value*2f); } } public class RotateScaleTransform extends BaseTransform { public RotateScaleTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); translate(screenx, screeny); scale(xscale, yscale); rotate(value*TWO_PI); scale(value*2f); } } public class TranslateRotateTransform extends BaseTransform { public TranslateRotateTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); screenx += (value-0.5) * 2f * xscale; screeny += (value-0.5) * 2f * yscale; translate(screenx, screeny); scale(xscale, yscale); rotate(value*TWO_PI); } } public class TranslateScaleTransform extends BaseTransform { public TranslateScaleTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); screenx += (value-0.5) * 2f * xscale; screeny += (value-0.5) * 2f * yscale; translate(screenx, screeny); scale(xscale, yscale); scale(value*2f); } } public class TranslateRotateScaleTransform extends BaseTransform { public TranslateRotateScaleTransform(PApplet applet) { super(applet); } public void apply(float screenx, float screeny, float value, float xscale, float yscale) { pushMatrix(); screenx += (value-0.5) * 2f * xscale; screeny += (value-0.5) * 2f * yscale; translate(screenx, screeny); scale(xscale, yscale); rotate(value*TWO_PI); scale(value*2f); } } // and where are the x and y rotations? // and if you rotate in x/y then z scale/translate makes sense to add too.. // and maybe shears too, though would have to update the matrix manually...