Android Open Source - Sketcher-Tab Fur Style






From Project

Back to project page Sketcher-Tab.

License

The source code is released under:

Apache License

If you think the Android project Sketcher-Tab listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sketchertab.style;
//from ww  w.j a v a2s.  c om
import android.graphics.Canvas;
import android.graphics.PointF;

import java.util.ArrayList;
import java.util.Map;

class FurStyle extends StyleBrush {
    private float prevX;
    private float prevY;
    private float density;

    private ArrayList<PointF> points = new ArrayList<PointF>();

    {
        paint.setAntiAlias(true);
    }

    FurStyle(float density) {
        this.density = density;
    }

    @Override
    public void setOpacity(int opacity) {
        super.setOpacity((int) (opacity * 0.5f));
    }

    public void stroke(Canvas c, float x, float y) {
        PointF current = new PointF(x, y);
        points.add(current);

        c.drawLine(prevX, prevY, x, y, paint);

        float dx;
        float dy;
        float length;

        for (int i = 0, max = points.size(); i < max; i++) {
            PointF point = points.get(i);
            dx = point.x - current.x;
            dy = point.y - current.y;

            length = dx * dx + dy * dy;

            float maxLength = 2000 * density * density;
            if (length < maxLength && Math.random() > length / maxLength) {
                float ddx = dx * 0.5F;
                float ddy = dy * 0.5F;
                c.drawLine(x + ddx, y + ddy, x - ddx, y - ddy, paint);
            }
        }

        prevX = x;
        prevY = y;
    }

    public void strokeStart(float x, float y) {
        prevX = x;
        prevY = y;
    }

    public void draw(Canvas c) {
    }

    public void saveState(Map<StylesFactory.BrushType, Object> state) {
        ArrayList<PointF> points = new ArrayList<PointF>();
        points.addAll(this.points);
        state.put(StylesFactory.BrushType.FUR, points);
    }

    @SuppressWarnings("unchecked")
    public void restoreState(Map<StylesFactory.BrushType, Object> state) {
        this.points.clear();
        ArrayList<PointF> points = (ArrayList<PointF>) state
                .get(StylesFactory.BrushType.FUR);
        this.points.addAll(points);
    }
}




Java Source Code List

org.sketchertab.AboutDialog.java
org.sketchertab.BrushProperties.java
org.sketchertab.DocumentHistory.java
org.sketchertab.DrawController.java
org.sketchertab.FileHelper.java
org.sketchertab.HistoryItem.java
org.sketchertab.Sketcher.java
org.sketchertab.Style.java
org.sketchertab.SurfaceDiff.java
org.sketchertab.Surface.java
org.sketchertab.colorpicker.HuePicker.java
org.sketchertab.colorpicker.PickerDialog.java
org.sketchertab.colorpicker.Picker.java
org.sketchertab.colorpicker.PreviewView.java
org.sketchertab.colorpicker.SatValPicker.java
org.sketchertab.colorpicker.Utils.java
org.sketchertab.style.CirclesStyle.java
org.sketchertab.style.FurStyle.java
org.sketchertab.style.RibbonStyle.java
org.sketchertab.style.ShadedStyle.java
org.sketchertab.style.SimpleStyle.java
org.sketchertab.style.SketchyStyle.java
org.sketchertab.style.StyleBrush.java
org.sketchertab.style.StylesFactory.java
org.sketchertab.style.WebStyle.java