Android Open Source - Sketcher Ribbon 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;
//  w w  w  .j a v  a 2  s.  c o  m
import java.util.HashMap;

import org.sketcher.Style;

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

class RibbonStyle implements Style {
  private Paint paint = new Paint();
  private Painter[] painters = new Painter[50];

  private float x;
  private float y;

  private class Painter {
    private static final int SCREEN_WIDTH = 480;
    private static final int SCREEN_HEIGHT = 600;

    float dx = SCREEN_WIDTH / 2;
    float dy = SCREEN_HEIGHT / 2;
    float ax = 0;
    float ay = 0;
    float div = 0.1F;
    float ease = (float) (Math.random() * 0.2 + 0.6);
  }

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

    for (int i = 0; i < 50; i++) {
      painters[i] = new Painter();
    }
  }

  @Override
  public void draw(Canvas c) {
    float startX = 0;
    float startY = 0;
    for (int i = 0; i < painters.length; i++) {
      startX = painters[i].dx;
      startY = painters[i].dy;
      painters[i].dx -= painters[i].ax = (painters[i].ax + (painters[i].dx - x)
          * painters[i].div)
          * painters[i].ease;
      painters[i].dy -= painters[i].ay = (painters[i].ay + (painters[i].dy - y)
          * painters[i].div)
          * painters[i].ease;
      c.drawLine(startX, startY, painters[i].dx, painters[i].dy, paint);
    }
  }

  @Override
  public void stroke(Canvas c, float x, float y) {
    this.x = x;
    this.y = y;
  }

  @Override
  public void strokeStart(float x, float y) {
    this.x = x;
    this.y = y;

    for (int i = 0, max = painters.length; i < max; i++) {
      Painter painter = painters[i];
      painter.dx = x;
      painter.dy = y;
    }
  }

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

  @Override
  public void saveState(HashMap<Integer, Object> state) {
  }

  @Override
  public void restoreState(HashMap<Integer, Object> state) {
  }
}




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