Android Open Source - Sketcher Web Style






From Project

Back to project page Sketcher.

License

The source code is released under:

Apache License

If you think the Android project Sketcher 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.sketcher.style;
/*from w  w  w.j  a v  a  2 s  .c  o m*/
import java.util.ArrayList;
import java.util.HashMap;

import org.sketcher.Style;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;

class WebStyle implements Style {
  private float prevX;
  private float prevY;

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

  private Paint paint = new Paint();

  {
    paint.setColor(Color.BLACK);
    paint.setAlpha(25);
    paint.setAntiAlias(true);
  }

  @Override
  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 = 0;
    float dy = 0;
    float length = 0;

    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;

      if (length < 2500 && Math.random() > 0.9) {
        c.drawLine(current.x, current.y, point.x, point.y, paint);
      }
    }

    prevX = x;
    prevY = y;
  }

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

  @Override
  public void draw(Canvas c) {
  }

  @Override
  public void setColor(int color) {
    paint.setColor(color);
    paint.setAlpha(25);
  }

  @Override
  public void saveState(HashMap<Integer, Object> state) {
    ArrayList<PointF> points = new ArrayList<PointF>();
    points.addAll(this.points);
    state.put(StylesFactory.WEB, points);
  }

  @SuppressWarnings("unchecked")
  @Override
  public void restoreState(HashMap<Integer, Object> state) {
    this.points.clear();
    ArrayList<PointF> points = (ArrayList<PointF>) state
        .get(StylesFactory.WEB);
    this.points.addAll(points);
  }
}




Java Source Code List

org.sketcher.AboutDialog.java
org.sketcher.Controller.java
org.sketcher.FileHelper.java
org.sketcher.HistoryHelper.java
org.sketcher.SketcherApplication.java
org.sketcher.Sketcher.java
org.sketcher.Style.java
org.sketcher.Surface.java
org.sketcher.colorpicker.AlphaPicker.java
org.sketcher.colorpicker.HuePicker.java
org.sketcher.colorpicker.PickerDialog.java
org.sketcher.colorpicker.Picker.java
org.sketcher.colorpicker.PreviewView.java
org.sketcher.colorpicker.SatValPicker.java
org.sketcher.colorpicker.Utils.java
org.sketcher.style.ChromeStyle.java
org.sketcher.style.CirclesStyle.java
org.sketcher.style.EraserStyle.java
org.sketcher.style.FurStyle.java
org.sketcher.style.GridStyle.java
org.sketcher.style.LongfurStyle.java
org.sketcher.style.RibbonStyle.java
org.sketcher.style.ShadedStyle.java
org.sketcher.style.SimpleStyle.java
org.sketcher.style.SketchyStyle.java
org.sketcher.style.SquaresStyle.java
org.sketcher.style.StylesFactory.java
org.sketcher.style.WebStyle.java