PLOGO/README.md

126 lines
2.1 KiB
Markdown
Raw Normal View History

2021-01-21 09:14:14 +00:00
# PLOGO
Purchase LOGO
A toy language.
A kind of LOGO-like DSL built in the p5.js library.
2021-01-29 18:39:23 +00:00
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.
2021-01-21 09:14:14 +00:00
2021-01-29 18:54:53 +00:00
![example program](example.jpg)
2021-01-21 09:18:38 +00:00
## How to Use
Put your code inside the turtle function in turtle.js
## Reference Commands
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
### Movement
```
forward(n)
2021-01-21 09:14:14 +00:00
```
2021-01-29 18:39:23 +00:00
move n pixels ahead
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
back(n)
```
move n pixels back
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
left(Δ)
```
turns Δ degrees to the left
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
right(Δ)
```
turns Δ degrees to the right
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
### Drawing
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
penup()
```
Going forward, Turtle will stop drawing a line with movement commands
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
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')```
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
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
2021-01-21 09:44:35 +00:00
2021-01-29 18:39:23 +00:00
### Randomness
2021-01-21 09:14:14 +00:00
```
2021-01-29 18:39:23 +00:00
randint(n)
```
or
2021-01-21 09:14:14 +00:00
2021-01-29 18:39:23 +00:00
```
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);
```