Upload
laurafries
View
214
Download
0
Embed Size (px)
Citation preview
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 1/31
Computation as an ExpressiveComputation as an Expressive
Lab Lab 2 2: : K indergarten Cubbies,Kindergarten Cubbies,Back to the Future and Lego Back to the Future and Lego
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 2/31
s ees ee
Assignment 1 Assignment 1
TimeTime ast ngast ng
Reading codeReading code Project 1Project 1
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 3/31
Assignment Assignment 11
A A11--0101: Draw three lines.: Draw three lines. A A11--0202: Draw five lines.: Draw five lines.
-- .. A A11--0404: Control the position of two lines with one variable.: Control the position of two lines with one variable.
A A11--0505: Control the position and size of two lines with two variables.: Control the position and size of two lines with two variables. A A11--0606: Control the properties of two shapes with two variables.: Control the properties of two shapes with two variables.
-- A A11--0808: Program your pattern from Assignment: Program your pattern from Assignment 11--0707 using while().using while(). A A11--0909: Draw a layered form with two new loops.: Draw a layered form with two new loops.
A A11--1010: Redo Assignment: Redo Assignment 11--0505 using mouseX and mouseY as the variables.using mouseX and mouseY as the variables. A A11--1111: Draw two visual elements that each move in relation to the mouse in a: Draw two visual elements that each move in relation to the mouse in adifferent way.different way. A A11--1212: Draw three visual elements that each move in relation to the mouse in a: Draw three visual elements that each move in relation to the mouse in adifferent way.different way.
A A11--1313: Move a visual element across the screen. When it disappears off the edge,: Move a visual element across the screen. When it disappears off the edge,move it back into the frame.move it back into the frame. A A11--1414: Draw a visual element that moves in relation to the mouse but with a: Draw a visual element that moves in relation to the mouse but with adifferent relation when the mouse is pressed.different relation when the mouse is pressed. A A11--1515: Using if and else, make the mouse perform different actions when in different: Using if and else, make the mouse perform different actions when in different
parts of the window.parts of the window. A A11--1616: Develop a kinetic image which responds to the mouse.: Develop a kinetic image which responds to the mouse.
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 4/31
w rw r
Don’t get too caught up in syntaxDon’t get too caught up in syntax he API is your friendhe API is your friend
Have fun with our assi nmentsHave fun with our assi nments
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 5/31
BrianBrian JoshuaJoshua
Class gradesClass grades
Assignment Assignment gradesgrades
Due datesDue dates
assignmentsassignments
I love my TA I love my TA ove my pro essorove my pro essor
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 7/31
rr yrr y
Clark Bruce Diana Peter
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 8/31
rr yrr y
Clark Bruce Diana Peter
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 9/31
int[] numbers = new int[3];
OR int[] numbers = {90, 150, 30};
0 1 2
numbers[0] = 90;
numbers[1] = 150;
numbers[2] = 30;
90 150 30
0 1 2
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 10/31
Arra s Arra s
Clark Bruce Diana Peter
Clark Bruce Diana Peter
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 11/31
rr yrr y
*Some exceptions apply
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 12/31
y ry r
ConciseConcise
LoopLoop--ableable
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 13/31
BubblesortBubblesortvoid bubblesort(int[] input)
{
n emp = - ;
for(int i = 0; i < input.length; i++) {
or n = ; < npu . eng - ; ++
{
if(input[j] > input[j+1])
temp = input[j+1];
input[j+1] = input[j];
input[j] = temp;
} //end if
} //end for(j)
} //end for(i) }
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 14/31
rr
arrayCopy()arrayCopy() sort()sort()
eexpand()xpand()
subset()subset()
rreverse()everse()
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 15/31
rr yrr y
//Retrieving array values
int a = numbers[0] + numbers[1]; // Sets variable a to 240
int b = numbers[1] + numbers[2]; // Sets variable b to 180
//Changing array size at runtime
String[] sa1 = { "OH ", "NY ", "CA "};
String[] sa2 = append(sa1, "MA ");
println(sa2); // Prints OH, NY, CA, MA
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 16/31
imeime
int minute()int minute()
int second()int second()
int day()int day() int month()int month()
long millis()long millis()
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 18/31
int x = 3;
int y = x/2; //y = 1?????
int x = 3;
float y = (float)x/2; //y = 1.5
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 19/31
void setup()
{
size(400,400);
}
int ellipseSize = 1;
void draw()
{
smooth();background(0);
stroke(234,98,71);strokeWeight(10); fill(0); ellipse(200,200,ellipseSize,ellipseSize);
mouse > && mouse < && mouse > && mouse <
{
ellipseSize = ellipseSize + 1;}
else
ellipseSize = ellipseSize - 1;
}
if (ellipseSize < 1)
ellipseSize = 1;}
if (ellipseSize > 400)
ellipseSize = 400;}
}
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 20/31
void setup()
{
size(400,400);
}
int ellipseSize = 1;
void draw()
{
smooth();background(0);
stroke(234,98,71);strokeWeight(10); fill(0); ellipse(200,200,ellipseSize,ellipseSize);
mouse > && mouse < && mouse > && mouse <
{
ellipseSize = ellipseSize + 1;}
else
ellipseSize = ellipseSize - 1;
}
if (ellipseSize < 1)
ellipseSize = 1;}
if (ellipseSize > 400)
ellipseSize = 400;}
}
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 21/31
void setup()
{
size(400,400);
}
int ellipseSize = 1;
void draw()
{
smooth();background(0);
stroke(234,98,71);strokeWeight(10); fill(0); ellipse(200,200,ellipseSize,ellipseSize);
mouse > && mouse < && mouse > && mouse <
{
ellipseSize = ellipseSize + 1;}
else
ellipseSize = ellipseSize - 1;
}
if (ellipseSize < 1)
ellipseSize = 1;}
if (ellipseSize > 400)
ellipseSize = 400;}
}
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 22/31
void setup()
{
size(400,400);
}
int ellipseSize = 1;
void draw()
{
smooth();background(0);
stroke(234,98,71);strokeWeight(10); fill(0); ellipse(200,200,ellipseSize,ellipseSize);
mouse > && mouse < && mouse > && mouse <
{
ellipseSize = ellipseSize + 1;}
else
ellipseSize = ellipseSize - 1;
}
if (ellipseSize < 1)
ellipseSize = 1;}
if (ellipseSize > 400)
ellipseSize = 400;}
}
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 23/31
void setup()
{
size(400,400);
}
int ellipseSize = 1;
void draw()
{
smooth();background(0);
stroke(234,98,71);strokeWeight(10); fill(0); ellipse(200,200,ellipseSize,ellipseSize);
mouse > && mouse < && mouse > && mouse <
{
ellipseSize = ellipseSize + 1;}
else
ellipseSize = ellipseSize - 1;
}
if (ellipseSize < 1)
ellipseSize = 1;}
if (ellipseSize > 400)
ellipseSize = 400;}
}
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 24/31
Read commentsRead comments
Run pieces of codeRun pieces of code
Go screaming to your TA Go screaming to your TA
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 25/31
rr
From the central heartbeat of the centralFrom the central heartbeat of the centralprocessor, to the obsessive timestamping of filesprocessor, to the obsessive timestamping of filesan og entries, to ever present c oc isp ays,an og entries, to ever present c oc isp ays,
time is a fundamental feature of computation.time is a fundamental feature of computation.-- way. It is OK to consider large temporal scalesway. It is OK to consider large temporal scales
e. . seasons but smaller tem oral scalese. . seasons but smaller tem oral scalesshould also be displayed (or be available to beshould also be displayed (or be available to bedisplayed, perhaps as a function of user input).displayed, perhaps as a function of user input).
ou may ma e use o mouse npu you w s .ou may ma e use o mouse npu you w s .
8/14/2019 lcc6310_lab02
http://slidepdf.com/reader/full/lcc6310lab02 30/31
r ur u
1.1. Create your designCreate your design..
3.3. Code each componentCode each component4.4. Fit t e components toget er as you goFit t e components toget er as you go
5.5.
Modify your idea if it becomes tooModify your idea if it becomes toodifficultdifficult
6.6. Consult our friendl nei hborhood TA Consult our friendl nei hborhood TA