Cannot call Processing functions outside of main class

Hey guys, I am really stumped on this one. I am trying to make a Java application with a central pane that is essentially a Processing output window. Through many hours of googling and experimentation I finally got it to work, which is super awesome.

However, now that my code is getting longer and more cumbersome, I would like to separate my classes out of the main class. My classes currently look like this. You can see that my classes CanvasArea, Shape, Circle, Rectangle, Line, Triangle, and Handle are all just inside of ArtStationApplication. I would prefer to place them in their own file in the same directory as my main class. When I do that, my code will not run any more. All of the processing specific code like color, fill, etc hangs up. I have an import for the processing.core.*; at the top of my separated classes, and I have tried extending my main class. (Which I do not fully understand). Neither allows my code to run. I just get a NullPointerException that traces back to the first call of fill. Here is what I have as my shape class:

package artstationapplication;

 import processing.core.*; /** * * @author wilder4690 */ abstract class Shape extends ArtStationApplication { PVector pos; PVector startingRotation; float angularChange = 0; float rotation = 0; int paint = color(255, 0, 255); int editColor = color(255, 255, 0); float lineThickness = 1; boolean completed = false; boolean selected = false; Shape(float x, float y) { pos = new PVector(x, y); } boolean getFinished() { return completed; } PVector getPosition() { return pos; } void setStartingRotation(PVector mouse) { startingRotation = PVector.sub(mouse, pos); } abstract boolean checkHandles(PVector mouse); abstract void adjustActiveHandle(PVector mouse); abstract void drawShape(); abstract void modify(PVector mouse); abstract boolean mouseOver(PVector mouse); void manipulate(PVector mouse) { pos.set(mouse); } void changeRotation(PVector mouse, boolean shiftKey) { PVector orientation = (pos.x < mouse.x) ? PVector.sub(pos, mouse) : PVector.sub(mouse, pos); //PVector orientation = PVector.sub(mouse,pos); angularChange = PVector.angleBetween(orientation, startingRotation); if (shiftKey) { float leftover = rotation % QUARTER_PI; leftover = round(leftover); rotation = floor(rotation / QUARTER_PI) * QUARTER_PI + (leftover * QUARTER_PI); } } void finishShape() { completed = true; } void select() { selected = true; } void deselect() { selected = false; } } 

Does anyone know what I can do to make this work? Or am I doomed to have the worlds longest wall of text all inside my main class?

submitted by /u/shifty4690
[link] [comments]

beginner needs help building a calculator

I'm incredibly new to programming, and I need to build a working, albeit basic, calculator for my required cp class and am looking for help.

I've currently got a button layout and the ability to click on said buttons, but I don't know where to go from here. I'm largely looking for help setting up a display and getting the buttons to actually execute things like displaying numbers and the four basic functions (addition, subtraction, etc.)

Anything helps!

Code

submitted by /u/super-may
[link] [comments]

How to add a gradient background to this code?

I'm very new to processing, and did try to follow some tutorials as to how to add a background gradient. However for some reason when I hit play, the gradient is visible but only for a split second at the start. It fades away immediately. Any suggestions? For the top I want the colour (18, 23, 36), and transition into the colour (27, 111, 155) at the bottom. I edited out my attempts to implement the gradient:

float shapeRadius = 120; float shapeAngle = 0; // angle star begins rotating int shapeSize = 10; //star size void setup() { size(1024,768); smooth(); noStroke(); background(0); } void draw() { noStroke(); pushMatrix(); fill( 0, 5); // fill with black, low opacity; builds up over old ellipses rect(0, 0, width, height); translate(width/2,height/2); rotate(shapeAngle); translate(shapeRadius,0); fill(255); ellipse(0,0,5,5); popMatrix(); shapeAngle += .05; // speed secondStar(); thirdStar(); forthStar(); } void secondStar(){ noStroke(); pushMatrix(); fill( 0, 5); rect(0, 0, width, height); translate(width/2,height/2); rotate(shapeAngle+90); //angle translate(shapeRadius+50, 0); //radius fill(255); ellipse(0,0,5,5); popMatrix(); } void thirdStar(){ noStroke(); pushMatrix(); fill( 0, 5); rect(0, 0, width, height); translate(width/2,height/2); rotate(shapeAngle+20); translate(shapeRadius+25, 0); fill(255); ellipse(0,0,5,5); popMatrix(); } void forthStar(){ noStroke(); pushMatrix(); fill( 0, 5); rect(0, 0, width, height); translate(width/2,height/2); rotate(shapeAngle+65); translate(shapeRadius+65, 0); fill(255); ellipse(0,0,5,5); popMatrix(); } 
submitted by /u/Nutter_Butter_98
[link] [comments]

Unique Firework Shapes?

Hello! I'm currently working on a final project for my CS class and my group has decided to do a New Years theme display. I found TheCodingTrain's Firework Challenge code and decided it's a decent starting point to figure out how to code fireworks. The fireworks in his code are too frequent and too generic. How do I go about coding unique shapes and making the fireworks appears either more frequent or less frequent?

submitted by /u/Comet0707
[link] [comments]

Spell Check Update – HELP STILL NEEDED

I had the code working. It had each word of the test document in a separate index of a string array. It however, throws out a lot of errors. All I want it to do it compare the words in the string array to the Hash table and add one to missspelled words. Where is my mistake??? It keeps telling me that there is an out of bounds exception at 3.

boolean fileChosen; HashTable Dictionary; int C=0; int mSpell; void setup() { size(200, 200); Dictionary=new HashTable(121870); selectInput("select a file to process:", "fileSelected"); fileChosen =false; String[] Dic = loadStrings("Dic.txt"); //if you want the dictionary to be diffrent, you have to hard code it for (int k=0; k<Dic.length; k=k+1) { Dictionary.add(new HashNode(Dic[k])); } } void fileSelected(File selection) { if (selection == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + selection.getAbsolutePath()); String [] instr = loadStrings(selection.getAbsolutePath()); for (int l =0; l<instr.length; l=l+1) { C=l; println(C); for (int k=0; k<instr[C].length(); k=k+1) { String [] Real = splitTokens(instr[k], ", .!"); for (int j=0; j<Real.length; j=j+1) { println(Real[j]); } } fileChosen=true; } } } void draw() { background (120); for (int k=0; k<Dictionary.tableSize; k=k+1) { fill(255); rectMode(CORNER); if (Dictionary.entries[k]!=null) { rect(0, height/Dictionary.tableSize*k, 180, height/Dictionary.tableSize-2); HashNode n=Dictionary.entries[k]; int xmult =0; while (n!=null) { fill(255); rect(180*xmult, height/Dictionary.tableSize*k, 180, height/Dictionary.tableSize-2); fill(0); text(n.word, 180*xmult+60, height/Dictionary.tableSize*k+height/Dictionary.tableSize/2-2/2); xmult=xmult+1; n=n.next; } } } } void add(HashNode newNode) { int index = hashFunction(newNode.word); //print(newNode.word+" "+ index); HashNode oldNode = entries[index]; //this entries[index] = newNode; newNode.next = oldNode; } HashNode find (String inStr){ int index = hashFunction(inStr); HashNode n=entries[index]; while((n.word.equals(inStr)==false) &&(n!=null)) { n=n.next; } return(n); } } 

Test Document

Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equel.

Now we are engaged in a great civil war, testing whether that natiom, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.

But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the geat task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the peeple, by the people, for the people, shall not perish from the earth.

submitted by /u/Maxkaiserwilhelm
[link] [comments]

Spell Check – LOTS OF HELP NEEDED

I'm working on a project that takes a text document,reads it and tell the user how many words they misspelled. I'm using a hash table for my dictionary. I wanted to then load in the test document and test every word to see if it is found in the dictionary. Instead, I load the test documet and the String [] is now 3 long, for the 3 paragraphs. I tried using splitToken, but it just splits the first word of each paragraph. Im in desperate help, anything would help.

I

boolean fileChosen; HashTable Dictionary; void setup() { size(1000, 1000); Dictionary=new HashTable(121870); selectInput("select a file to process:", "fileSelected"); fileChosen =false; String[] Dic = loadStrings("Dic.txt"); //if you want the dictionary to be diffrent, you have to hard code it for (int k=0; k<Dic.length; k=k+1) { Dictionary.add(new HashNode(Dic[k])); } } void fileSelected(File selection) { if (selection == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + selection.getAbsolutePath()); String [] instr = loadStrings(selection.getAbsolutePath()); for ( int j=0; j<instr.length; j=j+1) { for (int k=0; k<3; k=k+1) { String[] checking = splitTokens(instr[0], ", .!"); println(checking[0]); println(instr[0]); } } } fileChosen=true; } void draw() { background (120); for (int k=0; k<Dictionary.tableSize; k=k+1) { fill(255); rectMode(CORNER); if (Dictionary.entries[k]!=null) { rect(0, height/Dictionary.tableSize*k, 180, height/Dictionary.tableSize-2); HashNode n=Dictionary.entries[k]; int xmult =0; while (n!=null) { fill(255); rect(180*xmult, height/Dictionary.tableSize*k, 180, height/Dictionary.tableSize-2); fill(0); text(n.word, 180*xmult+60, height/Dictionary.tableSize*k+height/Dictionary.tableSize/2-2/2); xmult=xmult+1; n=n.next; } } } } class HashNode { String word; HashNode next; HashNode(String b) { //word = a; //what it is we're looking to bind to the index word = b; next = null; } } class HashTable { HashNode [] entries; int tableSize; HashTable(int ts) { tableSize = ts; entries = new HashNode[tableSize]; } int hashFunction(String inStr) { int outIndex = 0; for (int k = 0;k<inStr.length();k=k+1) { outIndex = outIndex+(int(inStr.charAt(k))*(k+1))*(13*(inStr.length()*inStr.length())); } return(outIndex%(tableSize/10)); //forces } void add(HashNode newNode) { int index = hashFunction(newNode.word); //print(newNode.word+" "+ index); HashNode oldNode = entries[index]; //this entries[index] = newNode; newNode.next = oldNode; } HashNode find (String inStr){ int index = hashFunction(inStr); HashNode n=entries[index]; while((n.word.equals(inStr)==false) &&(n!=null)) { n=n.next; } return(n); } } 

Test Document

Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equel.

Now we are engaged in a great civil war, testing whether that natiom, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.

But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the geat task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the peeple, by the people, for the people, shall not perish from the earth.

submitted by /u/Maxkaiserwilhelm
[link] [comments]