avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2128

Abstract

) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">200</span>) T<span class="hljs-selector-class">.right</span> (<span class="hljs-number">90</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">400</span>) T<span class="hljs-selector-class">.right</span>(<span class="hljs-number">90</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">200</span>) T<span class="hljs-selector-class">.end_fill</span>()</pre></div><div id="3846"><pre><span class="hljs-attribute">T</span>.back(<span class="hljs-number">400</span>) <span class="hljs-attribute">T</span>.right (<span class="hljs-number">90</span>) <span class="hljs-attribute">T</span>.forward (<span class="hljs-number">400</span>) <span class="hljs-attribute">T</span>.left(<span class="hljs-number">90</span>) <span class="hljs-attribute">T</span>.forward (<span class="hljs-number">200</span>)</pre></div><div id="615f"><pre><span class="hljs-attribute">T</span>.colormode (<span class="hljs-number">255</span>) <span class="hljs-attribute">T</span>.width (<span class="hljs-number">40</span>) <span class="hljs-attribute">for</span> i in range (<span class="hljs-number">200</span>): <span class="hljs-attribute">R</span> = random.randrange (<span class="hljs-number">256</span>) <span class="hljs-attribute">G</span> = random.randrange (<span class="hljs-number">256</span>) <span class="hljs-attribute">B</span> = random.randrange (<span class="hljs-number">256</span>) <span class="hljs-attribute">total</span> = R+G+B <span class="hljs-attribute">samp_color</span> = (R,G,B) <span class="hljs-attribute">T</span>.color (samp_color) <span class="hljs-attribute">X</span> = (random.randrange(-<span class="hljs-number">150</span>,-<span class="hljs-number">50</span>)) <span class="hljs-attribute">Y</span> = (random.randrange(-<span class="hljs-number">150</span>,-<span class="hljs-number">50</span>)) <span class="hljs-attribute">X1</span> = (random.randrange(<span class="hljs-number">50</span>,<span class="hljs-number">150</span>))

Options

<span class="hljs-attribute">Y1</span> = (random.randrange(<span class="hljs-number">50</span>,<span class="hljs-number">150</span>))</pre></div><div id="e2e3"><pre><span class="hljs-keyword">if</span> total ><span class="hljs-number">600</span>: T<span class="hljs-selector-class">.penup</span>() T<span class="hljs-selector-class">.goto</span> (X,Y) T<span class="hljs-selector-class">.pendown</span>() T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">30</span>) T<span class="hljs-selector-class">.right</span> (<span class="hljs-number">30</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">20</span>) T<span class="hljs-selector-class">.left</span> (<span class="hljs-number">20</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">10</span>)</pre></div><div id="4650"><pre><span class="hljs-keyword">if</span> total < <span class="hljs-number">200</span>: T<span class="hljs-selector-class">.penup</span>() T<span class="hljs-selector-class">.goto</span> (X1,Y1) T<span class="hljs-selector-class">.pendown</span>() T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">30</span>) T<span class="hljs-selector-class">.right</span> (<span class="hljs-number">30</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">20</span>) T<span class="hljs-selector-class">.left</span> (<span class="hljs-number">20</span>) T<span class="hljs-selector-class">.forward</span> (<span class="hljs-number">10</span>)</pre></div><p id="23ad"><a href="https://readmedium.com/c4d5fe0b9b6c?source=post_page-----acf8106ab83d----------------------">Jim McAulay🍁</a> says “Outside of a dog, a book is man’s best friend. Inside of a dog it is too dark to read.”</p><figure id="732c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*NtZngC8hIMSP2YLk.png"><figcaption>Buy me a coffee</figcaption></figure><p id="7387">91–90</p></article></body>

Painting With Light In Python Turtle

The more colour you add the lighter the image

Source screenshot my computer

In this lesson we demonstrate how colour works. When working with paint the more colour you add the darker the image. With light the more colour you add the lighter the image.

The human eye sees colour as a mixture of red,green and blue.

When you see paint which we call “red”. The paint is not actually red. The paint is blocking other colours so that only the red part of the spectrum of light is being reflected. As you add more colour you end up reflecting less light and the image gets darker.

When working with a computer you are working with light. the more “color” you add the lighter the image. if you add 255 pixels of red light 255 pixels of blue light and 255 pixels of green light you get white. and if you add 0 pixels of red, 0 pixels of blue and 0 pixels of Green you get black.

In the program below we create random colour combinations and add the total amount of red green and blue. Then we run the program 200 times. printing a squiggly line only with total amounts in upper and lower ranges.

import turtle as T
import random
T.color ("black")
T.goto (-200,-200)
T.begin_fill()
T.left (90)
T.forward (400)
T.right (90)
T.forward (200)
T.right (90)
T.forward (400)
T.right(90)
T.forward (200)
T.end_fill()
T.back(400)
T.right (90)
T.forward (400)
T.left(90)
T.forward (200)
T.colormode (255)
T.width (40)
for i in range (200):
    R = random.randrange (256)
    G = random.randrange (256)
    B = random.randrange (256)
    total = R+G+B
    samp_color = (R,G,B)
    T.color (samp_color)
    X = (random.randrange(-150,-50))
    Y = (random.randrange(-150,-50))
    X1 = (random.randrange(50,150))
    Y1 = (random.randrange(50,150))
if total >600:
        T.penup()
        T.goto (X,Y)
        T.pendown()
        T.forward (30)
        T.right (30)
        T.forward (20)
        T.left (20)
        T.forward (10)
if total < 200:
        T.penup()
        T.goto (X1,Y1)
        T.pendown()
        T.forward (30)
        T.right (30)
        T.forward (20)
        T.left (20)
        T.forward (10)

Jim McAulay🍁 says “Outside of a dog, a book is man’s best friend. Inside of a dog it is too dark to read.”

Buy me a coffee

91–90

Technology
Python
Jim Mcaulay
Illumination
Python Turtle
Recommended from ReadMedium