Skip to content

Instantly share code, notes, and snippets.

@Micrified
Created June 19, 2019 14:54
Show Gist options
  • Save Micrified/f48d10778226355329bd8f4e2626f266 to your computer and use it in GitHub Desktop.
Save Micrified/f48d10778226355329bd8f4e2626f266 to your computer and use it in GitHub Desktop.
Particle File
package com.example.lieu;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
public class Particle {
// Drawable object
private ShapeDrawable fillShape;
// Center point
private Point center;
// Radius of particle
private int radius;
// Constructor with optional color
public Particle (Point center, int radius) {
this.center = center;
this.fillShape = new ShapeDrawable(new OvalShape());
this.fillShape.getPaint().setColor(Color.WHITE);
}
// Positions the particle
private void setBounds () {
this.fillShape.setBounds(center.x - radius, center.y - radius, center.x + radius, center.y + radius);
}
// Draws the particle
public void draw (Canvas canvas) {
this.setBounds();
this.fillShape.draw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment