




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Processing in Java-modeLibraries, using other classes/librariesHTML parsing, intro to HTML parser
// any
code
here, no
methods
line(0,0,20,20);
// any
code
here, no
methods
line(0,0,20,20);
// methods!// global varsint a;// methodsvoid setup(){} void draw(){}
// any
code
here, no
methods
line(0,0,20,20);
// methods!// global varsint a;// methodsvoid setup(){} void draw(){}
// ...with classes// (all
of the above
and
then)
class Emotion
// fields// constructor// methods }
// any
code
here, no
methods
line(0,0,20,20);
// methods!// global varsint a;// methodsvoid setup(){} void draw(){}
// ...with classes// (all
of the above
and
then)
class Emotion
// fields// constructor// methods }
// ...and subclasses!// (all
of the above, and)
class Happy
extends
Emotion {
// new fields// constructor// methods }
// Java
mode!
class ThatsCrazyTalk
extends PApplet {
// setup()
and draw() as
normally...
// methods// classes
and subclasses
You can import classes that aren't normally imported into a Processing appImporting means making a classes available to your program - the JavaAPI docs tell you what package classes are in so you know what to import
Normally all Processing applets extend PApplet behind the scenesTake a look at any compiled Processing app
setup(), draw(), etc. are methods of the class extending PApplet
Look at an HTML file
So parsing means to walk through and interpret the tags
Results 1 - 20 of about 202 formatrix red … some text ==
some text
proHTML is a Processing library for HTML handling
http://www.texone.org/prohtml/…easy!
but poorly documented, and chokes on any malformed HTML…
Java contains HTML parsing capabilities in the swing package
We'll look at this one today
HTML Parser is another free parser that we'll look at later
http://htmlparser.sourceforge.net/
There are many others!
Switchboard is a web services library for Processing written by IDTgraduate Jeff Crouse
Micah will go over the usage of this in one of the tutorialshttp://www.realtimeart.com/switchboard/
ParserDelegator parses an HTML document passed in as a Reader andnotifies the passed-in ParserCallback object as to the state of the parsing
public void flush() throws BadLocationExceptionpublic void handleText(char[] data, int pos)public void handleComment(char[] data, int pos)public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos)public void handleEndTag(HTML.Tag t, int pos)public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)public void handleError(String errorMsg, int pos)public void handleEndOfLineString(String eol)
Handles anything that’s not a tag (the text between tags)data is an array of characters containing the textpos is the position in the file
Called for tags like IMGtag stores the name of the tagattrib stores any attributespos is the position in the file
The tag is imgThe attributes are src, alt, align, width (with their respective values)
Called for tags like BODYtag stores the name of the tagattrib stores any attributespos is the position in the file
The tag is bodyThe attributes are bgcolor, topmargin, leftmargin, marginheight,marginwidth (with their respective values)
Called for tags like tag stores the name of the tagpos is the position in the file
A try statement that catches the exception
try {
// some code that throws an exception } catch (Exception e) {
// what to do in case the exception happens }
A method that specifies that it can throw the exception
void myNastyMethod() throws Exception {
// some code that throws an exception }
javax.swing.text.html.parser.ParserDelegatorjavax.swing.text.html.HTMLEditorKit.ParserCallback
HTMLEditorKit.ParserCallback
callback
new
HTMLEditorKit.ParserCallback
override
the
handleText
method
public
void
handleText(char[]
data,
int
pos)
System.out.println(data); } };
try
BufferedReader reader =
new
BufferedReader(new
InputStreamReader(openStream("test.html"))); new
ParserDelegator().parse(reader,
callback,
true);
} catch
(IOException
e) {
e.printStackTrace(); }
URL url = new URL(href);InputStream instream = url.openStream();Reader reader = new BufferedReader(new InputStreamReader(instream));new ParserDelegator().parse(reader, callback, true);instream.close(); } catch (IOException e) {
e.printStackTrace();
Move our ParserCallback subclass into a separate Java class calledMyParserCallback.javaParse based on tags and attributes
Create a subclass of PImage that implements a mosaic(int blockSize) method. TheblockSize parameter specifies how big the mosaic block is (e.g. blockSize = 4 wouldmean the mosaic block size is 4 pixels by 4 pixels). The mosaic method shouldreplace each block of pixels in the image (e.g. if blockSize = 4, each block of 4 by 4pixels) with the average color value of the pixels in that block. Look at thePixelate->Mosaic filter in photoshop for an example of what this image operationdoes. Demonstrate your new class by drawing an image with several different blocksizes.
A3-02:
Write a small app that demonstrates kinetic text. Your app should allow the user totype something and move the text around in some way while they type. Forexample, the user might type text on a line, but slowly the words or letters startdrifting apart, or perhaps the line starts bending, or the words and letters flutter tothe bottom of the screen, etc. Of course you shouldn't exactly copy any of thetypographic examples in Processing or that you find on the web (though using suchexamples for inspiration, as a place to start modifying code, etc. is fine).
Two presenters (you know who you are!)Everyone else: prepare one discussion question for each reading
As We May Think - Vannevar Bush, NMR pp. 35-47Mythinformation - Langdon Winner, NMR pp. 587-