How to create Star and Diamond in Android

May 30, 2012 | Rishabh Agrawal | General

I am here to share  how to create Star and Diamond in Android:

1. Create Star using Line :

int maxX, maxY, minMaxXY, xCenter, yCenter;
maxX = width – 1;
maxY = height – 1;
minMaxXY = Math.min(maxX, maxY);
xCenter = maxX / 2;
yCenter = maxY / 2;
float side = 0.95F * minMaxXY, sideHalf = 0.5F * side, h = sideHalf
* (float) Math.sqrt(3), xA, yA, xB, yB, xC, yC, xA1, yA1, xB1, yB1, xC1, yC1,xD,yD, p, q;

int ax = (xCenter/2) + 20;
int ay = 20;
int bx = xCenter+20;
int by = (int)(.374*(double)(yCenter)+(double)(20));
int cx = (int)(.825*(double)(xCenter)+(double)(20));
int cy = yCenter+20;
int dx = (int)(.175*(double)(yCenter)+(double)(20));
int dy = yCenter+20;
int ex = 20;
int ey = by;
//Color colorSave = g.getColor(); // save previous color
//g.setColor(c);
g.drawLine(ax,ay,cx,cy);
g.drawLine(bx,by,dx,dy);
g.drawLine(cx,cy,ex,ey);
g.drawLine(dx,dy,ax,ay);
g.drawLine(ex,ey,bx,by);

2.Create Star using Eclipse :

float side = 0.95F * minMaxXY, sideHalf = 0.5F * side, h = sideHalf
* (float) Math.sqrt(4);

xA = xCenter – sideHalf;
yA = yCenter – 0.5F * h;
xB = xCenter + sideHalf;
yB = yA;
xC = xCenter + sideHalf;
yC = (yCenter + 0.5F * h) + 5;
xD = xCenter – sideHalf;
yD = (yCenter + 0.5F * h) + 5;

int r = (int) radius;
Random rd = new Random();
int red = rd.nextInt(255);
int blue = rd.nextInt(255);
int green = rd.nextInt(255);
RectF  oval = new RectF((float)centerX,(float)centerY, (float)centerX+30,(float) centerY+70);
RectF  oval1 = new RectF((float)centerX-25,(float)centerY+20, (float)centerX+60,(float) centerY+50);

c.drawOval(oval, p);
c.drawOval(oval1, p);

3.Create Diamond using Line :

centerX=width/2
centerY=height/2
c.drawLine((float)centerX,(float) (centerY), (float)centerX+20,(float)centerY+20,p);
c.drawLine((float)centerX,(float)centerY,(float)centerX+20,(float)centerY-20,p);
c.drawLine((float)centerX+20,(float)centerY-20,(float)centerX+40, (float)centerY,p);
c.drawLine((float)centerX+40,(float)centerY,(float)centerX+20, (float)centerY+20,p);

 

– By Sonu Odesi

Android Developer


THE AUTHORRishabh Agrawal

Rishabh Agrawal is the founder of Creatiosoft, a company focused on creating high-quality software for the iGaming industry, specialising in poker and card games. With years of experience, Rishabh is dedicated to delivering engaging and user-friendly gaming experiences. Through this blog, he shares his passion and insights to help readers understand the latest trends and advancements in iGaming.

Recent Posts

The Future of Mobile Gaming: What to Expect in the Next 5 Years

Over the years, mobile gaming has seen amazing development and innovation utilized by the game development company in India. It…
06 Jun 2023 Rishabh Agrawal

How Do I Get Started With NFT Gaming?

The popularity of the NFT game has created a different fan base. There was a time when games were a…
18 Jul 2022 Rishabh Agrawal

What Are The Top Trends in NFT Marketplace 2022?

The NFTs are the new engaging and revolutionary technology across the globe. Though, these non-fungible tokens appeared for the first…
09 Jun 2022 Rishabh Agrawal