Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
barryneedhelp
barryneedhelp's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Need Help with reading strings from an external text file
[2 Replies]
01-May-2013 09:07 AM
Forum:
Programming Questions
I need of some help with my processing program that i am doing for a college assignment.
It works until you try and take a value from the external file using the scanner class.
I have very little knowledge of Java with processing so I would appreciate some help with this please.
main class -
WordRipple
import processing.core.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class WordRipple extends PApplet{
ArrayList<Ripple> ripples;
int rippleWidth = 10;
public void setup() {
size(500, 500);
smooth();
noStroke();
ripples = new ArrayList<Ripple>();
ripples.add(new Ripple(this, width/2, height/2, rippleWidth));
//colorMode(HSB, 360, 100, 100);
textAlign(CENTER);
}
public void draw() {
background(360);
Ripple ripple;
for (int i=0; i<ripples.size(); i++) {
ripple = ripples.get(i);
ripple.wave();
ripple.display();
if (ripple.finished()) {
ripples.remove(i);
}
}
}
public void mousePressed() {
float x, y;
// double x, y;
for (int i=1; i<=10; i++) {
//double z = 36*i;
//float z = 36*i;
x = mouseX;// + 100 * sin(radians(z));
y = mouseY;// - 100 * cos(radians(z));
ripples.add(new Ripple(this, x, y, rippleWidth));
}
}
}
and my second class - Ripple
import processing.core.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Ripple extends PApplet {
public Ripple(String stringRead) throws FileNotFoundException {
File inputFile = new File( "input.txt" );
try
{
Scanner scan = new Scanner(inputFile);
while ( scan.hasNext( ) )
{
// read next String
stringRead = scan.nextLine( );
// process the value read
System.out.println( stringRead );
}
//release resources associated with string.txt
scan.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("Unable to find input.txt, exiting");
fnfe.printStackTrace();
}
}
//String words = "HELLOWORLD";
String words = stringRead;
int len = words.length();
float angle = 360 / len;
int radius = 50;
PApplet papplet;
float x, y, w;
float life;
public Ripple(PApplet p, float x, float y, float w) {
papplet = p;
this.x = x;
this.y = y;
this.w = w;
this.life = 75;
}
public void wave() {
w += w/30;
}
public boolean finished() {
life--;
if (life < 0) {
return true;
}
else {
return false;
}
}
public void display() {
papplet.pushMatrix();
papplet.translate((float)(x), (float)(y));
for (int i = 0; i < len; i++) {
papplet.pushMatrix();
papplet.rotate(radians(i * angle - 90));
papplet.translate((float)(radius*1.8),0);
papplet.rotate(radians(90));
papplet.fill(i * angle * 100 / 360, 100, 100, life);
papplet.textSize(w);
papplet.text(words.charAt(i), 0, 0);
papplet.popMatrix();
}
papplet.popMatrix();
}
}
Kind Regards,
Barry
«Prev
Next »
Moderate user : barryneedhelp
Forum