Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science I Fonts. Building on one jigsaw to make another.

Similar presentations


Presentation on theme: "Computer Science I Fonts. Building on one jigsaw to make another."— Presentation transcript:

1 Computer Science I Fonts. Building on one jigsaw to make another.
Classwork: Virtual Something

2 Check out Emmie’s comic in Course Announcements
A class is a blue print. Your code makes use of it Invoke the constructor to create the object Mainly initial setting of variables Invoke other methods for other behavior

3 Available Fonts Pfont.list is a class method that returns an array of all fonts available on the computer. A class method is independent of any specific object. In Java, we can create class methods using the modifier static.

4 Show fonts My sketch prints out the names of available fonts on the console and Displays text in specific, randomly selected font) after mouse click.

5 My sketch: showfonts String[] fontList ; PFont myfont; void setup() { size(800, 600); fill(255,0,0); fontList = PFont.list(); println(fontList); }

6 void draw() { } void mousePressed() { int ch = int(random(0,fontList
void draw() { } void mousePressed() { int ch = int(random(0,fontList.length)); myfont = createFont(fontList[ch],20); textFont(myfont); text(fontList[ch],mouseX,mouseY);

7 Fonts The command textFont(somefont); only works if somefont has been set using loadFont or createFont Extra credit opportunity for a good explanation of loadFont versus createFont Not just copy and paste from the document Include uses

8 Opportunity New photo from Aviva's trip to Cuba. Want to make new jigsaw Make vertical and horizontal cuts. Some other changes, including text on the screen. Close enough. You can click Restore or Mix up to try again. Build on other "linear jigsaw" Lesson (subtext, meta message): much work already done.

9 Overview of linear jigsaw
Classes: Button, Piece pieces is Array of Piece objects; buttons is Array of Button objects Global variables, all of which carry over Used for responsive design (adapt to screen size) Functions: setup, draw, mouseClicked, mousePressed, mouseDragged, mouseReleased makeButtons, drawButtons, makePieces, mixUpPieces, drawPieces

10 What needs to be changed or added?
The Piece class needs to add variable for y position, so now there is locy as well as locx. The constructor method Piece has one more parameter: Piece(int locxC,int locyC,int x,int y, int w, int h) Substantial changes to makePieces function Where else? Use Find for statements involving locx or getpx.

11 Nested for loops Standard pattern for creating something corresponding to rows and columns Need looping variable for each for loop: i and j Need additional variable because I put all the pieces in a 1 dimensional array: use alli.

12 void makePieces()//the Piece constructor will cut //out the piece { pieces = new Piece[NoP]; int pi = 0; // index for populating pieces for (int i=0;i<NHor;i++) for (int j=0;j<NVer;j++) { // initial positions is determined randomly int rx = round(random(.75*displayWidth)); int ry = round(random(.75*displayHeight)); pieces[pi] = new Piece(wedgeW*i,wedgeH*j,rx,ry,wedgeW,wedgeH); pieces[pi].display(); pi++; }

13 Note The Piece constructor method does the actual work of creating the piece content = createImage(pw,ph,RGB); content.copy(originalA,locxC,locyC,pw,ph, 0,0,pw,ph);

14 Aside The class code provides the template (blue print, specification) for objects What is the data to be associated with each object What are the behaviors: what is done with or to the object. One behavior is creating the object. This one is called the constructor and is used with the new operator. No object exists until it is constructed. See Emmie's announcement

15 For example, checking if puzzle done
From linear jigsaw: int perfectpx = firstx + i*wedgeW; int errorx = abs(perfectpx-pxi); int errory = abs(firsty-pyi);

16 2D jigsaw, in context for (int i=1;i<NoP;i++) { int pxi = pieces[i].getpx(); int pyi = pieces[i].getpy(); int perfectpx = firstx + pieces[i].getlocx(); int perfectpy = firsty + pieces[i].getlocy(); int errorx = abs(perfectpx-pxi); int errory = abs(perfectpy-pyi); if ((errorx>tolerance) || (errory>tolerance)) { oksofar = false; break; } }

17 Show the rest, to show text
if (oksofar) { text("Close enough. You can click Restore or Mix up to try again.",500,20); phase = 1; } "okay so far" coding This uses the default text font and size. Could be bigger. May be opportunity for sound!

18 Assignments Must use the naming convention jMeyerMyDog
Must zip (compress) the containing folder Not just the pde file, not just the data file Must have evocative names for variables and functions and classes Must have comments At start of code saying what it does Elsewhere indicating logic, assumptions What a function does. What the parameters represent. Where you may have wanted to do something more.

19 Classwork Use new techniques?
Complete and upload your virtual something.


Download ppt "Computer Science I Fonts. Building on one jigsaw to make another."

Similar presentations


Ads by Google