Class 28 — Friday November 2

Graphical drawing

TBD


Look both ways


Agenda


Examples


Discussion

  • m will always be the string 'RGB';
  • size will always be an ordered pair of a list of the form [ w, h ], where w is the width of the image and h is the height of the image.

Homework 22


Pillow epistle

from PIL import Image, ImageDraw


Image

rgb coloring

im_width = 480

im_height = 400

dimensions = [ im_width, im_height ]

im = Image.new( 'RGB', dimensions, color='Black' )

pillow canvas

im.show()

im.save( 'canvas.jpg' )

Function save() expects a string parameter giving the name for the picture file. The file will be located in the same folder as the program that did the saving.


ImageDraw

canvas = ImageDraw.Draw( im )


x = 40

y = 80

w = 50

h = 75

xy = [ ( x, y ), ( x + w, y + h ) ]

canvas.rectangle( xy, outline='Cornsilk' )

Further, the shape is to be the outline of a rectangle with the outline colored green. Parameter outline is optional, if specified its value is to be the color of the perimeter.

perimenter rectangle

x = 100

y = 20

w = 100

h = 25

xy = [ (x, y), (x + w, y + h) ]

canvas.rectangle( xy, fill='Lavender', outline='Orchid' )

Adds a filled-in rectangle to our drawing.

filled rectangle

x = 120

y = 65

w = 150

h = 90

xy = [ (x, y), (x + w, y + h) ]

canvas.ellipse( xy, outline='Magenta' )

x = 300

y = 25

w = 50

h = 75

xy = [ (x, y), (x + w, y + h) ]

canvas.ellipse( xy, fill='DeepPink', outline='GhostWhite' )

Both ellipses have their perimeter drawn; and one also has its background coloorange red.

ellipses

coord = ( 25, 200 )

s = 'We are the best'

canvas.text( coord, s, fill='Moccasin' )

to add the string 'We are the best' to our drawing. The first parameter to the function is the location to start the text; the second parameter is the desired text.

text

p0 = ( 25, 215 )

p1 = ( 115, 215 )

xy = [ p0, p1 ]

canvas.line( xy, s, fill='Moccasin' )

adds a horizontal line below our text.

line

p0 = (350, 120)

p1 = (400, 140)

p2 = (425, 200)

p3 = (425, 260)

p4 = (375, 245)

p5 = (325, 190)

seq = [ p0, p1, p2, p3, p4, p5 ]

canvas.polygon( seq, outline='Peru' )

p0 = (175, 80)

p1 = (240, 110)

p2 = (190, 130)

p3 = (150, 120)

seq = [ p0, p1, p2, p3 ]

canvas.polygon( seq, fill='RebeccaPurple' )

arc

p0 = ( 140, 220 )

p1 = ( 340, 380 )

xy = [ p0, p1 ]

a1 = 0

a2 = 90

canvas.arc( xy, a1, a2, fill='RoyalBlue' )

Note, a 0° angle points east; a 90° angle points south; a 180° angle points west; a 270° angle points north.

arc

p0 = ( 140, 220 )

p1 = ( 340, 380 )

xy = [ p0, p1 ]

a1 = 150

a2 = 210

canvas.chord( xy, a1, a2, fill='MediumTurquoise' )

chord

p0 = ( 140, 220 )

p1 = ( 340, 380 )

xy = [ p0, p1 ]

a1 = 225

a2 = 315

canvas.pieslice( xy, a1, a2, fill='OrangeRed' )

pie slice


To do


Imagery

rocket

gradient random

psychadelic art

blue-orange randomized pic

 


 

 

 
   
   
   
 
  © 2019 Jim Cohoon   Resources from previous semesters are available.