Android Matrix Drow Line and Circle

November 25, 2018 7:35 pm Published by
public class DrawView extends View {
    Paint paint = new Paint();

    private void init() {
        paint.setColor(Color.BLACK);
    }

    public DrawView(Context context) {
        super(context);
        init();
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    @Override
    public void onDraw(Canvas canvas) {
    	
    	int step_x = 20; //pixel
    	int step_y = 20; //pixel
    	int size_x = 10; //pixel
    	int size_y = 10; //pixel

    	
    	for (int count_rows = 0; count_rows < 15; count_rows ++) {
        	for (int count_cols = 0; count_cols < 15; count_cols ++) {
        		
        	int point1_x1 = count_rows * step_x;
        	int point1_y1 = count_cols * step_y;
        	int point1_x2 = point1_x1 + size_x;
        	int point1_y2 = point1_y1 + size_y;

            canvas.drawLine(point1_x1, point1_y1, point1_x2, point1_y2, paint);
            
         
        	int point2_x1 = point1_x1;
        	int point2_y1 = point1_y1 + size_x;
        	int point2_x2 = point1_x2;
        	int point2_y2 = point1_y2 - size_y;
            
        	canvas.drawLine(point2_x1, point2_y1, point2_x2, point2_y2, paint);
            
        	
        	int point3_x = point1_x1 + (size_x / 2);
        	int point3_y = point1_y1 + (size_y / 2);

            canvas.drawCircle(point3_x, point3_y, 2, paint);
            
        	}
    	}
    }

Categorised in: ,

This post was written by admin

Comments are closed here.