190 likes | 289 Views
Midterm Review. Midterm Exam: March 12 Monday during class hours Open book Access to computers Grades will be out within the same week. Simple Shapes. Point: point(x , y); Line: line(x1 , y1, x2, y2 ); Rectangle: rectMode (CORNER); //default mode rect (x , y, width, height);
E N D
Midterm Exam: March 12 Monday during class hours Open book Access to computers Grades will be out within the same week.
Simple Shapes Learning Processing: Slides by Don Smith
Point: point(x, y); • Line: line(x1, y1, x2, y2); • Rectangle: • rectMode(CORNER); //default mode • rect(x, y, width, height); • rectMode(CENTER); • rect(x, y, width, height); • rectMode(CORNERS); • rect(x1, y1, x2, y2);
Ellipse: • ellipseMode(CENTER); //default mode • ellipse(x, y, width, height); • ellipseMode(CORNER); • ellipse(x, y, width, height); • ellipseMode(CORNERS); • ellipse(x1, y1, x2, y2); • Circle is a special type of ellipse.
Color: Grayscale • You can set the color of lines and background: • 0 is black (no ‘light’) • 255 is white (most ‘light’) • Some examples in processing: • background(255); // Sets background to white • stroke(0); // Sets outline to black • fill(150); // Sets interior of a shape to grey • noStroke(); • noFill(); Learning Processing: Slides by Don Smith
RGB Color & Transparency • Each color has a value between 0 and 255 • colorMode(RGB,100); • colorMode(RGB,255,100,100) • Transparency • // 50% opacity • fill(255,0,0,127); • // 25% opacity • fill(255,0,0,63); • rect(0,150,200,40);
Tracking the Mouse mouseX: The current X coordinate of the mouse mouseY: The current Y coordinate of the mouse pmouseX: The previous X coordinate of the mouse pmouseY: The previous Y coordinate of the mouse strokeWeight(width)
Mouse clicks and Key presses mousePressed() //method keyPressed() //method mousePressed //system variable, boolean keyPressed//system variable, boolean
Use of Variables Global and local variables
frameRate() specifies the number of frames to be displayed every second. • The default rate is 60 frames per second. • random() returns a float. • Two arguments • random(1,100): a random float between [1,100) • One arguments • random(100): a random float between 0 (by default) and 100
System Variables • width: Width (in pixels) of sketch window • height: Height (in pixels) of sketch window • frameCount: Number of frames processed • frameRate: Rate (per sec.) that frames are processed • screen.height, screen.width: Entire screen • key: Most recent key pressed on keyboard (ASC-II) • keyCode: Numeric code for which key pressed • mousePressed: True or false (pressed or not?) • mouseButton: Which button (left, right, center)
if-else if (mouseX < width/3) { background(255); } else if (mouseX < 2*width/3) { background(127); } else { background(0); }
constrain() • constrain() takes three parameters • the value we intend to constrain • minimum limit • maximum limt • constrain(r,0,255); • Returns the “constrained” value
Logical Operator • And && • Or || • Not ! • Use a boolean variable as a button • Use a boolean variable as a switch
Loops while loops for loops Remember that draw() itself is a loop!
while loops • Plan the three parts: • What is the initial condition for the loop? • int y = 10; • When should the loop stop? • while (y < height){ • // loop • } • What is the loop operation? • rect(50,y,100,10); • y = y + 20;
for loops Start at 0 and count up to 9 for (inti = 0; i < 10; i = i + 1) Start at 0 and count up to 100 by 10 for (inti = 0; i < 101; i = i + 1) Start at 100 and count down to 0 by 5 for (inti = 100; i >= 0; i = i – 5)
Best way to study for the exam Go over the lecture slides Review the in-class exercises and homework I am here Monday through Thursday. Email me (ttian@kean.edu) if you have any question.