Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Help

Name: Anonymous 2011-02-10 17:39

So /prog/  I'm working on this little bit of java code for school.  What it's supposed to do is read through a pgm file (which is an array as far as I know) and then put horizontal white lines through it. 

The problem is that it only puts lines 2/3 of the way across the image and I have no idea why.  Any help would be greatly appreciated, code below.



public void gridH(int lineSpacing, int lineWidth){
for (int col = 0; col < pixels.length; ++col){

for(int  grid = 0; grid < pixels.length; grid = grid + lineSpacing + lineWidth){

for(int row =  grid; row < grid + lineWidth;  row++){
        
        int gScale = 255;
                pixels[row][col] = gScale;

Name: Anonymous 2011-02-10 19:15

Use code tags for code.

public void gridH(int lineSpacing, int lineWidth) {
   int i = this.pixels.length; //number of rows
   int j = this.pixels[0].length; //number of columns
   int k = lineWidth * j; //number of pixels making one "line"
   int row = 0, col = 0;
   for(; row < i; row = row + lineWidth + lineSpacing) {
      int col = 0;
      for(; col < k; ++col) {
         int gScale = 255;
         this.pixels[row+(int)(col/j)][col%j] = gScale;
      }
   }
}

Provided this.pixels.length reflects the actual height of the image and this.pixels[0].length (as a sample) reflects the actual width of the image, this should work more or less.

Name: Anonymous 2013-01-19 23:41

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List