S etup and draw functions
Download
1 / 9

s etup() and draw() functions - PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on

s etup() and draw() functions. Week 3. A block of code. A block of code is any code enclosed with curly brackets { } A block of code can be nested { { } }. Setup(). It can be used to define the base sketch setup, like its size, its mode For example void setup() {

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 's etup() and draw() functions' - danyl


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
S etup and draw functions

setup() and draw()functions

Week 3


A block of code
A block of code

  • A block of code is any code enclosed with curly brackets

    {

    }

  • A block of code can be nested

    {

    {

    }

    }


Setup
Setup()

  • It can be used to define the base sketch setup, like its size, its mode

  • For example

    void setup()

    {

    step 1a

    step 1b

    }

Do once


draw()

  • It can be used to define the base sketch setup, like its size, its mode

  • For example

    void draw()

    {

    step 2a

    step 2b

    }

Loop over and over


Example1 background in setup
example1Background in setup()

void setup(){

size(200,200);

background(255);

}

void draw(){

stroke(256,0,128);

fill(255,126,0);

rectMode(CENTER);

rect(mouseX, mouseY, 100,100);

}

Size and background are set once

Loops continualy until you close the sketch window


Example2 background in draw
Example2background in draw()

void setup(){

size(200,200);

}

void draw(){

background(255); //background is reset before each rect drawing

stroke(256,0,128);

fill(255,126,0);

rectMode(CENTER);

rect(mouseX, mouseY, 100,100);

}


Example 3 noloop
Example 3noLoop()

void setup(){

size(200,200);

background(255);

noLoop(); // this meeans that the draw function gets called once only.

}

void draw(){

stroke(256,0,128);

fill(255,126,0);

rectMode(CENTER);

rect(mouseX, mouseY, 100,100);

}


Example 4 loop
Example 4loop()

void setup(){

size(200,200);

background(255);

loop();

}

void draw(){

stroke(256,0,128);

fill(255,126,0);

rectMode(CENTER);

rect(mouseX, mouseY, 100,100);

}


ad