This site requires JavaScript, please enable it in your browser!
Greenfoot back
kodokulo
kodokulo wrote ...

2018/3/2

About non-center Rotation

1
2
kodokulo kodokulo

2018/3/27

#
i followed exactly the code you suggested to me earlier this is the complete code of my bar
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Bidang pesawat sederhana tuas.
 * 
 * @author (Sapta Hadi Kesuma) 
 */
public class BidangTuas extends Actor
{
    GreenfootImage baseImage;

    private ChangeButton panjangInfo;
    private ChangeButton lenganBebanInfo;
    private ChangeButton lenganKuasaInfo;

    private double panjang_tuas;
    private double lengan_beban;
    private double lengan_kuasa;

    // private Beban beban;
    private TitikTumpu fulkrum;
    private int centerX,fulcrumX;

    // boolean 
    /**
     * Act - do whatever the BidangTuas wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        this.setAllValues();
        //this.balance();        
        if(fulcrumX != fulkrum.getX()){
            this.updateImage();
        }
        // turn(1);
    }    

    public BidangTuas(ChangeButton panjangInfo,ChangeButton lenganBebanInfo, ChangeButton lenganKuasaInfo,TitikTumpu fulkrum){
        this.panjangInfo = panjangInfo;
        this.lenganBebanInfo = lenganBebanInfo;
        this.lenganKuasaInfo = lenganKuasaInfo;
        this.fulkrum = fulkrum;
        // this.beban = beban;
    }

    public void addedToWorld(World w){
        setImage("bidang.png");
        // setImage(new GreenfootImage(1,1));//transparent image
        this.fulcrumX = this.fulkrum.getX();
        this.centerX = this.fulcrumX;
        this.baseImage = this.getImage();
    }

    public void updateImage(){
        //this.resetPosition();
        int xOffset = centerX-fulkrum.getX();
        GreenfootImage img = new GreenfootImage(baseImage.getWidth()+2*(int)Math.abs(xOffset),baseImage.getHeight());
        img.drawImage(baseImage,(img.getWidth()-baseImage.getWidth())/2+xOffset,0);
        this.setImage(img);
        this.setLocation(fulkrum.getX(),this.getY());
    }

    public void setAllValues(){
        this.panjang_tuas = this.panjangInfo.getNilai();
        this.lengan_beban = this.lenganBebanInfo.getNilai();
        this.lengan_kuasa = this.lenganKuasaInfo.getNilai();
    }

    public double getPanjangTuas(){
        return this.panjang_tuas;
    }

    public double getLenganBeban(){
        return this.lengan_beban;
    }

    public double getLenganKuasa(){
        return this.lengan_kuasa;
    }

}
sorry for the half of the code is in the language of my country.
kodokulo kodokulo

2018/3/27

#
apparently i found the problem only if i changed fulcrum from another percentage of the bar length to 50% of the bar length. 1 2
kodokulo kodokulo

2018/4/11

#
any ideas about this?
danpost danpost

2018/4/11

#
Well, if I understand what you are saying correctly, then yes -- the fulcrum and the bar would always maintain equal x-coordinate values. If the fulcrum moves, the bar should adjust its image and move likewise.
kodokulo kodokulo

2018/4/13

#
ok thanks
You need to login to post a reply.
1
2