Search code examples
javaandroidalgorithmtopology

How can I draw a number of Friends in a Star Topology in Android


I Have Some problem.

Let's say I have Q Icons (simple icon let say android logo) and I want to place them in a star topology against the single star center (icons) and connecting them on android canvas.

enter image description here

How can I do it?

any exact Links?

any algorithm information?


Solution

  • public  void starTopology(Canvas mCanvas,int noOfFriends,float centerX,float centerY,int radious) {
    
    
            final double PI = 3.14;
            final double MARGIN = (2*PI)/noOfFriends;
            final double OFFSETX = centerX;
            final double OFFSETY = centerY;
            final int RADIUS = radious;
    
            float pointXCoord = 0;
            float pointYCoord = 0;
            double NextPositionOnCircumference = MARGIN;
    
    
    
            Paint myCustomizedBrush = new Paint();
            myCustomizedBrush.setAntiAlias(true);
    
            myCustomizedBrush.setColor(Color.WHITE);
    
    
            for(int i= 0; i < noOfFriends; i++){
    
                pointXCoord =  (float) (OFFSETX + RADIUS * Math.cos(NextPositionOnCircumference));
                pointYCoord  = (float) (OFFSETY + RADIUS * Math.sin(NextPositionOnCircumference));
    
                NextPositionOnCircumference += MARGIN;
                mCanvas.drawLine((float)OFFSETX, (float)OFFSETY, pointXCoord, pointYCoord, myCustomizedBrush);
                pointXCoord -= 10;
                pointYCoord -= 10;
                mCanvas.drawBitmap(Utility.FriendProfilePic.get(i), pointXCoord, pointYCoord, null);
    
    
            }
            mCanvas.drawCircle((float)OFFSETX, (float)OFFSETY, 5, myCustomizedBrush);
    

    }