A nascent LOGO-like library built in p5.js
Go to file
2021-01-29 13:54:53 -05:00
lib fix movement angle 2021-01-29 13:38:58 -05:00
example.jpg add example image 2021-01-29 13:54:53 -05:00
favicon.ico add turtle favicon 2021-01-21 04:21:17 -05:00
index.html add favicon.ico 2021-01-21 04:28:03 -05:00
README.md add example image 2021-01-29 13:54:53 -05:00
turtle.js change default example script 2021-01-29 13:39:14 -05:00

PLOGO

Purchase LOGO

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

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

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);