<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with min() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=min%28%29</link>
      <pubDate>Sun, 08 Aug 2021 20:19:22 +0000</pubDate>
         <description>Tagged with min() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmin%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Problems with transpose a 2D array or matrix ...</title>
      <link>https://forum.processing.org/two/discussion/25921/problems-with-transpose-a-2d-array-or-matrix</link>
      <pubDate>Fri, 12 Jan 2018 09:39:11 +0000</pubDate>
      <dc:creator>nowtronix</dc:creator>
      <guid isPermaLink="false">25921@/two/discussions</guid>
      <description><![CDATA[<p>Hello !</p>

<p>I have a question about the transpose of a 2D Array or Matrix. 
I wrote a short programm to explain my problem:</p>

<pre><code>int [][] matrix = { {0, 0, 0}, 
                    {0, 1, 0}, 
                    {1, 1, 1} };

int [][] tmpMatrix = new int [3][3];
int [][] newMatrix = new int [3][3];

void setup() {
  size(800, 600);
  background(0);
  tmpMatrix = matrix;
}

void draw() {
  drawMatrix(newMatrix);
  for (int j = 0; j&lt;3; j++) {
    for (int i = 0; i&lt;3; i++) {

      **newMatrix[j][i]**=tmpMatrix[i][j];
    }

    print("\n");
  }
  drawMatrix(matrix);
  drawMatrix(tmpMatrix);
  drawMatrix(newMatrix);
  noLoop();
}

void drawMatrix(int [][] matrix) { 
  for (int j = 0; j&lt;3; j++) {
    print("\n");
    for (int i = 0; i&lt;3; i++) {
      print(matrix[j][i]);
    }
  }
  print("\n");
}
</code></pre>

<p>So this programm works fine and I get the transpose of the Matrix in "newMatrix".</p>

<p>But when I change the variable from "newMatrix" into "matrix" (I mean inside of the two for loops) the transposed matrix is wrong !</p>

<p>I don't understand what is the problem here.</p>

<p>Thank you a lot !</p>
]]></description>
   </item>
   <item>
      <title>Text array in p5js</title>
      <link>https://forum.processing.org/two/discussion/18026/text-array-in-p5js</link>
      <pubDate>Wed, 31 Aug 2016 17:36:33 +0000</pubDate>
      <dc:creator>alexdontsurf</dc:creator>
      <guid isPermaLink="false">18026@/two/discussions</guid>
      <description><![CDATA[<p>Hello there,</p>

<p>I am trying to reproduce an old sketch in p5js but I ran into troubles...</p>

<p>Here is the code</p>

<pre><code>var fontRegular, fontBold

var offset = 20
var z = 0.0

function preload(){

    fontRegular = loadFont("assets/Regular.otf")
    fontBold = loadFont("assets/Bold.otf")
}


function setup() {

    createCanvas(windowWidth, windowHeight)
    colorMode(HSB,360, 100, 100);

}

function draw() {

    background(5)       

    var chars = "+ — I O"
    var splitString = split(chars, " ");

    textFont(fontRegular);
    fill(0,0,100).strokeWeight(0).textSize(20)
    text(s, 10, 10, 200, 80)

    for ( var x = offset; x &lt; width - offset; x += offset){
        for (var y = offset; y &lt; height - offset; y += offset){


            var nl = map(noise(z, x/450.0, y/450.0), 0, 1, 0, 3)

            text(chars[nl], x, y)
        }
    }

    z = z + .0006

}
</code></pre>

<p>Console is given me an error from the p5.js library:
p5.js:12854 Uncaught TypeError: Cannot read property 'toString' of undefined</p>

<p>This is the original sketch that works perfectly in Processing:</p>

<pre><code>float z = 0.0;
PFont myFont;
int offset = 18;

void setup(){
  size(500,700);
  pixelDensity(displayDensity());
  //colorMode(HSB, 360,300,360);
  noStroke();
  myFont = createFont("MaisonNeue-Bold", 10);
  textFont(myFont);
  textAlign(CENTER, CENTER);

}

void draw() {

  background(255);
  String[] chars = split("+ — I O + C", ' ');

  for ( int x = offset*3; x &lt; width-offset*2; x +=offset){
    for ( int y = offset*3; y &lt; height-offset*2; y += offset){

      int nl = (int) map(noise(z, x / 450.0, y / 450.0), 0, 1, 0, 7);

      fill(0);
      rectMode(CENTER);
      if ((y - 16) % (2) == 0){
        text(chars[nl], x,y );}
        else{
        text(chars[nl], x + 8 ,y);
        }

    }
  }

  z = z + .006;

}
</code></pre>

<p>I'm guessing I am doing something wrong with arrays in p5js...</p>

<p>Any suggestions?</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>Array of points, nullpointer exception</title>
      <link>https://forum.processing.org/two/discussion/17775/array-of-points-nullpointer-exception</link>
      <pubDate>Sun, 07 Aug 2016 02:15:37 +0000</pubDate>
      <dc:creator>Trilobyte</dc:creator>
      <guid isPermaLink="false">17775@/two/discussions</guid>
      <description><![CDATA[<p>Hello all;
If you look at another one of my discussions you will see I have been working on a genetic algorithm. I currently am experiencing a problem whilst trying to plot points of data in another window I have created. I get a null pointer exception after a little bit while running the code. The points do not show up. Please take a look at the code and please advise. Thanks.</p>

<pre><code>    import org.gicentre.utils.stat.*;  //import graph library

    import g4p_controls.*;

    ArrayList&lt;Ball&gt; balls = new ArrayList(); // arraylist for ball objects
    ArrayList&lt;Point&gt; points = new ArrayList();
    float gcorX, gcorY; // goal coords
    int timeIter = 300; //time step- internal clock

    float bscore; //best score

    String[] str_a;   //one copy of scorelist (use to copies to determine best and worst)
    String[] str_b;   //one copy of scorelist (use to copies to determine best and worst)
    float[] scores;   //scorelist
    final int pop = 10; //population size- final bc it shouldnt be changed in the program
    int cur_sub;      //current iteration- OLD METHOD, but still in just in case
    public int gen_num = 0; //count generation number
    int countDone; // count how many balls in the population finished their run in that generation
    float diameter = 30;
    float globmin = 1000; //base var
    float [] generations; // array of generations

    GWindow window;

    Ball globalBall = new Ball(-1, "0"); // starter/ global best ball


    public void windowDraw(PApplet app, GWinData data) {

      app.background(0);
      app.stroke(255);
      app.strokeWeight(8);
      //app.point((gen_num*2), min(scores));
      for ( int j = 0; j &lt; gen_num; j++ ) {
        points.add( new Point(gen_num*2, min(scores) ) );
      }

      for ( int i=0; i &lt; points.size(); i++ ) points.get(i).display();
    }

    public void windowMouse(PApplet app, GWinData data, MouseEvent event) {
    }

    public void windowKey(PApplet app, GWinData data, KeyEvent event) {
    }

    void setup() {
      size(800, 800);
      background(0);

      generations = new float[gen_num]; // init generations with size

      window =  GWindow.getWindow(this, "Graph", 100, 50, 500, 500, JAVA2D);

      window.addDrawHandler(this, "windowDraw");
      window.addMouseHandler(this, "windowMouse");
      window.addKeyHandler(this, "windowKey");

      bscore = dist(0, 0, width, height); // calc score
      gcorX= random(width);
      gcorY= random(height);

      ellipseMode(CENTER);

      //begin init scorestrings
      str_a = new String[pop];
      str_b = new String[pop];
      scores = new float[pop];
      for (int j = 0; j&lt;pop; j++) {
        str_a[j] = starterString();
        scores[j] = 0;
      }
      //end init scorestrings

      //for every done ball, add a new one/replace it
      cur_sub = -1;
      countDone = 0;
      for ( int i=0; i &lt; pop; i++ ) balls.add( new Ball( i, str_a[i] ) );
    }


    //begin init of starter string( Initial) so that the mutation has a place to begin

    String starterString() {
      String mut = "" + char( '0' + int( random(4) ) ); //  + "00000000" ;
      return( mut );
    }

    //end init

    //begin init instructions and strings of values- cr and hr refer to the textlines explaining each movement. r is a placeholder string so that the strings return a value to it based on the results of the cr loop

    String hr( String cr ) {
      String r = "";
      for ( int t = 0; t &lt; cr.length(); t++) {
        if ( cr.charAt(t) == '0' ) r+= 'N';
        if ( cr.charAt(t) == '1' ) r+= 'L';
        if ( cr.charAt(t) == '2' ) r+= 'R';
        if ( cr.charAt(t) == '3' ) r+= 'A';
      }
      return( r );
    }

    //end init instructions and cr/hr

    void draw() {
      background(0); //layer 2
      fill(255, 0, 0); //red
      //starting pad
      pushMatrix();
      stroke(255, 200);
      fill(0, 255, 0, 200);
      ellipse(width/2, height/2, 25, 25);
      popMatrix();
      //end starting pad


      String extra = ""; //message
      if ( bscore &lt; 20 ) extra = "That's close enough! Click the mouse to move the goal."; //message

      //text inits and placements
      pushMatrix();
      fill(255, 0, 0);
      text("| Best ever: (" + hr(globalBall.genome) + ") = " + int(bscore) + " |", 50, 20 );
      popMatrix();

      pushMatrix();
      fill(255, 200);
      text("| key: A = accelerate, R = right, L = left, N = do nothing | ", 500, height-20);
      popMatrix();

      pushMatrix();
      fill(0, 0, 255);
      text(extra, 30, height -20);
      popMatrix();

      pushMatrix();
      fill(#3FB73F);
      text("| Generation " + gen_num+ " |", 280, 20 );
      text("| minimum of gen:" + (min(scores))+ " |", 400, 20); //why does this get a NullPointer Exception? and why does it not plot the points? Frustrated. 
      text("| best:" + (bscore)+ " |", 600, 20);

      popMatrix();
      //end text inits and placements

      //globmin = min(globmin, min(scores));
      //text("globmin: " + globmin, 250, 34);


      //text for genome (hr/cr);
      for ( int tt=0; tt&lt; pop; tt++) {
        fill (balls.get(tt).col);
        text( "(" + hr( balls.get(tt).genome ) + ")", 10, 48 + 14 * tt);
      }
      //text for genome (hr/cr);

      // If no ball, last ball is done, simulate next one.
      // If all balls done, simulate next generation.
      if ( countDone == pop ) { // balls.size() == 0 ) {
        while ( balls.size () &gt; 0 ) balls.remove(0); 
        //cur_sub++;
        // If all balls in this generation simulated, create next generation.
        //if ( cur_sub == gen_size ) {
        countDone = 0; // cur_sub = 0;
        //println( "Making next generation..." );


        // Always keep the best one, and toss the worse.
        arrayCopy( str_a, str_b ); //copy for scrambling later
        int bestIndex = 0;
        int worstIndex = 0;
        for ( int j = 0; j &lt; pop; j++ ) {
          if ( scores[bestIndex] &gt; scores[j] ) {
            bestIndex = j;
          } //getting best score for index

          if ( scores[worstIndex] &lt; scores[j] ) {
            worstIndex = j;
          }
          //getting worst score for index
        }  

        str_b[worstIndex] = str_b[bestIndex]; // Replace the worst with a copy of the best for breeding.

        // Scramble.
        for ( int j = 0; j &lt; pop; j++ ) {
          str_a[j] = scramble( j, str_b[int(random(pop))], str_b[int(random(pop))] ); //scrambles initial a(stored in b) and replaces old a with new values
        }
        str_a[0] = str_b[bestIndex]; // Always keep the best.
        //Add all the balls to simulate.

        for ( int j = 0; j &lt; pop; j++ ) {
          balls.add( new Ball( j, str_a[j] ) );
        }

        gen_num++; //increment generation counter

        //}
      }

      globalBall.render(); // draw best as red(see coloring above in beginning of draw)


      for ( int i=0; i &lt; balls.size(); i++ ) balls.get(i).move(); //init move function for balls

      //begin goal init

      stroke(255);
      fill(255, 140);
      ellipse(gcorX, gcorY, diameter, diameter);

      //end goal init
    } // end draw

    String scramble( int which, String a, String b ) { // begin switching random values with substring r as the intermediate
      String r;
      int pos = int(random(min(a.length(), b.length())));
      r = a.substring(0, pos) + b.substring(pos, b.length());

      // Mutation! //change or add a random value between position 0 and length of r
      if ( random(1) &lt; .5 ) {
        pos = int(random(r.length()));
        if ( random(1) &lt; .5 ) { 
          String mut = "" + char( '0' + int( random(4) ) );
          //println( "New Ball #" + which + ": Mutation! Adding a char: '" + mut + "' at position " + pos );
          r = r.substring(0, pos) + mut + r.substring(pos, r.length());
        } else {
          if ( r.length() &gt; 0 ) {
            pos = int(random(r.length()-1));
            //println( "New Ball #" + which + ": Mutation! Losing the char at position " + pos );
            r = r.substring(0, pos) + r.substring(pos+1, r.length());
          }
        }
      }
      return( r ); //return the value to change the initial strings, reset w/change basically
    }

    //begin goal changing 
    void mousePressed() {
      if (mouseButton == LEFT) {
        gcorX = random(width);
        gcorY = random(height);
        bscore = dist(0, 0, width, height);
        gen_num=0;
      }
    }
    //end goal changing


    class Ball {
      float x, y, z, v; //position related
      color col; //color of balls
      int current_inst;//current instruction
      int inst_time;//time between instructions
      int[] instructions; //array of instructions
      boolean dis = false; //disable ball
      int num; //uuuhhhh... i forget
      String genome; //GENOME
      int checknum; //check number for genome val to ensure smooth transition

      boolean inst_a, inst_b, inst_c; //instructions

      Ball(int cknum, String input) {
        //x = width/2;
        //y = height-20;
        x = width/2;
        y = height/2;
        if (cknum == -1) {  
          x = -20;
          y = -20;
        }
        z =0;
        v = 0;

        col=color(random(40, 255), random(40, 255), random(40, 255), 200);
        inst_a = inst_b = inst_c = false; 
        checknum = cknum; //making sure the numbers are the same to avoid glitches
        current_inst = 0;
        checkString( input );
        inst_time = millis() + timeIter;
        dis = false; //not disabled
        genome = input; //read input (parse/checkstring) and input it into the genome
      }

      void checkString(String in) {    //parsing function
        instructions = new int[in.length()];
        for ( int j = 0; j &lt; in.length(); j++ ) {
          instructions[j] = int( in.charAt(j) - '0' );
        }
        //reads each character in the input string and puts it into instructions to be enacted
      }

      //begin scoreReport- uses an array to store the scores of the generation so that a best and a worst can be calculated

      void scoreRep() {
        scores[checknum] = dist(x, y, gcorX, gcorY) + genome.length(); //uses the distance between the translated ball(at x, y) and the goal at the gcords. //also, just added a penalty for length of genome, to try and promote a more direct route
        if ( scores[checknum] &lt; bscore ) { // if the score is not the best score, change the scores to be recalculated by the next generation
          bscore = scores[checknum];
          globalBall.x = x;
          globalBall.y = y;
          globalBall.z = z;
          globalBall.col = col;
          globalBall.genome = genome; //checks the best aspects and records the genome, moves the values for position
        }
        countDone++;
        //if ( scores[checknum] &lt; 20 ) {
        //  gcorX = random(width);
        //  gcorY = random(height);
        //}
        //balls.remove(0);
      }

      void move() {
        if ( millis() &gt; inst_time &amp;&amp; !dis) { // if the millisecond function (internal clock) is greater than the instance time and not disabled, 
          inst_time = millis() + timeIter; //time between things
          if ( current_inst &lt; instructions.length ) { //for every instruction in the instruction array 
            int i = instructions[current_inst++]; //i is used to represent the value of the instruction at the current instruction value
            switch( i ) { //switches between actions for instruction. For example, if the value "i" is 2, it would enact instruction case 2. it reads and enacts on the instructions based on their value and reads them in sequence based on their position in the array
            case 0:
              // Do nothing.
              break;
            case 1:
              inst_a = !inst_a;
              break;
            case 2:
              inst_b = !inst_b;
              break;
            case 3:
              inst_c = !inst_c;
              break;
            default:
              //println( "Bum instruction: " + i )//instruction does not exist
              break;
            }
          } else { // Terminate run.
            inst_a=inst_b=inst_c=false;
            v=0;
            dis = true; // disable is true, end run, set v to 0, set instructions to false, and statify the scoreReport
            scoreRep();
          }
        }
        // movement systems follow.
        z+=(inst_a?-.1:0)+(inst_b?.1:0); //conditional operator/ternary operator. I dont want to explain it here, it is a shorthand. Go here for more: <a href="http://stackoverflow.com/questions/798545/what-is-the-java-operator-called-and-what-does-it-do" target="_blank" rel="nofollow">http://stackoverflow.com/questions/798545/what-is-the-java-operator-called-and-what-does-it-do</a>
        v+=(inst_c?.1:0); //conditional
        //x=(x+width+v*cos(z))%width;
        //y=(y+height+v*sin(z))%height;
        x=x+v*cos(z); //math for x based on angle of movement (v is basically serving as a hypotenuse here)
        y=y+v*sin(z); //math for y based on angle of movement (v is basically serving as a hypotenuse here)
        v*=.99;
        render(); //calls a display function
      }
      void render() {
        pushMatrix(); //layer 4
        translate(x, y); //move the thing by the x and y calculated in move
        rotate(z); //rotate by z
        noStroke();
        fill(col); //fill with color 

        if ( checknum==-1) fill(255, 0, 0); //if it is the best ball, color it red
        ellipseMode(CENTER); //put measurements in center
        ellipse(0, 0, 25, 25); //ball size
        stroke(0);//black edge

        noFill(); //triangle no fill
        triangle(-6, -5, 8, 0, -6, 5); //  triangle(-5, -8.66, 0, 10, 5, -8.66);
        popMatrix();
      }
    }

    class Point {

      float xpos;
      float  ypos;


      Point(float x, float y) {
        xpos = x;
        ypos = y;
      }

      void display() {
        pushMatrix();
        fill(255, 0, 0);
        strokeWeight(6);
        point(xpos, ypos);
        popMatrix();
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is there a way I can compare numbers in a row from a table to find the smallest</title>
      <link>https://forum.processing.org/two/discussion/15988/is-there-a-way-i-can-compare-numbers-in-a-row-from-a-table-to-find-the-smallest</link>
      <pubDate>Tue, 12 Apr 2016 15:11:52 +0000</pubDate>
      <dc:creator>AmazingSuperDry</dc:creator>
      <guid isPermaLink="false">15988@/two/discussions</guid>
      <description><![CDATA[<p>Hey really new to programming, wanted to know if there was a way I could compare integers in a row (short cut way). SO that I can implement a simple nearest neighbour algorithm. I think I can do this a long way but wants to know if there was already an inbuilt function to compare numbers in processing.</p>
]]></description>
   </item>
   <item>
      <title>How to cover scattered point???</title>
      <link>https://forum.processing.org/two/discussion/12873/how-to-cover-scattered-point</link>
      <pubDate>Wed, 07 Oct 2015 11:21:47 +0000</pubDate>
      <dc:creator>kir</dc:creator>
      <guid isPermaLink="false">12873@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I have few set of point in the form (x,y coordinate),I would wish to draw a ellipse (i.e.circle) such that it all points fall within the circle.Would really appreciate if some one can help me .</p>

<p>Thanks in advance !!!!</p>
]]></description>
   </item>
   <item>
      <title>error code help plz (-ve strokeweight)</title>
      <link>https://forum.processing.org/two/discussion/12702/error-code-help-plz-ve-strokeweight</link>
      <pubDate>Sun, 27 Sep 2015 17:10:55 +0000</pubDate>
      <dc:creator>MaverickT90</dc:creator>
      <guid isPermaLink="false">12702@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I'm really new to processing and honestly not very good at coding but am trying to learn. I'm trying to make a simple paint type of thing and keep getting an error because my stroke weight is going below zero. My question would be how to stop that from happening.</p>

<pre><code>float px;
float py;
float strokeW = 1;

//draws once
void setup() {
  size(400, 400);
  background(255);
}

//draws everyframe
void draw() {
  px = pmouseX;
  py = pmouseY;


  //draws my line(paint brush)
  if (mousePressed) {
    stroke(10);
    fill(0);
    line(mouseX, mouseY, px, py);
  }

  //this increases the size of line
  if (keyPressed) {
    if (key == ']' || key == '}') {
      //created a variable for strokeWeight and added
      //strokeWeight = itself plus 1 for increaseing the size
      strokeW++;
    }

  //this decreases the size of my line
    if (keyPressed) {
      if (key == '[' || key == '{') {
        //opposite process for decrease
        //but i do have a problem because i can decrease the size
        //of the line until it is gone and the program freezes
        strokeW--;
      }
    }
  }
}
</code></pre>

<p>and i tried adding this to stop it but no luck yet</p>

<pre><code> if (strokeW &lt; 1) {
          strokeWeight(1);
        }
</code></pre>

<p>???</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to tell my program, that an integer-value shall never exceed 100?</title>
      <link>https://forum.processing.org/two/discussion/11661/how-to-tell-my-program-that-an-integer-value-shall-never-exceed-100</link>
      <pubDate>Sun, 12 Jul 2015 20:52:18 +0000</pubDate>
      <dc:creator>injuvik</dc:creator>
      <guid isPermaLink="false">11661@/two/discussions</guid>
      <description><![CDATA[<p>A simple question: How can i tell my program, that int "a" shall never exceed 100?</p>
]]></description>
   </item>
   </channel>
</rss>