Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you draw a line on the screen in Python? Here's BASIC. I'm not saying this is good. But it is easy.

  SCREEN 13 
  LINE (X1, Y1) - (X2, Y2), COLOUR


> How do you draw a line on the screen in Python?

Using only stdlib:

  import turtle
  turtle.penup()
  turtle.pencolor(colour)
  turtle.setpos(x1,y1)
  turtle.pendown()
  turtle.goto(x2,y2)


I tried it and it works. But that drawing window seems almost broken. It doesn't repaint properly when I resize it, and closing it seems impossible.


I am guessing that is straight-up LOGO on Python.


It is turtle library inspired by Logo alright, but important thing is that it was available from very early versions of python onwards, and by default available when python is installed.


I didn't realize the lib was in there by default. It is instantly recognizable as Logo, although the syntax is clearly python.

This video from Mathologer about solving polynomial equations might be just as easy to implement in Python with that library as it would be under NetLogo (a more multi-dimensional science-oriented implementation of Logo), which certainly justifies having a turtle library to begin with: https://www.youtube.com/watch?v=IUC-8P0zXe8

I'd hate to program that under BASIC.


Not exactly, but the turtle library was inspired by Logo, and designed to enable fairly direct translation of Logo code.


This is where a lot of modern languages are hard for kids. You have to find a library to do things you want to do.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: