liangm20

rectangle pyramid

Oct 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import javax.swing.JApplet;
  2. import java.awt.*;
  3. public class rectanglePyramid extends JApplet
  4. {
  5. public void paint (Graphics g) //main
  6. {
  7. g.setColor(Color.WHITE);
  8. Pyr(g,80,140,100,100,5,20);
  9. Pyr(g,0,0,100,100,10,10);
  10. Pyr(g,220,50,100,100,20,5);
  11. }
  12. public static void Pyr(Graphics g, int x, int y, int w, int h, int steps, int hs) //method
  13. {
  14. g.fillRect(x,y,w,h);
  15. g.setColor(Color.BLACK);
  16. g.drawRect(x,y,w,h);
  17. for (int i=0;i<steps;i++) //for loop to create the actual pyramid
  18. {
  19. g.setColor(Color.RED);
  20. g.fillRect(x+(i*(hs/2)),y+((steps-i)*hs)-hs,w-(i*hs),hs);
  21. g.setColor(Color.BLACK);
  22. g.drawRect(x+(i*(hs/2)),y+((steps-i)*hs)-hs,w-(i*hs),hs);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment