Loading...
Logo
Processing Forum
cucuatdottie's Profile
2 Posts
1 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hey everybody ! 
    My name is Duc, I'm from Germany and I want to use the Mergesort-Algorithm but I have no idea how to. 
    I already read tons of forums showing me how to do it but just in other languages like Java or C#,++.
    But still, I tried to write a code by myself but it doesn't work so I hope u guys can help me in a way. :D 

    here's the code :

    1. void mergesort(int [] list)
    2. {
    3.   if(list.length<=1)
    4.   { 
    5.     return;
    6.   }else{
    7.  int [] left = new int[list.length/2];
    8.  int [] right = new int[list.length - left.length];
    9.  return merge(left,right) 
    10.  }
    11. }

    12. void merge(int [] left,int [] right){
    13.   int x=0;
    14.   int y=0;
    15.   int z=0;
    16.   while( x< left.length && y < right.length)
    17.   { 
    18.     if(left[x] <= right[y])
    19.     {
    20.       
    21.       list[z] = left[x];
    22.       x++;
    23.       
    24.     }
    25.     else
    26.     {
    27.       
    28.       left[z] = right[y];
    29.       y++;
    30.    
    31.     }
    32.       z++;   
    33.   }
    34.   for(int i=x; i< left.length;i++)
    35.   {
    36.     list[z] = left[i];
    37.     z++;
    38.     
    39.   }
    40.   for(int j=y;j<right.length, i++)
    41.   {
    42.     list[z]=right[i];
    43.     z++;
    44.     
    45.   }
    46. }

    okay , that's it . The code isn't finished yet and I really have no idea where to fix what.

    There's another Question:

    I wanna use the Mergesortalgorithm in 


    1. int sy,sx,sy1;
    2. int [] b;
    3. int [] [] points;


    4. void setup ()
    5.   frameRate(3);
    6.   size(400,400);
    7.   sy1=height;
    8.   sx=width;
    9.   sy=200;
    10.   points = new int [sx][sy];
    11.   
    12.   for(int i =0; i < sx; i++) {
    13.     for(int j =199; j < sy; j++) {
    14.       points[(int)random(sx)][(int)j]=(int)random(10);
    15.  
    16.  
    17.  
    18. }
    19.   }
    20. }

    1. void draw() {
    2.   background (255);
    3.   
    4.   for (int x = 0; x < sx; x=x+1) { 
    5.     for (int y = 0; y < sy; y=y+1) { 
    6.       
    7.       if ((points[x][y] == 1) ) 
    8.       {  
    9.         stroke(#682292);
    10.         line(x,y-60,x,y+60);
    11.       } 
    12.       
    13.       if ((points[x][y] == 2) ) 
    14.       { 
    15.         stroke(#982828);
    16.        line(x,y-120,x,y+120);
    17.       } 
    18.       
    19.       if ((points[x][y] == 3) ) 
    20.       { 
    21.         stroke(#292898);
    22.        line(x,y-30,x,y+30);
    23.       } 
    24.       
    25.       if ((points[x][y] == 4) ) 
    26.       { 
    27.         stroke(#2AA044);
    28.        line(x,y-10,x,y+130);
    29.       } 
    30.       
    31.       if ((points[x][y] == 5) ) 
    32.       { 
    33.         stroke(#DBC928);
    34.        line(x,y-160,x,y+160);
    35.       } 
    36.       if ((points[x][y] == 6) ) 
    37.       { 
    38.         stroke(#FF7048);
    39.        line(x,y-210,x,y+50);
    40.       } 
    41.       if ((points[x][y] == 7) ) 
    42.       { 
    43.         stroke(#48FFB1);
    44.        line(x,y-70,x,y+70);
    45.       } 
    46.       if ((points[x][y] == 8) ) 
    47.       { 
    48.         stroke(#000000);
    49.        line(x,y-180,x,y+180);
    50.       } 
    51.       if ((points[x][y] == 9) ) 
    52.       { 
    53.         stroke(#151515);
    54.        line(x,y-60,x,y+40);
    55.       } 
    56.       if ((points[x][y] == 10) ) 
    57.       { 
    58.         stroke(#383838);
    59.        line(x,y-120,x,y+30);
    60.       } 
    61.     
    62.   }

    63. }

    as you can see a row of colorful lines .
    They're all indexed with numbers of course and I wanna sort them. 
    Where do I have to put mergesort() in and what do I have to put in these brackets ? 
    Because points[] isn't enough . It always tells me : "After "[" a character expected"

    I hope u guys can help me , I'm looking forward to see results.  And sorry for my weird English haha.
    Hey guys , i've got a problem .
    I just want mark the egdes on a random blackwhite picture and i have to work with a average value.
    The problem is that i don't know the value so i cannot compare the current average value with the usual average value.

    Here is the source :


    PImage laa;

    void setup () {
      size (344,400);
      laa = loadImage("xyz.jpg");
      noLoop();
    }

    void draw(){
      image(laa ,0 , 0);
      for(int x=0; x<344; x++){
        for(int y=0; y<400; y++){
      float mitte = blue(get(x,y));
      float rechts = blue(get(x+1,y));
      float links = blue(get(x-1,y));
      float oben = blue(get(x,y+1));
      float unten = blue(get(x,y-1));
      float mw = (oben+unten+rechts+links+mitte)/5;
          color i = get(x,y);
      float r = red(i);
      float g = green(i);
      float b = blue(i);
      stroke(r,g,b);
      point(x,y);
     
        }
      }
    }





    so what I want is to mark the pixel if the  average value of the pixel (with the neighbouringpixels ) is very different
    than the usual average value .
    How to do ?
    please help me ! =)