Jump to content

Printing randomly generated stars based on this one

AjAlien

I am looking for a way to draw 25 stars all with a different number of spikes and different levels of spikiness based on what I have so far in my program. I've tried looping through it with no luck (probably because I doing it wrong). I suppose you could say I would want to randomly generate the values? I would really appreciate the help on this. I am using DrawingPanel.java for this

 

My code:

 

My output:

CurrentOutput.png

 

Goal output:

goaloutput.png

CPU - I7 4770k @ 4.3GHz GPU - EVGA Nvidia GeForce GTX 780 Motherboard - ASUS Maximus VI Extreme RAM - 16GB of Corsair Dominator Platinum @ 2133MHz  Case - Corsair 800D PSU - Corsair AX1,200i CPU Cooler - Custom Liquid CPU Cooler SSD - Samsung 840 Pro 256GB Hard Drive - Western Digital Black 1TB.

Link to comment
Share on other sites

Link to post
Share on other sites

Put a loop around the "fillStar" function call in the main function and send the function different values (random if you want.)

 

Example: 

Quote

fillStar(g, 250, 250, 150, 5, .3); // How to rotate it to start at center?

int xLoc = 250, yLoc=250, starSize=150, starPoints=5

double starWeird = .3 //I'm assuming the .3 number is what makes the stars look "twisted" or not.

 

Loop start

fillStar(g,xLoc,yLoc,starSize,starPoints,starWeird)

xLoc = Random number between 0 and 500

yLoc = Random number between 0 and 500

starSize = Random number between 50 and 100ish

starPoints = Random number between 3 and 10ish?

starWeird = Random number between 0 and 1

Loop end

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, corrado33 said:

Put a loop around the "fillStar" function call in the main function and send the function different values (random if you want.)

Something like this?

int randomStars = (int)(Math.random()*25+1); // Variable for 25 Random Stars
           
           for (randomStars++; randomStars <= 25; randomStars++) {
           fillStar(g, 250, 250, 150, 5, .3);
           }

 

CPU - I7 4770k @ 4.3GHz GPU - EVGA Nvidia GeForce GTX 780 Motherboard - ASUS Maximus VI Extreme RAM - 16GB of Corsair Dominator Platinum @ 2133MHz  Case - Corsair 800D PSU - Corsair AX1,200i CPU Cooler - Custom Liquid CPU Cooler SSD - Samsung 840 Pro 256GB Hard Drive - Western Digital Black 1TB.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, AjAlien said:

Something like this?


int randomStars = (int)(Math.random()*25+1); // Variable for 25 Random Stars
           
           for (randomStars++; randomStars <= 25; randomStars++) {
           fillStar(g, 250, 250, 150, 5, .3);
           }

 

Yes except you'd have to change the numbers you're sending to the function, so that 250,250,150,5,.3. Those would all have to be variables. The only thing you've done is make the program create a random amount between 1 and 25 of those 5 pointed stars all at the exact location. See my edit above.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×