initial commit
This commit is contained in:
parent
707a1620f0
commit
1f009f13e8
|
@ -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));
|
||||
```
|
||||
|
23
sketch.js
23
sketch.js
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue