Resource: DEMO Code for teaching Unit 3

Below are several DEMO programs for students to see the power of:

Defining and calling Functions, Abstraction, Parameters, Loops, Randomizing and several commands such as penUp, penDown, penRBB, penWidth, moveTo, and so many others:


You can see the actually code by click BUILT ON CODE STUDIO & HOW IT WORKS

2 Likes

jkeays!
Thank you for sharing! This is a great collection of programs for students in principles and even the explore cs class. I am definitely sharing your programs with my students.

Could you tell me how many times your first app runs to create squares? I believe it is 500, but the title for the app states 20.

Thanks again!!
Keith

We keep changing the loop everytime I show students. So here’s the code you can copy and paste and change the parameters to show your students. Peace

//Draw Square Art
penUp();

for(var i=0;i<20;i++)
{
moveTo(randomNumber(50,320), randomNumber(50,450));
square(randomNumber(50,100));
}
moveTo(400,400);
//Program Ends

//Function to Draw a Square
function square(s) {
penWidth(randomNumber(1,15));
penColor(getRandomRgb());
penDown();

for(var j=0;j<4;j++)
{
drawSide(s);
}
penUp();
}

//Function to generate a Random RGB Color
function getRandomRgb() {
var r=randomNumber(0,255);
var g=randomNumber(0,255);
var b=randomNumber(0,255);
return β€˜rgb(’ + r + ', ’ + g + ', ’ + b + β€˜)’;
}

//Function to Draw 1 Side of the Square
function drawSide(length)
{
moveForward(length);
turnLeft(90);
}

1 Like