Note that there are some explanatory texts on larger screens.

plurals
  1. POmethod to change shapes not working
    primarykey
    data
    text
    <p>The question is to get my shapes to change over time according to some criteria of my own design therefore i tried to make the shape change size as it hits certain coordinates but it would turn into line and keep moving as lines below is my move method to make my shapes move, rebound, and move horizontally and vertically.</p> <pre><code>public void move() { // Rebound X if (x &lt;= 0 || x &gt;= 400 - width) { moveX = moveX * -1; } // Rebound Y if (y &lt;= 0 || y &gt;= 400 - height) { moveY = moveY * -1; } // Wide shapes move up and down, narrow shapes move sideways if (width &gt; 15) { y += moveY; } else { x += moveX; } // Change shape size if (y &lt;= 100 || y &gt;= 300 - height) { moveX = -moveX; height += height * 1 / 2; } //if { // height -= height * 1/2; // moveX = -moveX; //} //if (x &lt; 20) { // width -= width * 1/2; // moveY = -moveY; //} else { // width += width * 1/2; // moveY = -moveY; //} } </code></pre> <p>This is my shape class that all shapes extend:</p> <pre><code>package shapes; import java.awt.*; import java.util.Random; public abstract class Shape { protected int x; protected int y; protected int width; protected int height; protected Color color; protected int moveX = 1; protected int moveY = 1; public Shape() { Random r = new Random(); width = r.nextInt(30) + 10; height = width; x = r.nextInt(400 - width); y = r.nextInt(400 - height); color = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); } // Returns random value within range (low &lt; n &lt;= high). public int randomRange(int low, int high) { Random generator = new Random(); return generator.nextInt(high - low + 1) + low; } public abstract void display(Graphics page); public abstract void move(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload