Skip to content

Commit 43ff518

Browse files
Added drawing examples
More examples
1 parent a14fb97 commit 43ff518

9 files changed

+60
-0
lines changed

Display/Draw a circle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
circle( 85, 60, 40 )
2+
sleep(2000)

Display/Draw a rectangle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rect( 15, 30, 140, 50 )
2+
sleep(2000)

Display/Draw filled circles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for(i=25; i<120; i+=30) {
2+
fillCircle( i, 50, 15 )
3+
sleep(500)
4+
}
5+
sleep(5000)

Display/Draw filled rectangles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for(i=25; i<120; i+=30) {
2+
fillRect( i, 20, 15, 80 )
3+
sleep(500)
4+
}
5+
sleep(5000)

Display/Draw lines from a point.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
while(true) {
2+
line( 85, 60, random() * 180, random() * 120 )
3+
sleep(500)
4+
}

Display/Draw many circles.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
while(true) {
2+
circle( random() * 180, random() * 120, random() * 40 )
3+
sleep(500)
4+
}

Display/Draw many rectangles.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
while(true) {
2+
rect( random() * 180, random() * 120, random() * 40, random() * 40 )
3+
sleep(500)
4+
}

Display/Draw random lines.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
while(true) {
2+
line( random() * 180, random() * 120, random() * 180, random() * 120 )
3+
sleep(500)
4+
}

Display/Etch A Sketch.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Etch A Sketch
2+
// Attach two medium motors to ports A and D
3+
// Attach a wheel to each motor to use as the knobs of the Etch A Sketch
4+
// This program uses the motor encoders to position a cursor on the LCD screen
5+
// Attach a touch sensor to clear the screen
6+
resetEncoder(A)
7+
resetEncoder(D)
8+
clearScreen()
9+
center = { x: 89, y: 64 } // Create a 'center point'
10+
cursor = { x: 0, y: 0 } // Initialize a cursor object
11+
scaling = 0.7 // Scaling can control how many degrees of rotation are needed to move the cursor
12+
while(true) { // Loop forever
13+
cursor.y = encoderValue(A) * scaling // Calculate a value for cursor.y (Encoder times scaling)
14+
cursor.x = encoderValue(D) * scaling // Calculate a value for cursor.x (Encoder times scaling)
15+
// Check the cursor values to see if they have exceeded the bounds of the LCD display
16+
// The encoderValues will return degrees of rotation (positive and negative) which
17+
// are used as an offset to the center point. If the encoder is less than zero, then
18+
// the cursor will be moved to the left or upwards on the LCD display. If the encoder
19+
// is greater than zero, then the cursor will be moved to the right or downwards.
20+
21+
if(cursor.y > center.y) cursor.y = center.y - 1 // If the value of the cursor.y is greater than the center.y, then center.y+cursor.y would be greater than the maximum y value for the LCD display. In this case, set the cursor.y to center.y minus 1.
22+
if(cursor.y < -1 * center.y) cursor.y = center.y * -1 + 1 // If the value of the cursor.y is less than the -1*center.y, then center.y+cursor.y would be less than zero. In this case, set the cursor.y to center.y*-1 plus 1.
23+
if(cursor.x > center.x) cursor.x = center.x - 1 // If the value of the cursor.x is greater than the center.x, then center.x+cursor.x would be greater than the maximum x value for the LCD display. In this case, set the cursor.x to center.x minus 1.
24+
if(cursor.x < -1 * center.x) cursor.x = center.x * -1 + 1 // If the value of the cursor.x is less than the -1*center.x, then center.x+cursor.x would be less than zero. In this case, set the cursor.x to center.x*-1 plus 1.
25+
fillCircle( center.x+cursor.x, center.y+cursor.y, 2) // Good coordinates here. Draw a circle with radius 2
26+
if(touchSensorPressed()) clearScreen() // If the touch sensor is pressed, clear the screen
27+
sleep(10)
28+
}
29+
30+

0 commit comments

Comments
 (0)