A nascent LOGO-like library built in p5.js
Go to file
2021-02-14 01:44:15 -05:00
lib add bg() and console text display 2021-02-14 01:44:15 -05:00
favicon.ico add turtle favicon 2021-01-21 04:21:17 -05:00
index.html add minimal stylesheet spacing 2021-02-14 01:43:47 -05:00
README.md updated README to explain name 2021-02-07 04:49:20 -05:00
style.css add minimal stylesheet spacing 2021-02-14 01:43:47 -05:00
turtle.js change default example script 2021-01-29 13:39:14 -05:00

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.

example program

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.

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

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
  • 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.