Playfield objects such as the world object have a category called pen trails with tiles for managing pen use in all objects within the Playfield's bounds. Pen trail drawings may also be captured and assigned to graphic variables or to a Sketch object. You can manage pens entirely with Etoys tiles but I wanted the script to do something there was no tile for and added some smalltalk code.
The logo was drawn using a small Ellipse object. The "reset" script initializes the Ellipse's heading, script variables and location and clears any previously drawn pen trails.
The "drawTri" script creates the drawing. The Ellipse is moved forward by the value in variable "l" and then is turned by the value in variable "ang". Variable "l" is increased by 2. Variable "cph" is used in the script "changeHue" which is called after the "cph" variable is checked. The "cph" variable is explained in the coding description below. These statements are repeated 90 times.
There are no tiles available to manipulate the pen trail's colors. The pen color is explicitly assigned. I wanted my pen trails to change colors across the spectrum. To do so I switched to coding in text. This is done by selecting the menu options in the Script Editor menu bar and selecting show code textually. You can switch back to the tile version but you'll lose any code you have typed. When you drag out the "Ellipse's pen color" tile by the assignment symbol and switch to text mode you can see that the color is expressed with an rgb value. I wanted to express it as an hsv value so I could change the hue while keeping saturation and brightness the same.
saturation Returns the saturation of the color. 0.0 to 1.0
brightness Returns the brightness of the color. 0.0 to 1.0". Now to look for a method to set the hsv value. The third column lists method categories and the fourth column lists available methods in each category. At the bottom of the second column there are three buttons. One is for instances of the class, one is for documentation and one is for the class. I'm creating a new instance of Color not working with an instance so the class button is selected then the instance creation category is selected in the third column. The h.s.v. method looks similiar to the r.g.b. method so I have enough information to edit the script
Change the name of the script to changeHue. Replace r: 1.0 with h: self getCph. self refers to the Ellipse object. getCph gets the value of the cph variable. The first letter of the variable needs to be capitalized. It doesn't seem to matter when creating variables in the viewer because they are automatically converted but when writing your own code you'll need to do it. Replace g: 0.5 with s: 0.5 and b: 0.534 with v: 1.0. Add a period after the last parantheses so another statement can be added. The script will be repeated 90 times so to get through all the colors the cph variable needs to be increased by 360/90 each time. "self setCph: self getCph + 4" gets the value of variable cph adds 4 to it and sets the result to variable cph. This construction of assigning and accessing object variables defined in the viewer are Etoys methods. Press ctrl-s to save the script. I test cph in the drawTri script to make sure it resets back to 0 if cph gets increased past 360.
After running "reset" and "drawTri", I used the grab tool to convert the pen trail to a sketch and did some post processing. I filled the background with no color(transparent), added a light grey drop shadow and saved the Sketch as an image.
Last Updated.