create a class based on 2D/3D
in
Programming Questions
•
1 year ago
I want something simulair to createGraphics, a method that handles the creation of a class.
If the processing sketch is in 3d then the 3d class should be returned, else the 2d class.
The following gives the error 'the function printMe() does not exist."
- Deformer def;
- void setup() {
- def = Deformer.createDeformer();
- def.printMe();
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer {
- static Deformer createDeformer() {
- if (g.is3D) {
- return new Deformer3D();
- }
- return new Deformer2D();
- }
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer2D extends Defomer {
- void printMe() {
- println("2d");
- }
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer3D extends Deformer {
- void printMe() {
- println("3d");
- }
- }
I also tried like this (same error):
- Deformer def;
- void setup() {
- def = DoekeLib.createDeformer();
- def.printMe();
- }
- // . . . . . . . . . . . . . . . . . .
- static class DoekeLib {
- static Deformer createDeformer() {
- if (g.is3D) {
- return new Deformer3D();
- }
- return new Deformer2D();
- }
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer {
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer2D extends Defomer {
- void printMe() {
- println("2d");
- }
- }
- // . . . . . . . . . . . . . . . . . .
- class Deformer3D extends Deformer {
- void printMe() {
- println("3d");
- }
- }
1