Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JApplet;
- import java.awt.*;
- public class rectanglePyramid extends JApplet
- {
- public void paint (Graphics g) //main
- {
- g.setColor(Color.WHITE);
- Pyr(g,80,140,100,100,5,20);
- Pyr(g,0,0,100,100,10,10);
- Pyr(g,220,50,100,100,20,5);
- }
- public static void Pyr(Graphics g, int x, int y, int w, int h, int steps, int hs) //method
- {
- g.fillRect(x,y,w,h);
- g.setColor(Color.BLACK);
- g.drawRect(x,y,w,h);
- for (int i=0;i<steps;i++) //for loop to create the actual pyramid
- {
- g.setColor(Color.RED);
- g.fillRect(x+(i*(hs/2)),y+((steps-i)*hs)-hs,w-(i*hs),hs);
- g.setColor(Color.BLACK);
- g.drawRect(x+(i*(hs/2)),y+((steps-i)*hs)-hs,w-(i*hs),hs);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment