How to put if and then statements while creating snowflakes in python
<p>--im a beginner ..so im not sure how to make sure that the snowflakes don't overlap. Thanks!</p>

<pre><code>import turtle

turtle.right(90)

turtle.penup()

turtle.goto(-700,300)

turtle.pendown()

def snowflakebranch(n):

    turtle.forward(n*4)
    for i in range(3):
        turtle.backward(n)
        turtle.right(45)
        turtle.forward(n)
        turtle.backward(n)
        turtle.left(90)
        turtle.forward(n)
        turtle.backward(n)
        turtle.right(45)

def snowflake(n):

    for i in range(8):
        snowflakebranch(n)
        turtle.backward(n)
        turtle.right(45)

import random

turtle.colormode(255)

turtle.tracer(0)

for i in range(35):

    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    turtle.color(r, g, b)
    x = random.randint(-500, 500)
    y = random.randint(-500, 500)
    d = random.randint(6, 16)
    snowflake(d)
    turtle.penup()
    turtle.goto(x, y)
    #turtle.forward(250)
    turtle.pendown()


    turtle.update()
</code></pre>

<p>One approach would be to calculate a bounding rectangle (or circle) for each snowflake.  Save these as a list or a set.  Whenever you plan to make a new snowflake, first check if its bounding rectangle (or circle) overlaps with the bounds of any previous snowflakes.  If it does, don't draw it.  If it doesn't, draw it and save its bounds too.  An incomplete outline of this approach:</p>

<pre><code>import turtle
import random

def snowflakebranch(n):

    turtle.forward(n * 4)

    for _ in range(3):
        turtle.backward(n)
        turtle.right(45)
        turtle.forward(n)
        turtle.backward(n)
        turtle.left(90)
        turtle.forward(n)
        turtle.backward(n)
        turtle.right(45)

def snowflake(n):

    for _ in range(8):
        snowflakebranch(n)
        turtle.backward(n)
        turtle.right(45)

def overlapping(bounds_list, bounds):
    for previous in bounds_list:
        if overlap(previous, bounds):
            return True

    return False

def overlap(b1, b2):
    # return True or False if these two rectanges or circles overlap
    pass

turtle.penup()

turtle.colormode(255)

turtle.tracer(0)

previous_bounds = []

i = 0

while i &lt; 35:

    x = random.randint(-500, 500)
    y = random.randint(-500, 500)
    turtle.goto(x, y)

    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    turtle.color(r, g, b)

    turtle.pendown()

    d = random.randint(6, 16)

    # work out the bounding rectangle or circle based on 'd', 'x' &amp; 'y'
    # e.g. (x, y, width &amp; height) or (x, y, radius)
    bounds = ( ... )  

    if not overlapping(previous_bounds, bounds):

        snowflake(d)

        turtle.update()

        previous_bounds.append(bounds)

        i += 1

    turtle.penup()

turtle.done()
</code></pre>

<p>An image of non-overlapping snowflakes using the above logic with the bounding circles also displayed:</p>

<p><a href="http://i.stack.imgur.com/CuJMQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/CuJMQ.png" alt="enter image description here"></a></p>

<p>I actually like the look of your overlapping snowflakes.  Even if you want overlap, the above logic will allow you to control how much overlap.</p>

python turtle-graphics