Study Guides (238,406)
COMP 1005 (5)
Midterm

# Midterm notes

13 Pages
356 Views

School
Carleton University
Department
Computer Science
Course
COMP 1005
Professor
Jason Hinek
Semester
Winter

Description
January 17 2013 chapters 1,2,4,5,6. //comments /* comments size(x,y); //define size of the window background(R,G,B); colour textSize(int); fill(R,G,B); text(“text”,x,y); stroke(R,G,B); //outline colour noStroke(); //no outline strokeWeight(int); //thickness of outline ellipse(x,y,r,r); rect(x,y,w,h); colours can have 4 coordinates (R,G,B,A) Alpha value : opacity math : text(+-*/%) the / only give the quotient without the remainder % does a division and keeps the remainder if you let x=a number, you can use any value for x. so, int x; x=number; float means decimal number float xreal = number; dont do % in real numbers to print equation and answer : text(“x+18=”+(x+18),x,y); char c='x'; boolean can either be true or false boolean blue = true else ifs : fills in blue office hours. Thursday 2;30 3'30 random() gives a random number use width and height for rect spiral Variables: Everything has a type: • int (integers) • float (decimals) • boolean (true/false) • char (single character) other data types : • colors(RGB,RGBA,gray scale) • string (word, sentence) • Pimage (graphics) Casting: casting converts a data type into another Branching: if and if else and switch Operators: • == is equal to • != not equal to • < less than • > greater than • <= less or equal to • >= greater or equal to • && and • || or • ! not Starry night size(600,300); ellipse(300,150,590,290); strokeWeight(10); int a=300; int b=150; point(a,b); int x; while ((a<600||a>0)||(b<300||b>0)){ x=(int) random(5); if (x==1) { a+=10; //point(a,b-10); } else if (x==2) { a-=10; //point(a,b+10); } else if (x==3) { b+=10; //point(a+10,b); } else if (x==4) { b-=10; //point(a-10,b); } point(a,b); } January 24 2013 if statements if (sky is blue) print “Hurray!” if(sky is not blue) print”Booo” OR if(sky is blue) print”Hurray” else print”Boooo” th January 29 2013 type void= returns nothing setup () in brackets are the inputs February 12 2013 for(initialization, condition, increment) { for(initialization,condition,increment){ } } let's say we have an integer as an input, the output will be: true if (n=a^2+b^2) false (otherwise) in code: //initialization void setup() { size(600, 400); background(0); } boolean isSumOfSquares(int n) { for (int b=0;b<=n;b+=1) { for (int a=0;a<=n;a+=1) { if (n==(a*a)+(b*b)) { return true; } } } return false; } void mousePressed() { background(0); int num = mouseX + mouseY; if (isSumOfSquares(num)) { text("Yes"+num+"is the sum of squares", 100, 100); } else { text("No"+num+"is not the sum of squares", 100, 100); } } //main body void draw() { } Array: remember sets of numbers and variables for us intQ[]=new int [100]; February 28 2013 loadPixels(); [work with pixels] width*height updatePixels(); row*width+col -width -1 130 1 +width March 5 2013 Review What happens in a dynamic sketch ? There is a sequence of things that happens : 1. reads variable and function definitions. 2. Executes setup().At the bottom of draw, hidden to us, it updates the screen. 3. Executes draw(). Updates screen. 4. Goes back to 3 over and over. What happens when I want to click a button to make an interaction ? 1. Start → state of the program. (snapshot of
More Less

Related notes for COMP 1005

OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.