Created
June 19, 2019 14:54
-
-
Save Micrified/f48d10778226355329bd8f4e2626f266 to your computer and use it in GitHub Desktop.
Particle File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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