java - Move a Rectangle from point to point in a ramp with changing angle -


so have program test possibility of object slide down in ramp given friction, object mass , ramp angle. need animate box if force positive. simple animation moving box point end of ramp. can't. please help

    private void drawtransform(graphics g, double modifier) {    // redtowhite = new gradientpaint(0,0,color.red,100, 0,color.white); rectangle rect = new rectangle(130,350, 350, 15);     rectangle box = new rectangle((int) (rect.getx()+300), 300, 50, 50);     affinetransform @ = new affinetransform();     at.rotate(-math.toradians(modifier), rect.getx(), rect.gety() + rect.height);      // transform shape , draw screen     graphics2d g2d = (graphics2d) g;     g2d.setcolor(color.dark_gray);    // g2d.fillrect(0, 0, 350, 600);     g2d.fill(at.createtransformedshape(rect));     g2d.draw(at.createtransformedshape(box));  } 

screenshot:

enter image description here

if want move box, can done updating it's x position. should able manipulate rectangle's x position directly using "box.x++". alternatively create variable , reference provide initial x co-ordinate, updating variable "move" box. 1 issue only move box along x axis, hence need kind of constant downward force acting gravity. easy achieve, minus box's y position value when not colliding ground, or ramp.

another approach velocity based movement using vectors, mentioned animation should simple. if want smoother animation velocity based movement provide need perform little research first.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -