30 QuestionsΒΆ
How many bits are in a byte?
What is the purpose of a ; in a Processing program?
What, exactly, are the coordinates of the lower-left most pixel on a Processing screen that is 300 pixels wide and 200 pixels high?
What is the difference between Processings
quadfunction and itsrectfunction?What is the RGB triple for the color (pure) blue that is 50% transparent?
What does
map(8, 0, 100, 0, 1)evaluate to?What is the name of the type of an image variable in Processing?
What is the name of the Processing function you would use to convert an image to, for instance, black and white?
In the following code fragment, make a list of all the literals, and then make a list of all the variables.
int a = 5; int b = 7; int temp = a; a = b; b = temp; println(a); // prints 7 println(b); // prints 5
Suppose that
nis a Processing variable of typeint. Write four different statements that add 1 ton.Suppose that an animated ball uses
xandyto represent its center, anddxanddyto represent its velocity. Write an if- statement that makes the ball reverse its y direction when its center hits the bottom of the screen.Suppose
xandyare variables of typefloat. Write a logical expression that evaluates totruejust when bothxandyare between 5.0 and 10.0, andfalseotherwise. Your expression should returnfalseif eitherxoryis equal to either 5.0 or 10.0.Suppose
nis anint, andn + 1 < 0. What is the value ofn?What is the name of the function that you use to run some code when the user presses a key? What is the name of the that you use to run some code when the user clicks a mouse button?
What, exactly, does this print?
println("a\nb" + 3 + "2".length());
What does this code fragment print?
class Sprite { float x; float y; float dx; float dy; } void setup() { Sprite s; println(s.x + s.y + s.dx + s.dy) }
Write a
voidfunction that takes a name as input (as aString) and then prints “Hello <name>!” on the console window. Of course,<name>should be the name passed into the function. Don’t forget the ”!” at the end.Write a
booleanfunction calledinCircle(a, b, centerX, centerY, radius)that returnstrueif the point (a,b) is in the circle whose center is (centerX,centerY) and radius isradius.What are the conditions for the mouse to be dragged?
What does the function
translate(200, 150)do?What do
pushMatrix()andpopMatrix()do?In the following code, what is the super class and what is the subclass?
class Sprite { float x; float y; float dx; float dy; void update() { x += dx; y += dy; } } class Ball extends Sprite { float radius; color fillColor; }
Write a class called
Pointthat represents the (x,y) by storingxandyasfloats. Include a sensible default constructor, and a sensible copy constructor.Write a fragment of code that creates a new
ArrayListof strings that contains “apple”, “orange”, and “cherry”.Write a fragment of code that uses a while-loop to print the numbers 5000 down to 0 by 5s, e.g.:
5000 4995 4990 4985 ... 10 5 0
Suppose
particleshas just been created by this statement:ArrayList<Particle> particles;
Write a fragment of code that makes
particlesrefer to a newArrayList<Particle>of size 0.Suppose the function
rand(lo, hi)returns a randomintin the rangelotohi(inclusive). For example,rand(1, 3)returns either 1, 2, or 3 at random.Using
rand(lo, hi), write a new function calledrand(hi)that returns a random number in the range 0 tohi(inclusive).Suppose
tis a turtle graphics object, andt.forward(n)makes the turtle move forwardnpixels (drawing a line), andt.right(d)makes the turtle rotate to the right (i.e. clockwise)ddegrees in place (without drawing a line).Write a fragment of code using
tthat draws an equilateral triangle, i.e. a triangle whose sides are all the same length.What is a recursive function?
Re-write the following code using a while-loop:
int i = 5; while (i < 100) { println(i * i); i += 2; }