使用Python乌龟图形创建砖墙

时间:2018-11-15 14:28:20

标签: python turtle-graphics

我对如何制作墙有一个想法,但是我必须在砖之间实现空间,并且必须填满窗户。有人会对如何最好地实现这一点有什么建议吗?我的代码是这样的:

<html>
    <head>
        <title>Site</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="HandheldFriendly" content="true">
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="style.css">
        <link rel="stylesheet" href="style.css">
    </head>

    <body>
        <div class="container">
            <form>
                <div id="myDIV" class="header">
                    <h2>To-Do</h2>
                    <input type="text" id='uzd' placeholder="Užduotis">
                    <input type="button" id='todoadd' >
                </div>
            </form>
            <ul id='uzduotys'>

            </ul>
        </div>
        <script>
            document.getElementById("todoadd").onclick = function(){
                var node = document.createElement("Li");
                var text = document.getElementById("uzd").value;
                var textnode =document.createTextNode(text);
                node.appendChild(textnode);
                document.getElementById("uzduotys").appendChild(node);
            } 
       </script>
    </body>
</html>

在第一行之后,y应该增加自己,并在第一行之下添加另一行,直到填满屏幕为止。

1 个答案:

答案 0 :(得分:0)

即使这不是您要考虑的内容,它也应该为您提供一些有关如何进行的想法。它基于冲压而不是绘图,并将坐标系设置为以砖为中心:

from turtle import Screen, Turtle

CURSOR_SIZE = 20

screen = Screen()
screen.setup(600, 600)  # 12 x 24 bricks
screen.setworldcoordinates(0, 0, 12, 24)  # coordinates based on bricks
screen.bgcolor('black')

turtle = Turtle('square', visible=False)
turtle.penup()
turtle.speed('fastest')
turtle.color('black', 'red')
turtle.shapesize(25 / CURSOR_SIZE, 50 / CURSOR_SIZE, 5)  # turn cursor into brick

for y in range(24):
    turtle.setposition(-0.5 * (y % 2), y + 0.3)

    for x in range(13):  # baker's dozen due to brick skew
        turtle.stamp()
        turtle.forward(1)

screen.mainloop()

enter image description here