Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void draw() {
- // drawChessBoard(20, 20);
- // drawStar1(200, 8);
- // drawStar2(50, 8);
- // drawStar3(50, 10);
- // serpinski(width / 2, height - 100, 600);
- tree(width / 2, height - 100, 200);
- }
- public void serpinski(float x, float y, int side) {
- // TODO: Change the code so it will draw a Serpinski Carpet
- // https://media.springernature.com/lw685/springer-static/image/art%3A10.1007%2Fs00209-019-02319-4/MediaObjects/209_2019_2319_Fig1_HTML.png
- line(x - side / 2, y, x + side / 2, y);
- line(x - side / 2, y, x, (float) (y - Math.sqrt(3/2) * side));
- line(x + side / 2, y, x, (float) (y - Math.sqrt(3/2) * side));
- if (side > 10) {
- serpinski(x - side / 4, y, side / 2);
- serpinski(x + side / 4, y, side / 2);
- serpinski(x, (int) (y - (Math.sqrt(3/2) * side) / 2), side / 2);
- }
- }
- public void tree(float x, float y, int size) {
- // TODO: Change the code so it will look as http://www.lukaszkroenke.net/content/tree_simple.png
- line(x, y, x, y - size);
- line(x, y - size, x + (float) Math.cos(-45 * Math.PI / 180) * size, y - size + (float) Math.sin(-45 * Math.PI / 180) * size);
- line(x, y - size, x + (float) Math.cos(-135 * Math.PI / 180) * size,y - size + (float) Math.sin(-135 * Math.PI / 180) * size);
- if (size > 10) {
- tree(x + (float) Math.cos(-45 * Math.PI / 180) * size, y - size + (float) Math.sin(-45 * Math.PI / 180) * size, size / 2);
- tree(x + (float) Math.cos(-135 * Math.PI / 180) * size,y - size + (float) Math.sin(-135 * Math.PI / 180) * size, size / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement