• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Generating many random spoked star positions

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Currently my program generates only 1 spoked star figure and a bunch of lines but I'm trying to figure out how I would go about replicating the spoked stars. What do you guys think?
 
Marshal
Posts: 76830
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does DrawingCanvas come from?
Why have you got so many static methods, and why have you got so much code in the main() method?
Where is the instruction to draw lines, and how often does it run? Same for the instruction to draw stars.
 
Andrew Bauer
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where does DrawingCanvas come from?
Why have you got so many static methods, and why have you got so much code in the main() method?
Where is the instruction to draw lines, and how often does it run? Same for the instruction to draw stars.




DrawingCanvas is just a class, the static methods are there to perform a different action and I was trying to reference the main method code to the drawStar method. The instruction to draw the lines is in the main method and it runs a total of 19 times whereas the star method only runs once.
 
Saloon Keeper
Posts: 5157
207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you just bring the drawStar method inside the loop? Something like 'g.drawStar(g, x, y, width, widh, rand.nextInt(10) + 1);'? Do you need all those lines?
Another way is to create a class 'Star' and then create many instances, all with their own center, et cetera. By updating the center on a regular basis, you can get moving stars.
 
Campbell Ritchie
Marshal
Posts: 76830
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't that answer your question? If you move the star‑drawing code into the loop, you will get multiple stars. That might be what you want, or it might not be.

[edit]Maybe Piet's suggestion is better than mine.
 
Andrew Bauer
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Doesn't that answer your question? If you move the star‑drawing code into the loop, you will get multiple stars. That might be what you want, or it might not be.

[edit]Maybe Piet's suggestion is better than mine.




Are you referring to the main method loop?
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic