// DrawStar Example // Source code file: MyView.java // Create MyView widget that draws // a five-pointed star. package it372.smiths.drawstar; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; public class MyView extends View { public Context savedContext; public MyView(Context context) { super(context); savedContext = context; } @Override public void onDraw(Canvas canvas) { Paint p = new Paint( ); p.setColor(Color.RED); p.setStrokeWidth(5.0f); float xcenter = 400.0f; float ycenter = 400.0f; float r = 200.0f; float xprev = xcenter + r; float yprev = ycenter; float angle = 4 * (float) Math.PI / 5.0f; for(int k = 1; k <= 5; k++) { float x = xcenter + r * (float) Math.cos(angle * k); float y = ycenter + r * (float) Math.sin(angle * k); canvas.drawLine(xprev, yprev, x, y, p); xprev = x; yprev = y; } } }