2.9 KiB
PLOGO
Purchase LOGO
(currently named for my uni).
A toy language.
A kind of LOGO-like DSL built in the p5.js library.
This is a rudimentary proof of concept right now with globals and without implementing classes. To write loops or subroutines one must use regular javascript.
How to Use
Put your code inside the turtle function in turtle.js
Reference Commands
Movement
forward(n)
move n pixels ahead
back(n)
move n pixels back
left(Δ)
turns Δ degrees to the left
right(Δ)
turns Δ degrees to the right
setpos(x,y)
moves turtle to x,y pixel coordinate. 0,0 is top left of window.
Drawing
penup()
Going forward, Turtle will stop drawing a line with movement commands
pendown()
Turtle will start drawing lines tracing route. By default, pendown is on / true
penColor('colorName')
penColor takes any color word: purple, grey, blue, etc. The color name must be in quotes.
Alternatively, a HTML color name, like #ff4d4d, may be specified in quotes. Example: penColor('$ff4d4d')
Alternatively, a RGB color or RGBA color with transparency can be specified, with color. Example: penColor(color(255,0,255))
. See transparency example in examples section below.
penSize(n)
Width of pen in pixels
retro()
Adds a retro filter on the entire drawing. This command can be called anywhere and filter is always applied at the end of the program.
noConsole()
Turns off the default onscreen display of the program listing.
Randomness
randint(n)
or
randint()
Returns a random int between 0 and n. Specifying a value is optional. If no input n, the default is between 0 and 100. Example: forward(randint(30))
Examples
More examples in the examples folder
Backwards box
penColor('orange');
penSize(3);
left(90);
back(100);
left(90);
back(100);
left(90);
back(100);
left(90);
back(100);
Random Walk (with javascript for-loop)
for (let i = 0; i < 100; i++){
right(randint());
forward(randint());
}
Forward, with color transparency
In this example, the last parameter inside penColor's color is the alpha transparency amount. Like the individual red, green, blue colors specified before it, this can be a number from 0 to 255. The lower the number, the more transparent.
penSize(20);
penColor(color(100,0,100,50));
forward(100);
penColor(color(100,0,100,150));
forward(100);
penColor(color(100,0,100,250));
forward(100);
Updates
2021-02-07
- Added onscreen console print of commands (on by default) and noConsole() to turn off
- Added more example files
2021-02-07
- Re-render turtle() after screen resizing
- Added new setpos(x,y) function to move turtle to a position. A path will be drawn if the pen is currently down.
- add retro() command for retro filter.