Play with Python

You can do some funny staff with Python. it simply amuses.
Issue this command in your Linux terminal:
sudo apt-get install python3-tk
It will install the necessary packages. Now it is time to write some code:


#!/usr/bin/python3

import turtle

pen = turtle.Pen()
pen.speed(0)
turtle.bgcolor("black")
colors =['red', 'orange', 'yellow', 'blue', 'pink', 'white', 'purple', 'green', 'light blue']
sides = 8

for x in range(360):
    pen.pencolor(colors[x % sides])
    pen.forward(x * sides / 3 + x)
    pen.left(360 / sides + 1)
    pen.width(x * sides / 100)

If you run this program, you will see something like this:

Python with turtle module

Python with turtle module

Advertisements

3 thoughts on “Play with Python

  1. since fig (uses python + pygame) doesnt have turtle commands, here is a similar spiral with cos and sin and line instead:

    # public domain
    npi = -3.14159    times 5
    pi = 0            minus npi
    r = 5
    xb = ""
    yb = ""
    xr = .01
    for p npi pi 0.0314159
        now = r    plus 3.14159     swap now r
        now = xr   plus .01570795   swap now xr   plus p
    
        x = now    times 12         cos           times r   int    plus 400
        y = now    times 12         sin           times r   int    plus 300
        c = now    times 1000       mod 7                   int    plus 8
    
        ifequal xb ""
            pass
        else
            now line xb  yb x  y c
            xbp = xb    plus 1
            xp  = x     plus 1
            now line xbp yb xp y c
            fig
    
        xb = x
        yb = y
        next
    now lineinput
    

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s