90 likes | 221 Views
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() {
E N D
setup() 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() { 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
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
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 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 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); }