week 2

Introduction

  • Importance of studying variables in programming

  • Application of Processing; visual representation of code execution

Overview of Variables

  • Variable Basics

    • Variables are identifiers used to store data values.

    • Examples discussed are width and height.

    • Inbuilt variables help manage certain data types within the Processing environment.

Memory Representation of Variables

  • Each variable stores a value in a designated box (memory location) labeled by the variable name:

    • Example: size(400, 300);

      • width stores 400.

      • height stores 300.

  • Variable names must be unique to avoid conflicts.

Types of Variables

  • Inbuilt Variables:

    • mouseX, mouseY: track cursor locations.

    • Importance of naming conventions (case sensitivity).

  • User-defined Variables:

    • User can define variables with specific data types:

      • int: for integers (whole numbers).

      • float: for decimal numbers.

      • char: for single characters.

      • boolean: true/false values.

Coding Setup

  • Basic Structure:

    • void setup(): initializes settings once when the program starts.

    • void draw(): continuously executes code; runs in a loop.

Drawing with Cursor Interaction

  • Drawing a line from the top left corner to cursor position using mouseX and mouseY.

  • Implementation of resetting the background using background(255) to clear previous drawings.

  • Execution speed: draw() runs 60 times per second,

Common Errors

  • Potential errors arise from variable names and their casing (e.g., MouseY vs mouseY).

  • Importance of checking the spelling of inbuilt variables when errors occur.

Incrementing Values

  • Using variables to change visual representations:

    • Example: Making a circle or object move by incrementing the Y-coordinate (yPosition++).

  • Need for update in variable assignment each frame in draw() to create movement.

  • Global Variables allow access across multiple functions; declared outside the setup and draw.

Animation Concept

  • Create animations with objects moving across the screen and changing properties over time (increasing size, position).

  • Importance of clever use of loops and conditional statements for dynamic movement.

Challenge: Create a Random Circle App

  • Task to create a program generating random circles upon mouse click:

    • Use random(width) and random(height) to place circles at random coordinates.

  • Adjusting circle sizes upon each click to increase diameter to visualize growth over time.

  • Encouragement to keep learning through practice and further projects involving conditions and variable interactions.

Conclusion

  • Recap importance of variables, conditions, and loops in programming.

  • Reminder about practice to solidify programming concepts discussed in the session.

robot