java - Formula to draw pyramid of circles -


I am trying to create a pyramid of circles in my game, looking for this type:

< P>

But I can not print it properly. I'm constantly growing really weird, but nothing close to this. Can anyone give me some tips on the appropriate formula? My window is 600x600, the base of the pyramid is 8.

  field = new field [base * (base / 2) +4]; Int line_count = base; Int line_tmp = line_count; (For ([i] = new field (0, (150+ (line_tmp * 5)) for (int i = 0; i & lt; field lamps; i ++) {for (int j = line_tmp; j & Lt;), (600 + line_tmp * 5));} linemount -; line_tmp = linemount;  

I see that there are errors:

  • Wrong array size formula.
  • y expression in line_tmp (which looks like your counter counter).
  • having two variables, line_count and line_temp that are always equal
  • Instead of counting by line, your external loop calculation by node.
  • Usually meaningless variable names and magical numbers are scattered about.
  // I use  java.util.ArrayList  because its add method is convenient here. // is the proper platform for approximate number of nodes : Base and time; (base + 1) and split; 2 final list; field> field = new arreelist & lt; field> (base * (base + 1) / 2); // I use  java.awt.Point  to store the value (x, y) of the first node of the line. // Instead of using ints or long inline expressions, the meaning is the final point rowStart = new point (PANEL_WIDTH / 2, the dimeter); // The number of rows is equal to the number of nodes on the last line ({line  line; > N  nodes (int circle = 0; circle and lefinity; line; circle ++) {// each line begins on line start and each next circle is offset. Fields.add (new field (0, rowStart.x + circle * DIAMETER * 2, rowStart.y)); } // Each subsequent row starts at the lower left and the last left RowStart.x - = DIAMETER; RowStart.y + = DIAMETER; }  

If this is a homework, remember to use only its reference to fix your own code.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -