python - How can I create a plane using turtle and for statements? -
my teacher me use turtle
make plane (graphing plane) for
statements. can't figure out wondering if provide code me.
#my start of code import turtle wn = turtle.screen() t = turtle.turtle()
maybe example helpful. it's hard learn program merely reading code, need experimental: pull apart & put again until understand different pieces doing. play code, , try modifying various things see happens.
#! /usr/bin/env python ''' draw squared grid filling visible portion of turtle window http://stackoverflow.com/q/29943686/4014959 written pm 2ring 2015.04.30 ''' import turtle def draw_lines(current, num, length, delta): in range(num): turtle.up() turtle.goto(current) turtle.down() turtle.forward(length) current += delta def draw_grid(step): cols = turtle.window_width() // step rows = turtle.window_height() // step mx, = cols * step, rows * step origin = turtle.vec2d(-mx // 2, -my // 2) #horizontals delta = turtle.vec2d(0, step) draw_lines(origin, rows + 1, mx, delta) #verticals turtle.left(90) delta = turtle.vec2d(step, 0) draw_lines(origin, cols + 1, my, delta) def main(): turtle.setup(width=0.8, height=0.8) turtle.hideturtle() turtle.speed(0) draw_grid(25) #wait window closed turtle.done() if __name__ == '__main__': main()
Comments
Post a Comment