set Changes the value of a variable that has already been variable created to the value of the expression. (expression) In the above NetLogo code: creates a new variable and sets its value to 4.5. let x (4.5) x moves the turtle forward a number of steps equal to the value of forward x x. The first time through the repeat loop, the value of is 4.5. x changes the value of to the result of the expression set x (x + 4.5) x The first time this command is reached, has a value of 4.5 and (x + 4.5). x the expression therefore, has a value of 9.0. Thus, the first (x + 4.5), time this command is reached, the value of is changed from 4.5 to 9.0. x GOTCHA: In NetLogo, mathematical expressions must have a space before and after the operators. For example, is an error. (x + 4.5) is (x+4.5) correct. is inside the repeat loop and the second time it is reached, x has forward x the value 9.0 so the second line drawn by the turtle is 9.0 steps long. Just as a variable can be used as the number of steps in the command, a forward variable can be used as the angle in the right command and as the color in the set color command. More than one variable can be used if you want! You just need to use the let and set commands to create and modify each one separately. In the circles image, the forward command and turn angle command are both hardcoded constants, but inside the repeat loop is the command: set color (color + 1) HAVE FUN! Grading Rubric [20 points total]:
set variable (expression) Changes the value of a variable that has already been created to the value of the expression. In the above NetLogo code: let x (4.5) creates a new variable x and sets its value to 4.5. forward x moves the turtle forward a number of steps equal to the value of x. The first time through the repeat loop, the value of x is 4.5. set x (x + 4.5) changes the value of x to the result of the expression (x + 4.5). The first time this command is reached, x has a value of 4.5 and the expression (x + 4.5), therefore, has a value of 9.0. Thus, the first time this command is reached, the value of x is changed from 4.5 to 9.0. GOTCHA: In NetLogo, mathematical expressions must have a space before and after the operators. For example, (x+4.5) is an error. (x + 4.5) is correct. forward x is inside the repeat loop and the second time it is reached, x has the value 9.0 so the second line drawn by the turtle is 9.0 steps long. Just as a variable can be used as the number of steps in the forward command, a variable can be used as the angle in the right command and as the color in the set color command. More than one variable can be used if you want! You just need to use the let and set commands to create and modify each one separately. In the circles image, the forward command and turn angle command are both hardcoded constants, but inside the repeat loop is the command: set color (color + 1) HAVE FUN! Grading Rubric [20 points total]:
CS108_Spring2014_Week_3_Lab3_RepeatLoopSpiralingArt.docx