Sunday, November 27, 2016

Coding Project 2 - STEM - Lou Person

STEM Lab by Lou Person: Draw four boxes.

In this lab, you will use the Quite BASIC coding emulator to draw four boxes in a row.  You will use a FOR statement to loop through code.  You will also work with the PLOT command, which has the following syntax: PLOT X, Y, C  where X is the X axis, Y is the Y axis and C is a color.

First, enter this code into the Quite BASIC emulator:
2000 CLS
2110 LET X = 4
2140 LET C = "green"
5000 REM Subroutine -- draw a circle
5010 FOR Y = 0 TO 4
5020 PLOT X,Y, C
5030 NEXT Y

Second, run the code.  You'll see the 4 boxes appear.

Third, change the value in the FOR statement from 4 to 10.  What happens?

Fourth, change the word "green" to "red".  What happens when you run the code?

Fifth, change the PLOT statement to say PLOT X+5,Y,C and run the code.  What happens?

Sixth, change the PLOT statement to say PLOT X+Y,Y,C and run the code.  What happens?

The FOR statement gets executed starting at 0 up TO the number of times you enter.  So, when you change it to 10, you should notice that 10 boxes appeared instead of 4.

The statement LET defines a variable.  In line 2140, you defined a string variable which is why the word is in between double quotes.  If you change the color to another color, such as red, the boxes are drawn in red.  In line 5020, the PLOT command uses C to determine what color it should draw the boxes in.  So when you change C to a different color, the PLOT statement will draw the boxes in that color.

The PLOT statement draws a box, or pixel, based on the X and Y coordinates provided.  This is similar to a chart with an X and Y axis.  By adding 5 (X+5) to the X access, the line of boxes starts 5 boxes to the right.  This is also known as offsetting by 5 pixels. 

Each time the FOR loop is executed, the values will be:
X     Y
4      0
4      1
4      2
4      3
4      4

To make the line horizontal, each box will need to move up 1 pixel and right 1 pixel.  The Y access increases 1 each time.  In order to move 1 to the right each time, add Y to X.  The coordinates will look like this:
X     Y
4      0
5      1
6      2
7      3
8      4

These are the coordinates that represent a horizontal line.

Coding Project 1 - STEM - Lou Person

STEM Lab by Lou Person: Introduction to Quite BASIC.


This lab is geared for students ages 10-12.  It should take 15 minutes to complete.  The goal of this lab is to get used to work with the Quite BASIC coding emulator.  During the lab, you will edit the code and then run the code.  You will also test and fix a bug in the code.


Second, change the code to this (you can select the old code, delete it and copy and past this code in:


1200 CLS
2010 REM
2020 PRINT
2300 REM User input
2320 PRINT "Press 1, 2, 3, 4, or 5!"
2330 LET A = GETCHAR()
2340 IF A = "1" OR A = "2" OR A = "3" OR A = "4" OR A = "5" THEN GOTO 2370
2350 PAUSE 100
2560 GOTO 2330
2370 PRINT
2380 IF A = "1" THEN PRINT "1 ----------"
2390 IF A = "2" THEN PRINT "2 ----------"
2400 IF A = "3" THEN PRINT "3 ----------"
2410 IF A = "3" THEN PRINT "4 ----------"
2420 IF A = "5" THEN PRINT "5 ----------"
2430 END
5040 RETURN

Third, fix the bug where A is not being checked for 4.

Fourth, change the print statement to replace the ------------ with meangingful messages of whatever you want.