initial commit

This commit is contained in:
lee2sman 2021-01-21 04:14:14 -05:00
parent 707a1620f0
commit 1f009f13e8
3 changed files with 65 additions and 5 deletions

37
README.md Normal file
View File

@ -0,0 +1,37 @@
# 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 or ability to loop.
## Commands
```
//movement
forward(n); //moves n pixels ahead
back(n); //moves n pixels back
left(Δ); //turns Δ degrees to the left
right(Δ); //turns Δ degrees to the right
//drawing
penup(); //will draw a line with movement commands
pendown(); //will move to x,y coordinates without drawing line
//By default, pendown is on / true
//randomness
randint(n); //returns a random int between 0 and n (exclusive)
//if no input, default is between 0 and 100
//example: forward(randint(30));
```

View File

@ -1,4 +1,4 @@
let angle,x,y;
let angle,x,y,drawing=true;
function setup(){
createCanvas(windowWidth,windowHeight); //canvas is size of window
resetDefaults();
@ -18,7 +18,11 @@ function forward(d,startx=x, starty = y, _angle = angle){
let newX = startx+d*sin(_angle);
let newY = starty+d*cos(_angle);
line(startx,starty,newX,newY);
if (drawing){
line(startx,starty,newX,newY);
}
x=newX
y=newY
}
@ -26,10 +30,13 @@ function back(d,startx=x, starty = y, _angle =360- angle){
let newX = startx+d*sin(_angle);
let newY = starty+d*cos(_angle);
line(startx,starty,newX,newY);
if (drawing){
line(startx,starty,newX,newY);
}
x=newX
y=newY
}
function left(_angle){
angle=180+_angle;
@ -37,6 +44,14 @@ function left(_angle){
function right(_angle){
angle=_angle;
}
function pendown(){
drawing=true;
}
function penup(){
drawing=false;
}
function randint(max=100){
//default returns int between 0 and 100
return int(random(max))

View File

@ -1,3 +1,11 @@
function turtle(){
forward(randint(100));
right(randint(100));
forward(randint(200));
right(randint());
forward(randint());
right(randint(45));
forward(randint(300));
}