diff --git a/app/build.xml b/app/build.xml
new file mode 100644
index 000000000..eb1c313bf
--- /dev/null
+++ b/app/build.xml
@@ -0,0 +1,52 @@
+
+
- * Run 'java Main [-showtree] directory-full-of-java-files' - * - * [The -showtree option pops up a Swing frame that shows - * the AST constructed from the parser.] - * - * Run 'java Main- */ -class JavaRecognizer extends Parser; -options { - k = 2; // two token lookahead - exportVocab=Java; // Call its vocabulary "Java" - codeGenMakeSwitchThreshold = 2; // Some optimizations - codeGenBitsetTestThreshold = 3; - defaultErrorHandler = false; // Don't generate parser error handlers - buildAST = true; -} - -tokens { - BLOCK; MODIFIERS; OBJBLOCK; SLIST; CTOR_DEF; METHOD_DEF; VARIABLE_DEF; - INSTANCE_INIT; STATIC_INIT; TYPE; CLASS_DEF; INTERFACE_DEF; - PACKAGE_DEF; ARRAY_DECLARATOR; EXTENDS_CLAUSE; IMPLEMENTS_CLAUSE; - PARAMETERS; PARAMETER_DEF; LABELED_STAT; TYPECAST; INDEX_OP; - POST_INC; POST_DEC; METHOD_CALL; EXPR; ARRAY_INIT; - IMPORT; UNARY_MINUS; UNARY_PLUS; CASE_GROUP; ELIST; FOR_INIT; FOR_CONDITION; - FOR_ITERATOR; EMPTY_STAT; FINAL="final"; ABSTRACT="abstract"; - STRICTFP="strictfp"; SUPER_CTOR_CALL; CTOR_CALL; -} - -// Compilation Unit: In Java, this is a single file. This is the start -// rule for this parser -compilationUnit - : // A compilation unit starts with an optional package definition - ( packageDefinition - | /* nothing */ - ) - - // Next we have a series of zero or more import statements - ( importDefinition )* - - // Wrapping things up with any number of class or interface - // definitions - ( typeDefinition )* - - EOF! - ; - - -// Package statement: "package" followed by an identifier. -packageDefinition - options {defaultErrorHandler = true;} // let ANTLR handle errors - : p:"package"^ {#p.setType(PACKAGE_DEF);} identifier SEMI! - ; - - -// Import statement: import followed by a package or class name -importDefinition - options {defaultErrorHandler = true;} - : i:"import"^ {#i.setType(IMPORT);} identifierStar SEMI! - ; - -// A type definition in a file is either a class or interface definition. -typeDefinition - options {defaultErrorHandler = true;} - : m:modifiers! - ( classDefinition[#m] - | interfaceDefinition[#m] - ) - | SEMI! - ; - -/** A declaration is the creation of a reference or primitive-type variable - * Create a separate Type/Var tree for each var in the var list. - */ -declaration! - : m:modifiers t:typeSpec[false] v:variableDefinitions[#m,#t] - {#declaration = #v;} - ; - -// A type specification is a type name with possible brackets afterwards -// (which would make it an array type). -typeSpec[boolean addImagNode] - : classTypeSpec[addImagNode] - | builtInTypeSpec[addImagNode] - ; - -// A class type specification is a class type with possible brackets afterwards -// (which would make it an array type). -classTypeSpec[boolean addImagNode] - : identifier (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK!)* - { - if ( addImagNode ) { - #classTypeSpec = #(#[TYPE,"TYPE"], #classTypeSpec); - } - } - ; - -// A builtin type specification is a builtin type with possible brackets -// afterwards (which would make it an array type). -builtInTypeSpec[boolean addImagNode] - : builtInType (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK!)* - { - if ( addImagNode ) { - #builtInTypeSpec = #(#[TYPE,"TYPE"], #builtInTypeSpec); - } - } - ; - -// A type name. which is either a (possibly qualified) class name or -// a primitive (builtin) type -type - : identifier - | builtInType - ; - -// The primitive types. -builtInType - : "void" - | "boolean" - | "byte" - | "char" - | "short" - | "int" - | "float" - | "long" - | "double" - ; - -// A (possibly-qualified) java identifier. We start with the first IDENT -// and expand its name by adding dots and following IDENTS -identifier - : IDENT ( DOT^ IDENT )* - ; - -identifierStar - : IDENT - ( DOT^ IDENT )* - ( DOT^ STAR )? - ; - -// A list of zero or more modifiers. We could have used (modifier)* in -// place of a call to modifiers, but I thought it was a good idea to keep -// this rule separate so they can easily be collected in a Vector if -// someone so desires -modifiers - : ( modifier )* - {#modifiers = #([MODIFIERS, "MODIFIERS"], #modifiers);} - ; - -// modifiers for Java classes, interfaces, class/instance vars and methods -modifier - : "private" - | "public" - | "protected" - | "static" - | "transient" - | "final" - | "abstract" - | "native" - | "threadsafe" - | "synchronized" -// | "const" // reserved word, but not valid - | "volatile" - | "strictfp" - ; - -// Definition of a Java class -classDefinition![AST modifiers] - : "class" IDENT - // it _might_ have a superclass... - sc:superClassClause - // it might implement some interfaces... - ic:implementsClause - // now parse the body of the class - cb:classBlock - {#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"], - modifiers,IDENT,sc,ic,cb);} - ; - -superClassClause! - : ( "extends" id:identifier )? - {#superClassClause = #(#[EXTENDS_CLAUSE,"EXTENDS_CLAUSE"],id);} - ; - -// Definition of a Java Interface -interfaceDefinition![AST modifiers] - : "interface" IDENT - // it might extend some other interfaces - ie:interfaceExtends - // now parse the body of the interface (looks like a class...) - cb:classBlock - {#interfaceDefinition = #(#[INTERFACE_DEF,"INTERFACE_DEF"], - modifiers,IDENT,ie,cb);} - ; - - -// This is the body of a class. You can have fields and extra semicolons, -// That's about it (until you see what a field is...) -classBlock - : LCURLY! - ( field | SEMI! )* - RCURLY! - {#classBlock = #([OBJBLOCK, "OBJBLOCK"], #classBlock);} - ; - -// An interface can extend several other interfaces... -interfaceExtends - : ( - e:"extends"! - identifier ( COMMA! identifier )* - )? - {#interfaceExtends = #(#[EXTENDS_CLAUSE,"EXTENDS_CLAUSE"], - #interfaceExtends);} - ; - -// A class can implement several interfaces... -implementsClause - : ( - i:"implements"! identifier ( COMMA! identifier )* - )? - {#implementsClause = #(#[IMPLEMENTS_CLAUSE,"IMPLEMENTS_CLAUSE"], - #implementsClause);} - ; - -// Now the various things that can be defined inside a class or interface... -// Note that not all of these are really valid in an interface (constructors, -// for example), and if this grammar were used for a compiler there would -// need to be some semantic checks to make sure we're doing the right thing... -field! - : // method, constructor, or variable declaration - mods:modifiers - ( h:ctorHead s:constructorBody // constructor - {#field = #(#[CTOR_DEF,"CTOR_DEF"], mods, h, s);} - - | cd:classDefinition[#mods] // inner class - {#field = #cd;} - - | id:interfaceDefinition[#mods] // inner interface - {#field = #id;} - - | t:typeSpec[false] // method or variable declaration(s) - ( IDENT // the name of the method - - // parse the formal parameter declarations. - LPAREN! param:parameterDeclarationList RPAREN! - - rt:declaratorBrackets[#t] - - // get the list of exceptions that this method is - // declared to throw - (tc:throwsClause)? - - ( s2:compoundStatement | SEMI ) - {#field = #(#[METHOD_DEF,"METHOD_DEF"], - mods, - #(#[TYPE,"TYPE"],rt), - IDENT, - param, - tc, - s2);} - | v:variableDefinitions[#mods,#t] SEMI -// {#field = #(#[VARIABLE_DEF,"VARIABLE_DEF"], v);} - {#field = #v;} - ) - ) - - // "static { ... }" class initializer - | "static" s3:compoundStatement - {#field = #(#[STATIC_INIT,"STATIC_INIT"], s3);} - - // "{ ... }" instance initializer - | s4:compoundStatement - {#field = #(#[INSTANCE_INIT,"INSTANCE_INIT"], s4);} - ; - -constructorBody - : lc:LCURLY^ {#lc.setType(SLIST);} - ( options { greedy=true; } : explicitConstructorInvocation)? - (statement)* - RCURLY! - ; - -/** Catch obvious constructor calls, but not the expr.super(...) calls */ -explicitConstructorInvocation - : "this"! lp1:LPAREN^ argList RPAREN! SEMI! - {#lp1.setType(CTOR_CALL);} - | "super"! lp2:LPAREN^ argList RPAREN! SEMI! - {#lp2.setType(SUPER_CTOR_CALL);} - ; - -variableDefinitions[AST mods, AST t] - : variableDeclarator[getASTFactory().dupTree(mods), - getASTFactory().dupTree(t)] - ( COMMA! - variableDeclarator[getASTFactory().dupTree(mods), - getASTFactory().dupTree(t)] - )* - ; - -/** Declaration of a variable. This can be a class/instance variable, - * or a local variable in a method - * It can also include possible initialization. - */ -variableDeclarator![AST mods, AST t] - : id:IDENT d:declaratorBrackets[t] v:varInitializer - {#variableDeclarator = #(#[VARIABLE_DEF,"VARIABLE_DEF"], mods, #(#[TYPE,"TYPE"],d), id, v);} - ; - -declaratorBrackets[AST typ] - : {#declaratorBrackets=typ;} - (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK!)* - ; - -varInitializer - : ( ASSIGN^ initializer )? - ; - -// This is an initializer used to set up an array. -arrayInitializer - : lc:LCURLY^ {#lc.setType(ARRAY_INIT);} - ( initializer - ( - // CONFLICT: does a COMMA after an initializer start a new - // initializer or start the option ',' at end? - // ANTLR generates proper code by matching - // the comma as soon as possible. - options { - warnWhenFollowAmbig = false; - } - : - COMMA! initializer - )* - (COMMA!)? - )? - RCURLY! - ; - - -// The two "things" that can initialize an array element are an expression -// and another (nested) array initializer. -initializer - : expression - | arrayInitializer - ; - -// This is the header of a method. It includes the name and parameters -// for the method. -// This also watches for a list of exception classes in a "throws" clause. -ctorHead - : IDENT // the name of the method - - // parse the formal parameter declarations. - LPAREN! parameterDeclarationList RPAREN! - - // get the list of exceptions that this method is declared to throw - (throwsClause)? - ; - -// This is a list of exception classes that the method is declared to throw -throwsClause - : "throws"^ identifier ( COMMA! identifier )* - ; - - -// A list of formal parameters -parameterDeclarationList - : ( parameterDeclaration ( COMMA! parameterDeclaration )* )? - {#parameterDeclarationList = #(#[PARAMETERS,"PARAMETERS"], - #parameterDeclarationList);} - ; - -// A formal parameter. -parameterDeclaration! - : pm:parameterModifier t:typeSpec[false] id:IDENT - pd:declaratorBrackets[#t] - {#parameterDeclaration = #(#[PARAMETER_DEF,"PARAMETER_DEF"], - pm, #([TYPE,"TYPE"],pd), id);} - ; - -parameterModifier - : (f:"final")? - {#parameterModifier = #(#[MODIFIERS,"MODIFIERS"], f);} - ; - -// Compound statement. This is used in many contexts: -// Inside a class definition prefixed with "static": -// it is a class initializer -// Inside a class definition without "static": -// it is an instance initializer -// As the body of a method -// As a completely indepdent braced block of code inside a method -// it starts a new scope for variable definitions - -compoundStatement - : lc:LCURLY^ {#lc.setType(SLIST);} - // include the (possibly-empty) list of statements - (statement)* - RCURLY! - ; - - -statement - // A list of statements in curly braces -- start a new scope! - : compoundStatement - - // declarations are ambiguous with "ID DOT" relative to expression - // statements. Must backtrack to be sure. Could use a semantic - // predicate to test symbol table to see what the type was coming - // up, but that's pretty hard without a symbol table ;) - | (declaration)=> declaration SEMI! - - // An expression statement. This could be a method call, - // assignment statement, or any other expression evaluated for - // side-effects. - | expression SEMI! - - // class definition - | m:modifiers! classDefinition[#m] - - // Attach a label to the front of a statement - | IDENT c:COLON^ {#c.setType(LABELED_STAT);} statement - - // If-else statement - | "if"^ LPAREN! expression RPAREN! statement - ( - // CONFLICT: the old "dangling-else" problem... - // ANTLR generates proper code matching - // as soon as possible. Hush warning. - options { - warnWhenFollowAmbig = false; - } - : - "else"! statement - )? - - // For statement - | "for"^ - LPAREN! - forInit SEMI! // initializer - forCond SEMI! // condition test - forIter // updater - RPAREN! - statement // statement to loop over - - // While statement - | "while"^ LPAREN! expression RPAREN! statement - - // do-while statement - | "do"^ statement "while"! LPAREN! expression RPAREN! SEMI! - - // get out of a loop (or switch) - | "break"^ (IDENT)? SEMI! - - // do next iteration of a loop - | "continue"^ (IDENT)? SEMI! - - // Return an expression - | "return"^ (expression)? SEMI! - - // switch/case statement - | "switch"^ LPAREN! expression RPAREN! LCURLY! - ( casesGroup )* - RCURLY! - - // exception try-catch block - | tryBlock - - // throw an exception - | "throw"^ expression SEMI! - - // synchronize a statement - | "synchronized"^ LPAREN! expression RPAREN! compoundStatement - - // asserts (uncomment if you want 1.4 compatibility) - | "assert"^ expression ( COLON! expression )? SEMI! - - // empty statement - | s:SEMI {#s.setType(EMPTY_STAT);} - ; - -casesGroup - : ( // CONFLICT: to which case group do the statements bind? - // ANTLR generates proper code: it groups the - // many "case"/"default" labels together then - // follows them with the statements - options { - greedy = true; - } - : - aCase - )+ - caseSList - {#casesGroup = #([CASE_GROUP, "CASE_GROUP"], #casesGroup);} - ; - -aCase - : ("case"^ expression | "default") COLON! - ; - -caseSList - : (statement)* - {#caseSList = #(#[SLIST,"SLIST"],#caseSList);} - ; - -// The initializer for a for loop -forInit - // if it looks like a declaration, it is - : ( (declaration)=> declaration - // otherwise it could be an expression list... - | expressionList - )? - {#forInit = #(#[FOR_INIT,"FOR_INIT"],#forInit);} - ; - -forCond - : (expression)? - {#forCond = #(#[FOR_CONDITION,"FOR_CONDITION"],#forCond);} - ; - -forIter - : (expressionList)? - {#forIter = #(#[FOR_ITERATOR,"FOR_ITERATOR"],#forIter);} - ; - -// an exception handler try/catch block -tryBlock - : "try"^ compoundStatement - (handler)* - ( finallyClause )? - ; - -finallyClause - : "finally"^ compoundStatement - ; - -// an exception handler -handler - : "catch"^ LPAREN! parameterDeclaration RPAREN! compoundStatement - ; - - -// expressions -// Note that most of these expressions follow the pattern -// thisLevelExpression : -// nextHigherPrecedenceExpression -// (OPERATOR nextHigherPrecedenceExpression)* -// which is a standard recursive definition for a parsing an expression. -// The operators in java have the following precedences: -// lowest (13) = *= /= %= += -= <<= >>= >>>= &= ^= |= -// (12) ?: -// (11) || -// (10) && -// ( 9) | -// ( 8) ^ -// ( 7) & -// ( 6) == != -// ( 5) < <= > >= -// ( 4) << >> -// ( 3) +(binary) -(binary) -// ( 2) * / % -// ( 1) ++ -- +(unary) -(unary) ~ ! (type) -// [] () (method call) . (dot -- identifier qualification) -// new () (explicit parenthesis) -// -// the last two are not usually on a precedence chart; I put them in -// to point out that new has a higher precedence than '.', so you -// can validy use -// new Frame().show() -// -// Note that the above precedence levels map to the rules below... -// Once you have a precedence chart, writing the appropriate rules as below -// is usually very straightfoward - - - -// the mother of all expressions -expression - : assignmentExpression - {#expression = #(#[EXPR,"EXPR"],#expression);} - ; - - -// This is a list of expressions. -expressionList - : expression (COMMA! expression)* - {#expressionList = #(#[ELIST,"ELIST"], expressionList);} - ; - - -// assignment expression (level 13) -assignmentExpression - : conditionalExpression - ( ( ASSIGN^ - | PLUS_ASSIGN^ - | MINUS_ASSIGN^ - | STAR_ASSIGN^ - | DIV_ASSIGN^ - | MOD_ASSIGN^ - | SR_ASSIGN^ - | BSR_ASSIGN^ - | SL_ASSIGN^ - | BAND_ASSIGN^ - | BXOR_ASSIGN^ - | BOR_ASSIGN^ - ) - assignmentExpression - )? - ; - - -// conditional test (level 12) -conditionalExpression - : logicalOrExpression - ( QUESTION^ assignmentExpression COLON! conditionalExpression )? - ; - - -// logical or (||) (level 11) -logicalOrExpression - : logicalAndExpression (LOR^ logicalAndExpression)* - ; - - -// logical and (&&) (level 10) -logicalAndExpression - : inclusiveOrExpression (LAND^ inclusiveOrExpression)* - ; - - -// bitwise or non-short-circuiting or (|) (level 9) -inclusiveOrExpression - : exclusiveOrExpression (BOR^ exclusiveOrExpression)* - ; - - -// exclusive or (^) (level 8) -exclusiveOrExpression - : andExpression (BXOR^ andExpression)* - ; - - -// bitwise or non-short-circuiting and (&) (level 7) -andExpression - : equalityExpression (BAND^ equalityExpression)* - ; - - -// equality/inequality (==/!=) (level 6) -equalityExpression - : relationalExpression ((NOT_EQUAL^ | EQUAL^) relationalExpression)* - ; - - -// boolean relational expressions (level 5) -relationalExpression - : shiftExpression - ( ( ( LT^ - | GT^ - | LE^ - | GE^ - ) - shiftExpression - )* - | "instanceof"^ typeSpec[true] - ) - ; - - -// bit shift expressions (level 4) -shiftExpression - : additiveExpression ((SL^ | SR^ | BSR^) additiveExpression)* - ; - - -// binary addition/subtraction (level 3) -additiveExpression - : multiplicativeExpression ((PLUS^ | MINUS^) multiplicativeExpression)* - ; - - -// multiplication/division/modulo (level 2) -multiplicativeExpression - : unaryExpression ((STAR^ | DIV^ | MOD^ ) unaryExpression)* - ; - -unaryExpression - : INC^ unaryExpression - | DEC^ unaryExpression - | MINUS^ {#MINUS.setType(UNARY_MINUS);} unaryExpression - | PLUS^ {#PLUS.setType(UNARY_PLUS);} unaryExpression - | unaryExpressionNotPlusMinus - ; - -unaryExpressionNotPlusMinus - : BNOT^ unaryExpression - | LNOT^ unaryExpression - - | ( // subrule allows option to shut off warnings - options { - // "(int" ambig with postfixExpr due to lack of sequence - // info in linear approximate LL(k). It's ok. Shut up. - generateAmbigWarnings=false; - } - : // If typecast is built in type, must be numeric operand - // Also, no reason to backtrack if type keyword like int, float... - lpb:LPAREN^ {#lpb.setType(TYPECAST);} builtInTypeSpec[true] RPAREN! - unaryExpression - - // Have to backtrack to see if operator follows. If no operator - // follows, it's a typecast. No semantic checking needed to parse. - // if it _looks_ like a cast, it _is_ a cast; else it's a "(expr)" - | (LPAREN classTypeSpec[true] RPAREN unaryExpressionNotPlusMinus)=> - lp:LPAREN^ {#lp.setType(TYPECAST);} classTypeSpec[true] RPAREN! - unaryExpressionNotPlusMinus - - | postfixExpression - ) - ; - -// qualified names, array expressions, method invocation, post inc/dec -postfixExpression - : - /* - "this"! lp1:LPAREN^ argList RPAREN! - {#lp1.setType(CTOR_CALL);} - - | "super"! lp2:LPAREN^ argList RPAREN! - {#lp2.setType(SUPER_CTOR_CALL);} - | - */ - primaryExpression - - ( - /* - options { - // the use of postfixExpression in SUPER_CTOR_CALL adds DOT - // to the lookahead set, and gives loads of false non-det - // warnings. - // shut them off. - generateAmbigWarnings=false; - } - : */ - DOT^ IDENT - ( lp:LPAREN^ {#lp.setType(METHOD_CALL);} - argList - RPAREN! - )? - | DOT^ "this" - - | DOT^ "super" - ( // (new Outer()).super() (create enclosing instance) - lp3:LPAREN^ argList RPAREN! - {#lp3.setType(SUPER_CTOR_CALL);} - | DOT^ IDENT - ( lps:LPAREN^ {#lps.setType(METHOD_CALL);} - argList - RPAREN! - )? - ) - | DOT^ newExpression - | lb:LBRACK^ {#lb.setType(INDEX_OP);} expression RBRACK! - )* - - ( // possibly add on a post-increment or post-decrement. - // allows INC/DEC on too much, but semantics can check - in:INC^ {#in.setType(POST_INC);} - | de:DEC^ {#de.setType(POST_DEC);} - )? - ; - -// the basic element of an expression -primaryExpression - : identPrimary ( options {greedy=true;} : DOT^ "class" )? - | constant - | "true" - | "false" - | "null" - | newExpression - | "this" - | "super" - | LPAREN! assignmentExpression RPAREN! - // look for int.class and int[].class - | builtInType - ( lbt:LBRACK^ {#lbt.setType(ARRAY_DECLARATOR);} RBRACK! )* - DOT^ "class" - ; - -/** Match a, a.b.c refs, a.b.c(...) refs, a.b.c[], a.b.c[].class, - * and a.b.c.class refs. Also this(...) and super(...). Match - * this or super. - */ -identPrimary - : IDENT - ( - options { - // .ident could match here or in postfixExpression. - // We do want to match here. Turn off warning. - greedy=true; - } - : DOT^ IDENT - )* - ( - options { - // ARRAY_DECLARATOR here conflicts with INDEX_OP in - // postfixExpression on LBRACK RBRACK. - // We want to match [] here, so greedy. This overcomes - // limitation of linear approximate lookahead. - greedy=true; - } - : ( lp:LPAREN^ {#lp.setType(METHOD_CALL);} argList RPAREN! ) - | ( options {greedy=true;} : - lbc:LBRACK^ {#lbc.setType(ARRAY_DECLARATOR);} RBRACK! - )+ - )? - ; - -/** object instantiation. - * Trees are built as illustrated by the following input/tree pairs: - * - * new T() - * - * new - * | - * T -- ELIST - * | - * arg1 -- arg2 -- .. -- argn - * - * new int[] - * - * new - * | - * int -- ARRAY_DECLARATOR - * - * new int[] {1,2} - * - * new - * | - * int -- ARRAY_DECLARATOR -- ARRAY_INIT - * | - * EXPR -- EXPR - * | | - * 1 2 - * - * new int[3] - * new - * | - * int -- ARRAY_DECLARATOR - * | - * EXPR - * | - * 3 - * - * new int[1][2] - * - * new - * | - * int -- ARRAY_DECLARATOR - * | - * ARRAY_DECLARATOR -- EXPR - * | | - * EXPR 1 - * | - * 2 - * - */ -newExpression - : "new"^ type - ( LPAREN! argList RPAREN! (classBlock)? - - //java 1.1 - // Note: This will allow bad constructs like - // new int[4][][3] {exp,exp}. - // There needs to be a semantic check here... - // to make sure: - // a) [ expr ] and [ ] are not mixed - // b) [ expr ] and an init are not used together - - | newArrayDeclarator (arrayInitializer)? - ) - ; - -argList - : ( expressionList - | /*nothing*/ - {#argList = #[ELIST,"ELIST"];} - ) - ; - -newArrayDeclarator - : ( - // CONFLICT: - // newExpression is a primaryExpression which can be - // followed by an array index reference. This is ok, - // as the generated code will stay in this loop as - // long as it sees an LBRACK (proper behavior) - options { - warnWhenFollowAmbig = false; - } - : - lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} - (expression)? - RBRACK! - )+ - ; - -constant - : NUM_INT - | CHAR_LITERAL - | STRING_LITERAL - | NUM_FLOAT - | NUM_LONG - | NUM_DOUBLE - ; - - -//---------------------------------------------------------------------------- -// The Java scanner -//---------------------------------------------------------------------------- -class JavaLexer extends Lexer; - -options { - exportVocab=Java; // call the vocabulary "Java" - testLiterals=false; // don't automatically test for literals - k=4; // four characters of lookahead - charVocabulary='\u0003'..'\uFFFF'; - // without inlining some bitset tests, couldn't do unicode; - // I need to make ANTLR generate smaller bitsets; see - // bottom of JavaLexer.java - codeGenBitsetTestThreshold=20; -} - - - -// OPERATORS -QUESTION : '?' ; -LPAREN : '(' ; -RPAREN : ')' ; -LBRACK : '[' ; -RBRACK : ']' ; -LCURLY : '{' ; -RCURLY : '}' ; -COLON : ':' ; -COMMA : ',' ; -//DOT : '.' ; -ASSIGN : '=' ; -EQUAL : "==" ; -LNOT : '!' ; -BNOT : '~' ; -NOT_EQUAL : "!=" ; -DIV : '/' ; -DIV_ASSIGN : "/=" ; -PLUS : '+' ; -PLUS_ASSIGN : "+=" ; -INC : "++" ; -MINUS : '-' ; -MINUS_ASSIGN : "-=" ; -DEC : "--" ; -STAR : '*' ; -STAR_ASSIGN : "*=" ; -MOD : '%' ; -MOD_ASSIGN : "%=" ; -SR : ">>" ; -SR_ASSIGN : ">>=" ; -BSR : ">>>" ; -BSR_ASSIGN : ">>>=" ; -GE : ">=" ; -GT : ">" ; -SL : "<<" ; -SL_ASSIGN : "<<=" ; -LE : "<=" ; -LT : '<' ; -BXOR : '^' ; -BXOR_ASSIGN : "^=" ; -BOR : '|' ; -BOR_ASSIGN : "|=" ; -LOR : "||" ; -BAND : '&' ; -BAND_ASSIGN : "&=" ; -LAND : "&&" ; -SEMI : ';' ; - - -// Whitespace -- ignored -WS : ( ' ' - | '\t' - | '\f' - // handle newlines - | ( options {generateAmbigWarnings=false;} - : "\r\n" // Evil DOS - | '\r' // Macintosh - | '\n' // Unix (the right way) - ) - { newline(); } - )+ - { _ttype = Token.SKIP; } - ; - -// Single-line comments -SL_COMMENT - : "//" - (~('\n'|'\r'))* ('\n'|'\r'('\n')?) - {$setType(Token.SKIP); newline();} - ; - -// multiple-line comments -ML_COMMENT - : "/*" - ( /* '\r' '\n' can be matched in one alternative or by matching - '\r' in one iteration and '\n' in another. I am trying to - handle any flavor of newline that comes in, but the language - that allows both "\r\n" and "\r" and "\n" to all be valid - newline is ambiguous. Consequently, the resulting grammar - must be ambiguous. I'm shutting this warning off. - */ - options { - generateAmbigWarnings=false; - } - : - { LA(2)!='/' }? '*' - | '\r' '\n' {newline();} - | '\r' {newline();} - | '\n' {newline();} - | ~('*'|'\n'|'\r') - )* - "*/" - {$setType(Token.SKIP);} - ; - - -// character literals -CHAR_LITERAL - : '\'' ( ESC | ~'\'' ) '\'' - ; - -// string literals -STRING_LITERAL - : '"' (ESC|~('"'|'\\'))* '"' - ; - - -// escape sequence -- note that this is protected; it can only be called -// from another lexer rule -- it will not ever directly return a token to -// the parser -// There are various ambiguities hushed in this rule. The optional -// '0'...'9' digit matches should be matched here rather than letting -// them go back to STRING_LITERAL to be matched. ANTLR does the -// right thing by matching immediately; hence, it's ok to shut off -// the FOLLOW ambig warnings. -protected -ESC - : '\\' - ( 'n' - | 'r' - | 't' - | 'b' - | 'f' - | '"' - | '\'' - | '\\' - | ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT - | '0'..'3' - ( - options { - warnWhenFollowAmbig = false; - } - : '0'..'7' - ( - options { - warnWhenFollowAmbig = false; - } - : '0'..'7' - )? - )? - | '4'..'7' - ( - options { - warnWhenFollowAmbig = false; - } - : '0'..'7' - )? - ) - ; - - -// hexadecimal digit (again, note it's protected!) -protected -HEX_DIGIT - : ('0'..'9'|'A'..'F'|'a'..'f') - ; - - -// a dummy rule to force vocabulary to be all characters (except special -// ones that ANTLR uses internally (0 to 2) -protected -VOCAB - : '\3'..'\377' - ; - - -// an identifier. Note that testLiterals is set to true! This means -// that after we match the rule, we look in the literals table to see -// if it's a literal or really an identifer -IDENT - options {testLiterals=true;} - : ('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')* - ; - - -// a numeric literal -NUM_INT - {boolean isDecimal=false; Token t=null;} - : '.' {_ttype = DOT;} - ( ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})? - { - if (t != null && t.getText().toUpperCase().indexOf('F')>=0) { - _ttype = NUM_FLOAT; - } - else { - _ttype = NUM_DOUBLE; // assume double - } - } - )? - - | ( '0' {isDecimal = true;} // special case for just '0' - ( ('x'|'X') - ( // hex - // the 'e'|'E' and float suffix stuff look - // like hex digits, hence the (...)+ doesn't - // know when to stop: ambig. ANTLR resolves - // it correctly by matching immediately. It - // is therefor ok to hush warning. - options { - warnWhenFollowAmbig=false; - } - : HEX_DIGIT - )+ - | ('0'..'7')+ // octal - )? - | ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal - ) - ( ('l'|'L') { _ttype = NUM_LONG; } - - // only check to see if it's a float if looks like decimal so far - | {isDecimal}? - ( '.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})? - | EXPONENT (f3:FLOAT_SUFFIX {t=f3;})? - | f4:FLOAT_SUFFIX {t=f4;} - ) - { - if (t != null && t.getText().toUpperCase() .indexOf('F') >= 0) { - _ttype = NUM_FLOAT; - } - else { - _ttype = NUM_DOUBLE; // assume double - } - } - )? - ; - - -// a couple protected methods to assist in matching floating point numbers -protected -EXPONENT - : ('e'|'E') ('+'|'-')? ('0'..'9')+ - ; - - -protected -FLOAT_SUFFIX - : 'f'|'F'|'d'|'D' - ; - diff --git a/app/src/antlr/java/java.g.java15 b/app/src/antlr/java/java.g.java15 deleted file mode 100644 index b119cd35f..000000000 --- a/app/src/antlr/java/java.g.java15 +++ /dev/null @@ -1,2002 +0,0 @@ -header -{ -package de.hunsicker.jalopy.language.antlr; - -import de.hunsicker.jalopy.language.antlr.JavaNode; -import de.hunsicker.jalopy.language.JavaNodeHelper; -} - -/** Java 1.5 Recognizer - * - * Run 'java Main [-showtree] directory-full-of-java-files' - * - * [The -showtree option pops up a Swing frame that shows - * the JavaNode constructed from the parser.] - * - * Run 'java Main' - * - * Contributing authors: - * John Mitchell johnm@non.net - * Terence Parr parrt@magelang.com - * John Lilley jlilley@empathy.com - * Scott Stanchfield thetick@magelang.com - * Markus Mohnen mohnen@informatik.rwth-aachen.de - * Peter Williams pete.williams@sun.com - * Allan Jacobs Allan.Jacobs@eng.sun.com - * Steve Messick messick@redhills.com - * John Pybus john@pybus.org - * - * Version 1.00 December 9, 1997 -- initial release - * Version 1.01 December 10, 1997 - * fixed bug in octal def (0..7 not 0..8) - * Version 1.10 August 1998 (parrt) - * added tree construction - * fixed definition of WS,comments for mac,pc,unix newlines - * added unary plus - * Version 1.11 (Nov 20, 1998) - * Added "shutup" option to turn off last ambig warning. - * Fixed inner class def to allow named class defs as statements - * synchronized requires compound not simple statement - * add [] after builtInType DOT class in primaryExpression - * "const" is reserved but not valid..removed from modifiers - * Version 1.12 (Feb 2, 1999) - * Changed LITERAL_xxx to xxx in tree grammar. - * Updated java.g to use tokens {...} now for 2.6.0 (new feature). - * - * Version 1.13 (Apr 23, 1999) - * Didn't have (stat)? for else clause in tree parser. - * Didn't gen ASTs for interface extends. Updated tree parser too. - * Updated to 2.6.0. - * Version 1.14 (Jun 20, 1999) - * Allowed final/abstract on local classes. - * Removed local interfaces from methods - * Put instanceof precedence where it belongs...in relationalExpr - * It also had expr not type as arg; fixed it. - * Missing ! on SEMI in classBlock - * fixed: (expr) + "string" was parsed incorrectly (+ as unary plus). - * fixed: didn't like Object[].class in parser or tree parser - * Version 1.15 (Jun 26, 1999) - * Screwed up rule with instanceof in it. :( Fixed. - * Tree parser didn't like (expr).something; fixed. - * Allowed multiple inheritance in tree grammar. oops. - * Version 1.16 (August 22, 1999) - * Extending an interface built a wacky tree: had extra EXTENDS. - * Tree grammar didn't allow multiple superinterfaces. - * Tree grammar didn't allow empty var initializer: {} - * Version 1.17 (October 12, 1999) - * ESC lexer rule allowed 399 max not 377 max. - * java.tree.g didn't handle the expression of synchronized - * statements. - * Version 1.18 (August 12, 2001) - * Terence updated to Java 2 Version 1.3 by - * observing/combining work of Allan Jacobs and Steve - * Messick. Handles 1.3 src. Summary: - * o primary didn't include boolean.class kind of thing - * o constructor calls parsed explicitly now: - * see explicitConstructorInvocation - * o add strictfp modifier - * o missing objBlock after new expression in tree grammar - * o merged local class definition alternatives, moved after declaration - * o fixed problem with ClassName.super.field - * o reordered some alternatives to make things more efficient - * o long and double constants were not differentiated from int/float - * o whitespace rule was inefficient: matched only one char - * o add an examples directory with some nasty 1.3 cases - * o made Main.java use buffered IO and a Reader for Unicode support - * o supports UNICODE? - * Using Unicode charVocabulay makes code file big, but only - * in the bitsets at the end. I need to make ANTLR generate - * unicode bitsets more efficiently. - * Version 1.19 (April 25, 2002) - * Terence added in nice fixes by John Pybus concerning floating - * constants and problems with super() calls. John did a nice - * reorg of the primary/postfix expression stuff to read better - * and makes f.g.super() parse properly (it was METHOD_CALL not - * a SUPER_CTOR_CALL). Also: - * - * o "finally" clause was a root...made it a child of "try" - * o Added stuff for asserts too for Java 1.4, but *commented out* - * as it is not backward compatible. - * - * Version 1.20 (October 27, 2002) - * - * Terence ended up reorging John Pybus' stuff to - * remove some nondeterminisms and some syntactic predicates. - * Note that the grammar is stricter now; e.g., this(...) must - * be the first statement. - * - * Trinary ?: operator wasn't working as array name: - * (isBig ? bigDigits : digits)[i]; - * - * Checked parser/tree parser on source for - * Resin-2.0.5, jive-2.1.1, jdk 1.3.1, Lucene, antlr 2.7.2a4, - * and the 110k-line jGuru server source. - * - * This grammar is in the PUBLIC DOMAIN - *
+ * Differences between beginShape() and line() and point() methods. + *
+ * beginShape() is intended to be more flexible at the expense of being + * a little more complicated to use. it handles more complicated shapes + * that can consist of many connected lines (so you get joins) or lines + * mixed with curves. + *
+ * The line() and point() command are for the far more common cases + * (particularly for our audience) that simply need to draw a line + * or a point on the screen. + *
+ * From the code side of things, line() may or may not call beginShape() + * to do the drawing. In the beta code, they do, but in the alpha code, + * they did not. they might be implemented one way or the other depending + * on tradeoffs of runtime efficiency vs. implementation efficiency &mdash + * meaning the speed that things run at vs. the speed it takes me to write + * the code and maintain it. for beta, the latter is most important so + * that's how things are implemented. + */ public void beginShape(int kind) { if (recorder != null) recorder.beginShape(kind); g.beginShape(kind); } + /** + * Sets whether the upcoming vertex is part of an edge. + * Equivalent to glEdgeFlag(), for people familiar with OpenGL. + */ public void edge(boolean edge) { if (recorder != null) recorder.edge(edge); g.edge(edge); } + /** + * Sets the current normal vector. Only applies with 3D rendering + * and inside a beginShape/endShape block. + *
+ * This is for drawing three dimensional shapes and surfaces, + * allowing you to specify a vector perpendicular to the surface + * of the shape, which determines how lighting affects it. + * + * For the most part, PGraphics3D will attempt to automatically + * assign normals to shapes, but since that's imperfect, + * this is a better option when you want more control. + * + * For people familiar with OpenGL, this function is basically + * identical to glNormal3f(). + */ public void normal(float nx, float ny, float nz) { if (recorder != null) recorder.normal(nx, ny, nz); g.normal(nx, ny, nz); } + /** + * Set texture mode to either to use coordinates based on the IMAGE + * (more intuitive for new users) or NORMALIZED (better for advanced chaps) + */ public void textureMode(int mode) { if (recorder != null) recorder.textureMode(mode); g.textureMode(mode); } + /** + * Set texture image for current shape. + * Needs to be called between @see beginShape and @see endShape + * + * @param image reference to a PImage object + */ public void texture(PImage image) { if (recorder != null) recorder.texture(image); g.texture(image); @@ -7528,6 +7600,11 @@ public class PApplet extends Applet } + /** + * Used by renderer subclasses or PShape to efficiently pass in already + * formatted vertex information. + * @param v vertex parameters, as a float array of length VERTEX_FIELD_COUNT + */ public void vertex(float[] v) { if (recorder != null) recorder.vertex(v); g.vertex(v); @@ -7546,6 +7623,7 @@ public class PApplet extends Applet } + /** This feature is in testing, do not use or rely upon its implementation */ public void breakShape() { if (recorder != null) recorder.breakShape(); g.breakShape(); @@ -7598,6 +7676,26 @@ public class PApplet extends Applet } + /** + * Draws a point, a coordinate in space at the dimension of one pixel. + * The first parameter is the horizontal value for the point, the second + * value is the vertical value for the point, and the optional third value + * is the depth value. Drawing this shape in 3D using the z + * parameter requires the P3D or OPENGL parameter in combination with + * size as shown in the above example. + *+ * Implementation notes: + *
+ * cache all the points of the sphere in a static array + * top and bottom are just a bunch of triangles that land + * in the center point + *
+ * sphere is a series of concentric circles who radii vary + * along the shape, based on, er.. cos or something + *
+ * [toxi 031031] new sphere code. removed all multiplies with + * radius, as scale() will take care of that anyway + * + * [toxi 031223] updated sphere code (removed modulos) + * and introduced sphereAt(x,y,z,r) + * to avoid additional translate()'s on the user/sketch side + * + * [davbol 080801] now using separate sphereDetailU/V + *+ * + * @webref shape:3d_primitives + * @param r the radius of the sphere + */ public void sphere(float r) { if (recorder != null) recorder.sphere(r); g.sphere(r); } + /** + * Evalutes quadratic bezier at point t for points a, b, c, d. + * The parameter t varies between 0 and 1. The a and d parameters are the + * on-curve points, b and c are the control points. To make a two-dimensional + * curve, call this function once with the x coordinates and a second time + * with the y coordinates to get the location of a bezier curve at t. + * + * =advanced + * For instance, to convert the following example:
+ * stroke(255, 102, 0); + * line(85, 20, 10, 10); + * line(90, 90, 15, 80); + * stroke(0, 0, 0); + * bezier(85, 20, 10, 10, 90, 90, 15, 80); + * + * // draw it in gray, using 10 steps instead of the default 20 + * // this is a slower way to do it, but useful if you need + * // to do things with the coordinates at each step + * stroke(128); + * beginShape(LINE_STRIP); + * for (int i = 0; i <= 10; i++) { + * float t = i / 10.0f; + * float x = bezierPoint(85, 10, 90, 15, t); + * float y = bezierPoint(20, 10, 90, 80, t); + * vertex(x, y); + * } + * endShape();+ * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + */ public float bezierPoint(float a, float b, float c, float d, float t) { return g.bezierPoint(a, b, c, d, t); } + /** + * Calculates the tangent of a point on a Bezier curve. There is a good + * definition of "tangent" at Wikipedia: http://en.wikipedia.org/wiki/Tangent + * + * =advanced + * Code submitted by Dave Bollinger (davol) for release 0136. + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + */ public float bezierTangent(float a, float b, float c, float d, float t) { return g.bezierTangent(a, b, c, d, t); } + /** + * Sets the resolution at which Beziers display. The default value is 20. This function is only useful when using the P3D or OPENGL renderer as the default (JAVA2D) renderer does not use this information. + * + * @webref shape:curves + * @param detail resolution of the curves + * + * @see PApplet#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PApplet#curveVertex(float, float) + * @see PApplet#curveTightness(float) + */ public void bezierDetail(int detail) { if (recorder != null) recorder.bezierDetail(detail); g.bezierDetail(detail); } + /** + * Draws a Bezier curve on the screen. These curves are defined by a series + * of anchor and control points. The first two parameters specify the first + * anchor point and the last two parameters specify the other anchor point. + * The middle parameters specify the control points which define the shape + * of the curve. Bezier curves were developed by French engineer Pierre + * Bezier. Using the 3D version of requires rendering with P3D or OPENGL + * (see the Environment reference for more information). + * + * =advanced + * Draw a cubic bezier curve. The first and last points are + * the on-curve points. The middle two are the 'control' points, + * or 'handles' in an application like Illustrator. + *
+ * Identical to typing: + *
beginShape(); + * vertex(x1, y1); + * bezierVertex(x2, y2, x3, y3, x4, y4); + * endShape(); + *+ * In Postscript-speak, this would be: + *
moveto(x1, y1); + * curveto(x2, y2, x3, y3, x4, y4);+ * If you were to try and continue that curve like so: + *
curveto(x5, y5, x6, y6, x7, y7);+ * This would be done in processing by adding these statements: + *
bezierVertex(x5, y5, x6, y6, x7, y7) + *+ * To draw a quadratic (instead of cubic) curve, + * use the control point twice by doubling it: + *
bezier(x1, y1, cx, cy, cx, cy, x2, y2);+ * + * @webref shape:curves + * @param x1 coordinates for the first anchor point + * @param y1 coordinates for the first anchor point + * @param z1 coordinates for the first anchor point + * @param x2 coordinates for the first control point + * @param y2 coordinates for the first control point + * @param z2 coordinates for the first control point + * @param x3 coordinates for the second control point + * @param y3 coordinates for the second control point + * @param z3 coordinates for the second control point + * @param x4 coordinates for the second anchor point + * @param y4 coordinates for the second anchor point + * @param z4 coordinates for the second anchor point + * + * @see PGraphics#bezierVertex(float, float, float, float, float, float) + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + */ public void bezier(float x1, float y1, float x2, float y2, float x3, float y3, @@ -7726,28 +8139,137 @@ public class PApplet extends Applet } + /** + * Evalutes the Catmull-Rom curve at point t for points a, b, c, d. The + * parameter t varies between 0 and 1, a and d are points on the curve, + * and b and c are the control points. This can be done once with the x + * coordinates and a second time with the y coordinates to get the + * location of a curve at t. + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of second point on the curve + * @param c coordinate of third point on the curve + * @param d coordinate of fourth point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#bezierPoint(float, float, float, float, float) + */ public float curvePoint(float a, float b, float c, float d, float t) { return g.curvePoint(a, b, c, d, t); } + /** + * Calculates the tangent of a point on a Catmull-Rom curve. There is a good definition of "tangent" at Wikipedia: http://en.wikipedia.org/wiki/Tangent. + * + * =advanced + * Code thanks to Dave Bollinger (Bug #715) + * + * @webref shape:curves + * @param a coordinate of first point on the curve + * @param b coordinate of first control point + * @param c coordinate of second control point + * @param d coordinate of second point on the curve + * @param t value between 0 and 1 + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curvePoint(float, float, float, float, float) + * @see PGraphics#bezierTangent(float, float, float, float, float) + */ public float curveTangent(float a, float b, float c, float d, float t) { return g.curveTangent(a, b, c, d, t); } + /** + * Sets the resolution at which curves display. The default value is 20. + * This function is only useful when using the P3D or OPENGL renderer as + * the default (JAVA2D) renderer does not use this information. + * + * @webref shape:curves + * @param detail resolution of the curves + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curveTightness(float) + */ public void curveDetail(int detail) { if (recorder != null) recorder.curveDetail(detail); g.curveDetail(detail); } + /** + * Modifies the quality of forms created with curve() and + *curveVertex(). The parameter squishy determines how the + * curve fits to the vertex points. The value 0.0 is the default value for + * squishy (this value defines the curves to be Catmull-Rom splines) + * and the value 1.0 connects all the points with straight lines. + * Values within the range -5.0 and 5.0 will deform the curves but + * will leave them recognizable and as values increase in magnitude, + * they will continue to deform. + * + * @webref shape:curves + * @param tightness amount of deformation from the original vertices + * + * @see PGraphics#curve(float, float, float, float, float, float, float, float, float, float, float, float) + * @see PGraphics#curveVertex(float, float) + * + */ public void curveTightness(float tightness) { if (recorder != null) recorder.curveTightness(tightness); g.curveTightness(tightness); } + /** + * Draws a curved line on the screen. The first and second parameters + * specify the beginning control point and the last two parameters specify + * the ending control point. The middle parameters specify the start and + * stop of the curve. Longer curves can be created by putting a series of + * curve() functions together or using curveVertex(). + * An additional function called curveTightness() provides control + * for the visual quality of the curve. The curve() function is an + * implementation of Catmull-Rom splines. Using the 3D version of requires + * rendering with P3D or OPENGL (see the Environment reference for more + * information). + * + * =advanced + * As of revision 0070, this function no longer doubles the first + * and last points. The curves are a bit more boring, but it's more + * mathematically correct, and properly mirrored in curvePoint(). + *
+ * Identical to typing out:
+ * beginShape(); + * curveVertex(x1, y1); + * curveVertex(x2, y2); + * curveVertex(x3, y3); + * curveVertex(x4, y4); + * endShape(); + *+ * + * @webref shape:curves + * @param x1 coordinates for the beginning control point + * @param y1 coordinates for the beginning control point + * @param z1 coordinates for the beginning control point + * @param x2 coordinates for the first point + * @param y2 coordinates for the first point + * @param z2 coordinates for the first point + * @param x3 coordinates for the second point + * @param y3 coordinates for the second point + * @param z3 coordinates for the second point + * @param x4 coordinates for the ending control point + * @param y4 coordinates for the ending control point + * @param z4 coordinates for the ending control point + * + * @see PGraphics#curveVertex(float, float) + * @see PGraphics#curveTightness(float) + * @see PGraphics#bezier(float, float, float, float, float, float, float, float, float, float, float, float) + */ public void curve(float x1, float y1, float x2, float y2, float x3, float y3, @@ -7766,18 +8288,46 @@ public class PApplet extends Applet } + /** + * If true in PImage, use bilinear interpolation for copy() + * operations. When inherited by PGraphics, also controls shapes. + */ public void smooth() { if (recorder != null) recorder.smooth(); g.smooth(); } + /** + * Disable smoothing. See smooth(). + */ public void noSmooth() { if (recorder != null) recorder.noSmooth(); g.noSmooth(); } + /** + * Modifies the location from which images draw. The default mode is + * imageMode(CORNER), which specifies the location to be the + * upper-left corner and uses the fourth and fifth parameters of + * image() to set the image's width and height. The syntax + * imageMode(CORNERS) uses the second and third parameters of + * image() to set the location of one corner of the image and + * uses the fourth and fifth parameters to set the opposite corner. + * Use imageMode(CENTER) to draw images centered at the given + * x and y position. + *
+ * Given an (x, y, z) coordinate, returns the x position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenX(float x, float y, float z) { return g.screenX(x, y, z); } + /** + * Maps a three dimensional point to its placement on-screen. + *
+ * Given an (x, y, z) coordinate, returns the y position of where + * that point would be placed on screen, once affected by translate(), + * scale(), or any other transformations. + */ public float screenY(float x, float y, float z) { return g.screenY(x, y, z); } + /** + * Maps a three dimensional point to its placement on-screen. + *
+ * Given an (x, y, z) coordinate, returns its z value. + * This value can be used to determine if an (x, y, z) coordinate + * is in front or in back of another (x, y, z) coordinate. + * The units are based on how the zbuffer is set up, and don't + * relate to anything "real". They're only useful for in + * comparison to another value obtained from screenZ(), + * or directly out of the zbuffer[]. + */ public float screenZ(float x, float y, float z) { return g.screenZ(x, y, z); } + /** + * Returns the model space x value for an x, y, z coordinate. + *
+ * This will give you a coordinate after it has been transformed
+ * by translate(), rotate(), and camera(), but not yet transformed
+ * by the projection matrix. For instance, his can be useful for
+ * figuring out how points in 3D space relate to the edge
+ * coordinates of a shape.
+ */
public float modelX(float x, float y, float z) {
return g.modelX(x, y, z);
}
+ /**
+ * Returns the model space y value for an x, y, z coordinate.
+ */
public float modelY(float x, float y, float z) {
return g.modelY(x, y, z);
}
+ /**
+ * Returns the model space z value for an x, y, z coordinate.
+ */
public float modelZ(float x, float y, float z) {
return g.modelZ(x, y, z);
}
@@ -8279,12 +9145,26 @@ public class PApplet extends Applet
}
+ /**
+ * Disables drawing the stroke (outline). If both noStroke() and
+ * noFill() are called, no shapes will be drawn to the screen.
+ *
+ * @webref color:setting
+ *
+ * @see PGraphics#stroke(float, float, float, float)
+ */
public void noStroke() {
if (recorder != null) recorder.noStroke();
g.noStroke();
}
+ /**
+ * Set the tint to either a grayscale or ARGB value.
+ * See notes attached to the fill() function.
+ * @param rgb color value in hexadecimal notation
+ * (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype
+ */
public void stroke(int rgb) {
if (recorder != null) recorder.stroke(rgb);
g.stroke(rgb);
@@ -8297,6 +9177,10 @@ public class PApplet extends Applet
}
+ /**
+ *
+ * @param gray specifies a value between white and black
+ */
public void stroke(float gray) {
if (recorder != null) recorder.stroke(gray);
g.stroke(gray);
@@ -8315,30 +9199,70 @@ public class PApplet extends Applet
}
+ /**
+ * Sets the color used to draw lines and borders around shapes. This color
+ * is either specified in terms of the RGB or HSB color depending on the
+ * current colorMode() (the default color space is RGB, with each
+ * value in the range from 0 to 255).
+ *
When using hexadecimal notation to specify a color, use "#" or
+ * "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six
+ * digits to specify a color (the way colors are specified in HTML and CSS).
+ * When using the hexadecimal notation starting with "0x", the hexadecimal
+ * value must be specified with eight characters; the first two characters
+ * define the alpha component and the remainder the red, green, and blue
+ * components.
+ *
The value for the parameter "gray" must be less than or equal
+ * to the current maximum value as specified by colorMode().
+ * The default maximum value is 255.
+ *
+ * @webref color:setting
+ * @param alpha opacity of the stroke
+ * @param x red or hue value (depending on the current color mode)
+ * @param y green or saturation value (depending on the current color mode)
+ * @param z blue or brightness value (depending on the current color mode)
+ */
public void stroke(float x, float y, float z, float a) {
if (recorder != null) recorder.stroke(x, y, z, a);
g.stroke(x, y, z, a);
}
+ /**
+ * Removes the current fill value for displaying images and reverts to displaying images with their original hues.
+ *
+ * @webref image:loading_displaying
+ * @see processing.core.PGraphics#tint(float, float, float, float)
+ * @see processing.core.PGraphics#image(PImage, float, float, float, float)
+ */
public void noTint() {
if (recorder != null) recorder.noTint();
g.noTint();
}
+ /**
+ * Set the tint to either a grayscale or ARGB value.
+ */
public void tint(int rgb) {
if (recorder != null) recorder.tint(rgb);
g.tint(rgb);
}
+ /**
+ * @param rgb color value in hexadecimal notation
+ * (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype
+ * @param alpha opacity of the image
+ */
public void tint(int rgb, float alpha) {
if (recorder != null) recorder.tint(rgb, alpha);
g.tint(rgb, alpha);
}
+ /**
+ * @param gray any valid number
+ */
public void tint(float gray) {
if (recorder != null) recorder.tint(gray);
g.tint(gray);
@@ -8357,18 +9281,60 @@ public class PApplet extends Applet
}
+ /**
+ * Sets the fill value for displaying images. Images can be tinted to
+ * specified colors or made transparent by setting the alpha.
+ *
To make an image transparent, but not change it's color,
+ * use white as the tint color and specify an alpha value. For instance,
+ * tint(255, 128) will make an image 50% transparent (unless
+ * colorMode() has been used).
+ *
+ *
When using hexadecimal notation to specify a color, use "#" or
+ * "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six
+ * digits to specify a color (the way colors are specified in HTML and CSS).
+ * When using the hexadecimal notation starting with "0x", the hexadecimal
+ * value must be specified with eight characters; the first two characters
+ * define the alpha component and the remainder the red, green, and blue
+ * components.
+ *
The value for the parameter "gray" must be less than or equal
+ * to the current maximum value as specified by colorMode().
+ * The default maximum value is 255.
+ *
The tint() method is also used to control the coloring of
+ * textures in 3D.
+ *
+ * @webref image:loading_displaying
+ * @param x red or hue value
+ * @param y green or saturation value
+ * @param z blue or brightness value
+ *
+ * @see processing.core.PGraphics#noTint()
+ * @see processing.core.PGraphics#image(PImage, float, float, float, float)
+ */
public void tint(float x, float y, float z, float a) {
if (recorder != null) recorder.tint(x, y, z, a);
g.tint(x, y, z, a);
}
+ /**
+ * Disables filling geometry. If both noStroke() and noFill()
+ * are called, no shapes will be drawn to the screen.
+ *
+ * @webref color:setting
+ *
+ * @see PGraphics#fill(float, float, float, float)
+ *
+ */
public void noFill() {
if (recorder != null) recorder.noFill();
g.noFill();
}
+ /**
+ * Set the fill to either a grayscale value or an ARGB int.
+ * @param rgb color value in hexadecimal notation (i.e. #FFCC00 or 0xFFFFCC00) or any value of the color datatype
+ */
public void fill(int rgb) {
if (recorder != null) recorder.fill(rgb);
g.fill(rgb);
@@ -8381,6 +9347,9 @@ public class PApplet extends Applet
}
+ /**
+ * @param gray number specifying value between white and black
+ */
public void fill(float gray) {
if (recorder != null) recorder.fill(gray);
g.fill(gray);
@@ -8399,6 +9368,24 @@ public class PApplet extends Applet
}
+ /**
+ * Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color depending on the current colorMode() (the default color space is RGB, with each value in the range from 0 to 255).
+ *
When using hexadecimal notation to specify a color, use "#" or "0x" before the values (e.g. #CCFFAA, 0xFFCCFFAA). The # syntax uses six digits to specify a color (the way colors are specified in HTML and CSS). When using the hexadecimal notation starting with "0x", the hexadecimal value must be specified with eight characters; the first two characters define the alpha component and the remainder the red, green, and blue components.
+ *
The value for the parameter "gray" must be less than or equal to the current maximum value as specified by colorMode(). The default maximum value is 255.
+ *
To change the color of an image (or a texture), use tint().
+ *
+ * @webref color:setting
+ * @param x red or hue value
+ * @param y green or saturation value
+ * @param z blue or brightness value
+ * @param alpha opacity of the fill
+ *
+ * @see PGraphics#noFill()
+ * @see PGraphics#stroke(float)
+ * @see PGraphics#tint(float)
+ * @see PGraphics#background(float, float, float, float)
+ * @see PGraphics#colorMode(int, float, float, float, float)
+ */
public void fill(float x, float y, float z, float a) {
if (recorder != null) recorder.fill(x, y, z, a);
g.fill(x, y, z, a);
@@ -8525,48 +9512,119 @@ public class PApplet extends Applet
}
+ /**
+ * Set the background to a gray or ARGB color.
+ *
+ * For the main drawing surface, the alpha value will be ignored. However, + * alpha can be used on PGraphics objects from createGraphics(). This is + * the only way to set all the pixels partially transparent, for instance. + *
+ * Note that background() should be called before any transformations occur,
+ * because some implementations may require the current transformation matrix
+ * to be identity before drawing.
+ *
+ * @param rgb color value in hexadecimal notation (i.e. #FFCC00 or 0xFFFFCC00)
or any value of the color datatype
+ */
public void background(int rgb) {
if (recorder != null) recorder.background(rgb);
g.background(rgb);
}
+ /**
+ * See notes about alpha in background(x, y, z, a).
+ */
public void background(int rgb, float alpha) {
if (recorder != null) recorder.background(rgb, alpha);
g.background(rgb, alpha);
}
+ /**
+ * Set the background to a grayscale value, based on the
+ * current colorMode.
+ */
public void background(float gray) {
if (recorder != null) recorder.background(gray);
g.background(gray);
}
+ /**
+ * See notes about alpha in background(x, y, z, a).
+ * @param gray specifies a value between white and black
+ * @param alpha opacity of the background
+ */
public void background(float gray, float alpha) {
if (recorder != null) recorder.background(gray, alpha);
g.background(gray, alpha);
}
+ /**
+ * Set the background to an r, g, b or h, s, b value,
+ * based on the current colorMode.
+ */
public void background(float x, float y, float z) {
if (recorder != null) recorder.background(x, y, z);
g.background(x, y, z);
}
+ /**
+ * The background() function sets the color used for the background of the Processing window. The default background is light gray. In the draw() function, the background color is used to clear the display window at the beginning of each frame.
+ *
An image can also be used as the background for a sketch, however its width and height must be the same size as the sketch window. To resize an image 'b' to the size of the sketch window, use b.resize(width, height).
+ *
Images used as background will ignore the current tint() setting.
+ *
It is not possible to use transparency (alpha) in background colors with the main drawing surface, however they will work properly with createGraphics.
+ *
+ * =advanced
+ *
Clear the background with a color that includes an alpha value. This can + * only be used with objects created by createGraphics(), because the main + * drawing surface cannot be set transparent.
+ *It might be tempting to use this function to partially clear the screen + * on each frame, however that's not how this function works. When calling + * background(), the pixels will be replaced with pixels that have that level + * of transparency. To do a semi-transparent overlay, use fill() with alpha + * and draw a rectangle.
+ * + * @webref color:setting + * @param x red or hue value (depending on the current color mode) + * @param y green or saturation value (depending on the current color mode) + * @param z blue or brightness value (depending on the current color mode) + * + * @see PGraphics#stroke(float) + * @see PGraphics#fill(float) + * @see PGraphics#tint(float) + * @see PGraphics#colorMode(int) + */ public void background(float x, float y, float z, float a) { if (recorder != null) recorder.background(x, y, z, a); g.background(x, y, z, a); } + /** + * Takes an RGB or ARGB image and sets it as the background. + * The width and height of the image must be the same size as the sketch. + * Use image.resize(width, height) to make short work of such a task. + *+ * Note that even if the image is set as RGB, the high 8 bits of each pixel + * should be set opaque (0xFF000000), because the image data will be copied + * directly to the screen, and non-opaque background images may have strange + * behavior. Using image.filter(OPAQUE) will handle this easily. + *
+ * When using 3D, this will also clear the zbuffer (if it exists). + */ public void background(PImage image) { if (recorder != null) recorder.background(image); g.background(image); } + /** + * @param mode Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness + * @param max range for all color elements + */ public void colorMode(int mode) { if (recorder != null) recorder.colorMode(mode); g.colorMode(mode); @@ -8579,12 +9637,34 @@ public class PApplet extends Applet } + /** + * Set the colorMode and the maximum values for (r, g, b) + * or (h, s, b). + *
+ * Note that this doesn't set the maximum for the alpha value, + * which might be confusing if for instance you switched to + *
colorMode(HSB, 360, 100, 100);+ * because the alpha values were still between 0 and 255. + */ public void colorMode(int mode, float maxX, float maxY, float maxZ) { if (recorder != null) recorder.colorMode(mode, maxX, maxY, maxZ); g.colorMode(mode, maxX, maxY, maxZ); } + /** + * Changes the way Processing interprets color data. By default, the parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using the RGB color model. The colorMode() function is used to change the numerical range used for specifying colors and to switch color systems. For example, calling colorMode(RGB, 1.0) will specify that values are specified between 0 and 1. The limits for defining colors are altered by setting the parameters range1, range2, range3, and range 4. + * + * @webref color:setting + * @param maxX range for the red or hue depending on the current color mode + * @param maxY range for the green or saturation depending on the current color mode + * @param maxZ range for the blue or brightness depending on the current color mode + * @param maxA range for the alpha + * + * @see PGraphics#background(float) + * @see PGraphics#fill(float) + * @see PGraphics#stroke(float) + */ public void colorMode(int mode, float maxX, float maxY, float maxZ, float maxA) { if (recorder != null) recorder.colorMode(mode, maxX, maxY, maxZ, maxA); @@ -8592,106 +9672,310 @@ public class PApplet extends Applet } + /** + * Extracts the alpha value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + */ public final float alpha(int what) { return g.alpha(what); } + /** + * Extracts the red value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.
float r1 = red(myColor);+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + * @ref rightshift + */ public final float red(int what) { return g.red(what); } + /** + * Extracts the green value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.
float r2 = myColor >> 16 & 0xFF;
float r1 = green(myColor);+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + * @ref rightshift + */ public final float green(int what) { return g.green(what); } + /** + * Extracts the blue value from a color, scaled to match current colorMode(). This value is always returned as a float so be careful not to assign it to an int value.
float r2 = myColor >> 8 & 0xFF;
float r1 = blue(myColor);+ * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + */ public final float blue(int what) { return g.blue(what); } + /** + * Extracts the hue value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#saturation(int) + * @see PGraphics#brightness(int) + */ public final float hue(int what) { return g.hue(what); } + /** + * Extracts the saturation value from a color. + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#brightness(int) + */ public final float saturation(int what) { return g.saturation(what); } + /** + * Extracts the brightness value from a color. + * + * + * @webref color:creating_reading + * @param what any value of the color datatype + * + * @see PGraphics#red(int) + * @see PGraphics#green(int) + * @see PGraphics#blue(int) + * @see PGraphics#hue(int) + * @see PGraphics#saturation(int) + */ public final float brightness(int what) { return g.brightness(what); } + /** + * Calculates a color or colors between two color at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. + * + * @webref color:creating_reading + * @param c1 interpolate from this color + * @param c2 interpolate to this color + * @param amt between 0.0 and 1.0 + * + * @see PGraphics#blendColor(int, int, int) + * @see PGraphics#color(float, float, float, float) + */ public int lerpColor(int c1, int c2, float amt) { return g.lerpColor(c1, c2, amt); } + /** + * Interpolate between two colors. Like lerp(), but for the + * individual color components of a color supplied as an int value. + */ static public int lerpColor(int c1, int c2, float amt, int mode) { return PGraphics.lerpColor(c1, c2, amt, mode); } + /** + * Return true if this renderer should be drawn to the screen. Defaults to + * returning true, since nearly all renderers are on-screen beasts. But can + * be overridden for subclasses like PDF so that a window doesn't open up. + *
float r2 = myColor & 0xFF;
+ * If the image is in RGB format (i.e. on a PVideo object), + * the value will get its high bits set, just to avoid cases where + * they haven't been set already. + *
+ * If the image is in ALPHA format, this returns a white with its + * alpha value set. + *
+ * This function is included primarily for beginners. It is quite
+ * slow because it has to check to see if the x, y that was provided
+ * is inside the bounds, and then has to check to see what image
+ * type it is. If you want things to be more efficient, access the
+ * pixels[] array directly.
+ */
public int get(int x, int y) {
return g.get(x, y);
}
+ /**
+ * Reads the color of any pixel or grabs a group of pixels. If no parameters are specified, the entire image is returned. Get the value of one pixel by specifying an x,y coordinate. Get a section of the display window by specifing an additional width and height parameter. If the pixel requested is outside of the image window, black is returned. The numbers returned are scaled according to the current color ranges, but only RGB values are returned by this function. Even though you may have drawn a shape with colorMode(HSB), the numbers returned will be in RGB.
+ *
Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to "get(x, y)" using pixels[] is "pixels[y*width+x]". Processing requires calling loadPixels() to load the display window data into the pixels[] array before getting the values.
+ *
As of release 0149, this function ignores imageMode().
+ *
+ * @webref
+ * @brief Reads the color of any pixel or grabs a rectangle of pixels
+ * @param x x-coordinate of the pixel
+ * @param y y-coordinate of the pixel
+ * @param w width of pixel rectangle to get
+ * @param h height of pixel rectangle to get
+ *
+ * @see processing.core.PImage#set(int, int, int)
+ * @see processing.core.PImage#pixels
+ * @see processing.core.PImage#copy(PImage, int, int, int, int, int, int, int, int)
+ */
public PImage get(int x, int y, int w, int h) {
return g.get(x, y, w, h);
}
+ /**
+ * Returns a copy of this PImage. Equivalent to get(0, 0, width, height).
+ */
public PImage get() {
return g.get();
}
+ /**
+ * Changes the color of any pixel or writes an image directly into the display window. The x and y parameters specify the pixel to change and the color parameter specifies the color value. The color parameter is affected by the current color mode (the default is RGB values from 0 to 255). When setting an image, the x and y parameters define the coordinates for the upper-left corner of the image.
+ *
Setting the color of a single pixel with set(x, y) is easy, but not as fast as putting the data directly into pixels[]. The equivalent statement to "set(x, y, #000000)" using pixels[] is "pixels[y*width+x] = #000000". You must call loadPixels() to load the display window data into the pixels[] array before setting the values and calling updatePixels() to update the window with any changes.
+ *
As of release 1.0, this function ignores imageMode().
+ *
Due to what appears to be a bug in Apple's Java implementation, the point() and set() methods are extremely slow in some circumstances when used with the default renderer. Using P2D or P3D will fix the problem. Grouping many calls to point() or set() together can also help. (Bug 1094)
+ * =advanced
+ *
As of release 0149, this function ignores imageMode().
+ *
+ * @webref image:pixels
+ * @param x x-coordinate of the pixel
+ * @param y y-coordinate of the pixel
+ * @param c any value of the color datatype
+ */
public void set(int x, int y, int c) {
if (recorder != null) recorder.set(x, y, c);
g.set(x, y, c);
}
+ /**
+ * Efficient method of drawing an image's pixels directly to this surface.
+ * No variations are employed, meaning that any scale, tint, or imageMode
+ * settings will be ignored.
+ */
public void set(int x, int y, PImage src) {
if (recorder != null) recorder.set(x, y, src);
g.set(x, y, src);
}
+ /**
+ * Set alpha channel for an image. Black colors in the source
+ * image will make the destination image completely transparent,
+ * and white will make things fully opaque. Gray values will
+ * be in-between steps.
+ *
+ * Strictly speaking the "blue" value from the source image is
+ * used as the alpha color. For a fully grayscale image, this
+ * is correct, but for a color image it's not 100% accurate.
+ * For a more accurate conversion, first use filter(GRAY)
+ * which will make the image into a "correct" grayscale by
+ * performing a proper luminance-based conversion.
+ *
+ * @param maskArray any array of Integer numbers used as the alpha channel, needs to be same length as the image's pixel array
+ */
public void mask(int maskArray[]) {
if (recorder != null) recorder.mask(maskArray);
g.mask(maskArray);
}
+ /**
+ * Masks part of an image from displaying by loading another image and using it as an alpha channel.
+ * This mask image should only contain grayscale data, but only the blue color channel is used.
+ * The mask image needs to be the same size as the image to which it is applied.
+ * In addition to using a mask image, an integer array containing the alpha channel data can be specified directly.
+ * This method is useful for creating dynamically generated alpha masks.
+ * This array must be of the same length as the target image's pixels array and should contain only grayscale data of values between 0-255.
+ * @webref
+ * @brief Masks part of the image from displaying
+ * @param maskImg any PImage object used as the alpha channel for "img", needs to be same size as "img"
+ */
public void mask(PImage maskImg) {
if (recorder != null) recorder.mask(maskImg);
g.mask(maskImg);
@@ -8704,12 +9988,41 @@ public class PApplet extends Applet
}
+ /**
+ * Filters an image as defined by one of the following modes:
THRESHOLD - converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. The level must be between 0.0 (black) and 1.0(white). If no level is specified, 0.5 is used.
GRAY - converts any colors in the image to grayscale equivalents
INVERT - sets each pixel to its inverse value
POSTERIZE - limits each channel of the image to the number of colors specified as the level parameter
BLUR - executes a Guassian blur with the level parameter specifying the extent of the blurring. If no level parameter is used, the blur is equivalent to Guassian blur of radius 1.
OPAQUE - sets the alpha channel to entirely opaque.
ERODE - reduces the light areas with the amount defined by the level parameter.
DILATE - increases the light areas with the amount defined by the level parameter
+ * =advanced
+ * Method to apply a variety of basic filters to this image.
+ *
+ *
A useful reference for blending modes and their algorithms can be + * found in the SVG + * specification.
+ *It is important to note that Processing uses "fast" code, not + * necessarily "correct" code. No biggie, most software does. A nitpicker + * can find numerous "off by 1 division" problems in the blend code where + * >>8 or >>7 is used when strictly speaking + * /255.0 or /127.0 should have been used.
+ *For instance, exclusion (not intended for real-time use) reads + * r1 + r2 - ((2 * r1 * r2) / 255) because 255 == 1.0 + * not 256 == 1.0. In other words, (255*255)>>8 is not + * the same as (255*255)/255. But for real-time use the shifts + * are preferrable, and the difference is insignificant for applications + * built with Processing.
+ */ static public int blendColor(int c1, int c2, int mode) { return PGraphics.blendColor(c1, c2, mode); } + /** + * Blends one area of this image to another area. + * + * @see processing.core.PImage#blendColor(int,int,int) + */ public void blend(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode) { if (recorder != null) recorder.blend(sx, sy, sw, sh, dx, dy, dw, dh, mode); @@ -8737,6 +10138,42 @@ public class PApplet extends Applet } + /** + * Blends a region of pixels into the image specified by the img parameter. These copies utilize full alpha channel support and a choice of the following modes to blend the colors of source pixels (A) with the ones of pixels in the destination image (B):