Created
February 22, 2020 17:57
-
-
Save MinSomai/36a60e85d0b539250082fe88af7c9282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hw; | |
import java.awt.Graphics; | |
import javax.swing.JFrame; | |
public class ScalingOrigin13 extends JFrame { | |
int xPoly[] = { 25, 45, 96, 110, 145, 35, 40 }; | |
int yPoly[] = { 25, 50, 36, 66, 75, 85, 40 }; | |
int i; | |
ScalingOrigin13() { | |
setTitle("Scaling on Origin: "); | |
setSize(960, 960); | |
setVisible(true); | |
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
} | |
public void paint(Graphics g) { | |
g.translate(100, 100); | |
g.drawPolygon(xPoly, yPoly, xPoly.length); | |
scaleAt(2, 2); | |
} | |
public void scaleAt(int Sx, int Sy) { | |
for (i = 0; i < xPoly.length; i++) { | |
xPoly[i] = xPoly[i] * Sx; | |
yPoly[i] = yPoly[i] * Sy; | |
} | |
Graphics g = this.getGraphics(); | |
g.translate(100, 100); | |
g.drawPolygon(xPoly, yPoly, xPoly.length); | |
} | |
public static void main(String[] args) { | |
javax.swing.SwingUtilities.invokeLater(new Runnable() { | |
public void run() { | |
new ScalingOrigin13(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment