0% found this document useful (0 votes)
160 views5 pages

Lesson 5 - Colors PDF

This document introduces using colors in Logo programs. It provides two ways to specify colors: using a color index from 0-15 to select from a predefined color table, or specifying red, green, and blue component values between 0-255 to create over 16 million custom colors. It includes examples of using the SETPENCOLOR and SETSCREENCOLOR commands to draw shapes on colored backgrounds and encourages experimenting with different color combinations.

Uploaded by

bluesky_1976
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views5 pages

Lesson 5 - Colors PDF

This document introduces using colors in Logo programs. It provides two ways to specify colors: using a color index from 0-15 to select from a predefined color table, or specifying red, green, and blue component values between 0-255 to create over 16 million custom colors. It includes examples of using the SETPENCOLOR and SETSCREENCOLOR commands to draw shapes on colored backgrounds and encourages experimenting with different color combinations.

Uploaded by

bluesky_1976
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lesson5:Colors

Thefirstfewlessonstaughtushowtowriteprogramsthatdrawpictures.Sofar,allofourprogramsdrawthe
blackandwhitepictures.Inthislesson,wearegoingtoaddcolorstoourpictures.
Logogivesyoutwowaystopickacolor.Onewayistopickacolorfromasetof16commonlyusedcolors.
Anotherwayistocreateyourowncolorbymixingdifferentamountsofred,green,andblue.Thisgivesyoua
choiceofover16milliondifferentcolors.

PenColorandScreenColor
YoucanchangethecolorofthelinesthattheturtledrawswiththeSETPENCOLORcommand.Youcan
changethecolorofthescreen(orbackground)withtheSETSCREENCOLORcommand.
Command
SETPENCOLOR
color

Example
SETPENCOLOR2

WhatHappens
Setsthecolorthattheturtledrawstogreen.

SETSCREENCOLOR SETSCREENCOLOR Fillstheentirescreenwithgreen.Anythingonthescreenwill


color
2
beerased.Theturtleisnotmoved.

ColorIndex
Theeasywaytochangethecoloroftheturtle'spenistogiveSETPENCOLORanumberfrom015.Each
numberwillsettheturtle'spentoadifferentcolor,giveninthetablebelow.Thenumberiscalledthe"color
index".
ColorIndex
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

ColorName

[RGB]
black
[000]
blue
[00255]
green
[02550]
cyan(lightblue)
[0255255]
red
[25500]
magenta(reddishpurple) [2550255]
yellow
[2552550]
white
[255255255]
brown
[1559659]
lightbrown
[19713618]
darkgreen
[10016264]
darkishblue
[120187187]
tan
[255149119]
plum(purplish)
[144113208]
orange
[2551630]
gray
[183183183]

Color

Activity:Drawabluesquareonayellowbackground.

SETSCREENCOLOR6
SETPENCOLOR1
REPEAT4[FORWARD100RIGHT90]

WhatwouldhappenifyouswitchedthenumberthatyougavetoSETSCREENCOLORand
SETPENCOLOR?Tryitandsee.
WhatwouldhappenifyougaveSETSCREENCOLORandSETPENCOLORdifferentnumbersall
together?Tryitandsee.
Whathappensifyouuseanumberthatislargerthan15?
Howdoyougetthecolorsbacktonormal(whitescreenandblackpen)?

Red,Green,andBlue
Whatdowedoifwewanttouseacolorthatisnotinthecolortable?Wecanspecifyitusingthecolorsred,
green,andbluecomponents.Thisissometimescalledan"RGBvalue".
Everycoloristheworldismadeupofred,green,andblue.Takentogether,red,green,andbluearecalled
"theprimarycolors"becauseyoucancreateeverycolorjustbymixingred,green,andbluetogether.
Youmaybethinking"wait,Ithoughttheprimarycolorswerered,yellowandblue."Well,that'spartlytrue.
Thoseareactuallythe"primarypigmentcolors".Theyaretheprimarycolorswhendealingwithpaint.
Actually,theprimarypigmentcolorsaren'texactlyred,yellow,andbluethey'remagenta(areddishpurple),
yellow,andcyan(alightblue).Butwhenyou'redealingwithlight,theprimarycolorsarered,green,andblue.
Thereasonwhyred,green,andbluearesoimportanthasnothingtodowithphysicsorcomputers.Ithastodo
withthestructureofthehumaneye.Thehumaneyecontainsthreetypesofcolorreceptorscalled"cones".
Onetypeofconeissensitivetoredlight,anotherissensitivetogreenlight,andanotherissensitivetoblue
light.Thebrainmixesthestimulusfromeachofthesetypesofconesandcreatestheperceptionofcolors.
That'sallveryinteresting,butwhatdoesthishavetodowithLogo?Well,Logoletsyouspecifycolorsin
termsofred,green,andblue.ByusingRGBvalues,youcanpickanyofthecolorsinthetableaboveand
morethat16millionothers.Insteadofspecifyinganumberfrom015,youspecifyatripleofnumbers,like
this"SETPENCOLOR[187187187]".
Activity:
Let'swriteaprogramthatdrawsabluesquareonayellowbackground.Butthistime,let'suseRGB
values,insteadofacolorindex.

SETSCREENCOLOR[2552550]
SETPENCOLOR[00255]
REPEAT4[FORWARD100RIGHT90]

Trychangingthenumbersinthesquarebracketandseewhathappens.

Activity:ExperimentwithSETPENCOLORandSETSCREENCOLORtocreateyourowninteresting
pictures.YoucanstartwithanyprogramfromtheotherlessonsandinsertaSETSCREENCOLOR
commandnearthebeginning,orinsertaSETPENCOLORcommandjustbeforetheturtlemoves.

SamplePrograms
TOSQUARE
REPEAT4[FORWARD50RIGHT90]
END
TOSETPEN:BRIGHTNESS
SETPENCOLOR(LIST
255;red
255:BRIGHTNESS;green
:BRIGHTNESS;blue
)
END
TOSQUAREFLOWER
REPEAT64[
SETPENREPCOUNT*41
RIGHT360/64
SQUARE
]
END
SQUAREFLOWER

TOCOLORSTAR
SETSCREENCOLOR0
REPEAT35[
SETPENCOLORINT(REPCOUNT1)/5
FORWARDREPCOUNT*6
RIGHT144
]
END
COLORSTAR

TOCOLORBALL
REPEAT4[
SETPENCOLORREPCOUNT
REPEAT120[FORWARDREPCOUNT*2RIGHT204]
HOME
RIGHT90*REPCOUNT
]
END
COLORBALL

TORECTANGLE:HEIGHT:WIDTH
REPEAT2[
FORWARD:HEIGHT
RIGHT90
FORWARD:WIDTH
RIGHT90
]
END
TOTRIANGLE:LENGTH
RIGHT45
FORWARD:LENGTH*(SQRT2)/2
RIGHT90
FORWARD:LENGTH*(SQRT2)/2
RIGHT135
FORWARD:LENGTH
RIGHT90
END
TOHOUSE
;drawaredroof
SETPENCOLOR[25500]
FORWARD100
TRIANGLE100
BACK100
;drawadarkgreendoor
SETPENCOLOR[10016264]
RIGHT90

FORWARD60
LEFT180
RECTANGLE2040
FORWARD60
RIGHT90
;drawabrownhouse
SETPENCOLOR[1559659]
RECTANGLE100100
END
HOUSE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy