Drop Shadow Method

edited December 2015 in Share Your Work

Hey guys, after a few hours of hard work.. I figured out how to get a drop shadow to work perfectly... here is a image example... dropshadow

I'd like to mention that the linear gradient example on Processing.org was instrumental in my figuring this out, couldn't have done it without it... here is my code: (Made to work in Eclipse... may require modification for the PDE)

public enum Axis { Y_AXIS, X_AXIS };
    public void setGradient(int x, int y, float w, float h, int c1, int c2, Axis axis ) {

        parent.noFill();

          if (axis == Axis.Y_AXIS) {  // Top to bottom gradient
            for (int i = y; i <= y+h-1; i++) {
              float inter = map(i, y, y+h, 0, 1);
              int c = lerpColor(c1, c2, inter);
              parent.stroke(c);
              parent.line(x, i, x+w, i);
            }
          }  
          else if (axis == Axis.X_AXIS) {  // Left to right gradient
            for (int i = (int) (x+w); i > x +1; i--) {
              float inter = map(i, x, x+w, 0, 1);
              int c = lerpColor(c1, c2, inter);
              parent.stroke(c);
              parent.line(i, y, i, y+h);
            }
          }

          parent.noStroke();
        }

 int a = color(0,0,0,175);
 int b = color(0,0,0,0);
//Make sure to import the enum Axis or you'll get a error with "Axis.X_AXIS" 
VTK.setGradient(width - dp(153), dp(60), dp(3), height - dp(60), b , a , Axis.X_AXIS );
VTK.setGradient(0,dp(60),width,dp(4),a,b,Axis.Y_AXIS);

Please ignore the "dp()"'s, they are just ints that return a density-independent pixel. if you want to use that, here is the code:

     public static int dp(float px) {
                 return (int) ((px * 160) / (int) (Toolkit.getDefaultToolkit().getScreenResolution()));
     }

       //I would import the dp method from another class statically, like so:

      import static blabla.classname.dp;

       //So that it could be used like:

            dp(int px);

            //As opposed to

            Classname d = new Classname();

            d.dp(int px);

Comments

Sign In or Register to comment.