Unit 1: Day 12

START DATE:DUE DATE:STATUS:Open

Tasks

This lesson has been designed with flexibility in mind. You can:

  • Allow students to begin working through the remaining Unit 1 assignments at their own pace.
  • Introduce concepts from the Theory Unit.

12.1 Snowflake Example

  • This is a quick, extra example, just to show students some other uses for variables.
  • What will happen each time the mouse is pressed? What function is called? What impact does it have?

Unit 1 - Example 11 - Snowflake

let fontSize = 20;

let drawing = '*';

function setup() {

  let sketch = createCanvas(600, 400);

  sketch.parent("mycanvas");

  background(0);

  textAlign(CENTER,CENTER);

}//end setup

function draw() {

  //background(0);

  textSize(fontSize);

  fill( random(255), random(255), random(255) );

  text (drawing, mouseX, mouseY);

}//end draw

function mousePressed(){

  fontSize += 10;

  fill( random(255), random(255), random(255) );

  text (drawing, mouseX, mouseY);

}//end mousePressed

12.2 Loop Your Letter Example

  • This example has some similarities to the above example so you could choose one or the other. 
  • Introduce the concept of substring - could also be substituted using charAt(0) as part of a string.  
    • AAP-2.D.2: A substring is part of an existing string.

New Example - Loop Your Letter

let first

let numLetters

let xtemp, ytemp;

let tsize;

function setup() {

  createCanvas(600, 400);

  background(0);

  textAlign(CENTER,CENTER);  //this is new

first = window.prompt("Please enter your name (as a String)")

first = first.substring(0,1)

    numLetters = 1*window.prompt("Enter an int (not a float) between 10 and 100");

    tsize = numLetters * 2;

}//end setup

function draw() {

}//end draw

function mousePressed(){

    background(0)

    noStroke();     

    for(let i=0; i

      fill( random(255), random(255), random(255)   );

     textSize(20+random(tsize));

     xtemp = random(mouseX-tsize, mouseX+tsize);

     ytemp = random(mouseY-tsize, mouseY+tsize);

     text(first, xtemp, ytemp)         

    }//end for loop

    fill(0,0,155)

    textSize(200);

    text(first, mouseX, mouseY)

}//end mousePressed

12.3 Assignment 3 - Team Points

  • This assignment gets them focused on using variables with simple math


Continue to Unit 1: Day 13 »