Computerkunstwerke


Mondrian



# Mondrian.py
from gturtle import *
from random import *
import time

def maybe(bias = None):
    return choice ([False, True, bias, bias] if bias != None else [False, True])    

def between (a, b):
    return a + (0.2 + 0.3 * random ()) * (b - a)

recentColors = ['black', 'black']
def originalColor ():
    global recentColors
    while True:
        result = choice (colors)
        if result == 'white' or not result in recentColors:
            recentColors = [result, recentColors [0]]
            return result
    
def rect(xMin, yMin, xMax, yMax):
    for aColor in ('black', originalColor ()):
        setFillColor(aColor)
        penUp()
        moveTo(xMin, yMin)
        penDown()        
        startPath()
        moveTo(xMax, yMin)
        moveTo(xMax, yMax)
        moveTo(xMin, yMax)
        moveTo(xMin, yMin)
        fillPath()        
        xMin += delta
        yMin += delta
        xMax -= delta
        yMax -= delta
    
def draw (xMin = -250, yMin = -300, xMax = 250, yMax = 300):
    if xMax - xMin > threshold and yMax - yMin > threshold:
        if maybe (xMax - xMin > yMax - yMin):
            xMid = between(xMin, xMax)
            if maybe():
                draw(xMin, yMin, xMid, yMax)
                rect(xMid, yMin, xMax, yMax)
            else:
                rect(xMin, yMin, xMid, yMax)
                draw(xMid, yMin, xMax, yMax)
        else:
            yMid = between(yMin, yMax)
            if maybe():
                draw(xMin, yMin, xMax, yMid)
                rect(xMin, yMid, xMax, yMax)
            else:
                rect(xMin, yMin, xMax, yMid)
                draw(xMin, yMid, xMax, yMax)
    else:
        rect(xMin, yMin, xMax, yMax)

makeTurtle()
ht()
colors = ('gray', 'green', 'red', 'white', 'blue', 'yellow')
delta = 8
threshold = 100
setPenColor ('black')

while True:
    clear()
    draw ()
    time.sleep(2)
     
Programmcode markieren (Ctrl+C kopieren, Ctrl+V einfügen)

 

Georgia



# Georgia.py

from gturtle import *

makeTurtle()

clear ('black')

for a_color, a_pensize, start_radius, stop_radius, radius_step in (
    ('green', 1, 82, 40, -6),        
    ('red', 1, 84, 40, -6),    
    ('blue', 2, 98, 50, -5),
    ('yellow', 2, 70, 50, -5),
    ('red', 3, 97, 70, -5),
    ('orange', 2, 87, 40, -17),
    ('red', 3, 102, 60, -17),    
):
    penWidth (a_pensize)
    setPenColor (a_color)
    for angle_index in range (10):
        for radius in range (start_radius, stop_radius, radius_step):
            rightCircle (radius)
        right (36)
Programmcode markieren (Ctrl+C kopieren, Ctrl+V einfügen)

 

Stars


# Stars

from gturtle import *
from random import randint

def onMousePressed(x, y): 
    c = colors[randint(0, 4)]
    setFillColor(c)
    setPos(x, y)
    star() 

def star():
    startPath()
    repeat 30:
        forward(150)
        right(174.2) 
    fillPath()    

makeTurtle(mousePressed = onMousePressed)
ht()
setPenColor('red')
colors = ["yellow", "green", "blue", "orange", "black"]
c ="yellow"
Programmcode markieren (Ctrl+C kopieren, Ctrl+V einfügen)