I don't know quite how to describe what I want to do, but here it goes:
I want to have a function that takes every Nth value of a subarray and outputs it into a 1D array. The array that it is taking data from has two dimensions, one with between 1 and 8 thousand elements, each subarray containing 42 elements. I want to take every 3rd element (for example) of every element and output that into a single array. This is not the problem, though.
I want to have a function take, preferably as input, the multidimensional array to be broken up, and the type of the output array, as well as the integer which represents which of the 42 subarray elements to extract and pipe to the separate, secondary array. The second item is the one that is of interest to me. I want to know if it is possible for a function to take type (e.g. int, float, double, String[]) as an input so that the output type can vary depending on the input value. I may find a simpler way to do this after more thought, but in the meantime, is there a way for a function to take a type as input?
I am sure that I am doing something very basic wrong here, but I cannot identify what it is because of my lack of experience using multidimensional arrays. I have read this:
CommonErrors - Processing and I assume it is a problem with me having not properly allocated space for the array(s), even though the error comes up when I try to do that.
I have the whole (unfinished) code above, with the area of interest highlighted in yellow and the line that is highlighted for the NullPointerException error highlighted in green. I would be surprised if this was not a simple fix, but I cannot seem to figure out what it is. Thanks!
I am writing a program that records user input for the location of two axes of what will become a graph. Once distances from the edge of the window are set, I want the program to create a ratio that will allow the window to be resized so that when it is, the axes are still the same relative distance away from the window borders. If that statement isn't clear enough, I want the user to place (for example) the graph's y axis in the desired location. Then, if the user decreases the width of the window by 50%, the distance between the window's edge and the y axis also decreases by 50% rather than there being a constant difference of space between them (i.e. 32 pixels, or something like that).
I thought that that would be a fairly simple thing to do, but I have been running into problems with, what I assume, is Processing rounding the numbers I need for the ratio to zero. Unless I have made some coding mistake that I missed, the numbers (only two decimal places) put out by the simple line of division always end up being zero.
There is the code, as it stands, in my sketch right now. Although some of it may not make sense, I was doing a bunch of commenting-out for debugging purposes. The only area of interest relative to this problem (I think) is the highlighted region, but I included all of the code so that it's in-context.
Thanks!
~J
//Initialize variables PFont font; int xofy, yofx; //x-cor of y axis, y-cor of x axis float xrat, yrat; //ratio of difference between window width and x-cor of y axis to window width, ratio of difference between window height and y-cor of x axis to window height boolean clicked = false; boolean done = false; void setup() { size(800, 500); frame.setResizable(true); font = loadFont("CourierNewPSMT-16.vlw"); //font = createFont("CourierNewPSMT", 16, true); } void draw() { //Set up to draw lines and write text background(0); fill(255); stroke(255); textFont(font, 16); textAlign(CENTER, CENTER); /* if(!(done)) { //If selections have not been made if (clicked) { //If the user has already aligned the y axis line(xofy, 0, xofy, mouseY); //Draw a line from the top of the window to the mouse's y-cor along the selected x-cor value line(xofy, mouseY, width, mouseY); //Draw a line from the bottom left corner where the already selected x-cor meets the mouse's y-cor if (yofx!=0) { //If the mouse has not been clicked a second time text(width+" pixels by "+height+" pixels are the window dimensions\nx: "+mouseX+" "+xofy+"\ny: "+(height-mouseY)+" "+yofx, width/2, (height/2)-75); } else { text(width+" pixels by "+height+" pixels are the window dimensions\nx: "+mouseX+" "+xofy+"\ny: "+(height-mouseY)+" "+(height-mouseY), width/2, (height/2)-75); } } else { //If the mouse has not been clicked line(mouseX, height/2, width, height/2); //Draw a line from the mouse's x-cor to the edge of te window along the center of the window horizontally line(mouseX, 0, mouseX, height); //Draw a line to the top and bottom of the screen in line with the mouse's x-cor if (yofx!=0) { //If the mouse has not been clicked a second time text(width+" pixels by "+height+" pixels are the window dimensions\nx: "+mouseX+" "+mouseX+"\ny: "+(height-mouseY)+" "+yofx, width/2, (height/2)-75); } else { text(width+" pixels by "+height+" pixels are the window dimensions\nx: "+mouseX+" "+mouseX+"\ny: "+(height-mouseY)+" "+(height-mouseY), width/2, (height/2)-75); } } } else { *///If the selections for both axes have been made xofy = 40; yofx = height-25; frame.setResizable(false); //Temporarily, the user can no longer resize the window //line(xofy, yofx, xofy, 0); //Both axes with their finalized points are made //line(xofy, yofx, width, yofx); text("Your lines are "+xofy+" pixels from the left window border\nand "+(height-yofx)+" pixels away from the bottom window border.\nThe window is "+width+" pixels by "+height+" pixels.\nClick anywhere to continue.", width/2, height/2); xrat = (height-yofx)/height; //Ratio of distance between window's edge and y axis to height yrat = xofy/width; //Ratio of distance between window's edge and x axis to height //println(xrat+" "+yrat); /*line(yrat*width, abs((xrat*height)-((1-xrat)*height)), yrat*width, 0); line(yrat*width, abs((xrat*height)-((1-xrat)*height)), width, abs((xrat*height)-((1-xrat)*height)));*/ } //} void mouseClicked() { if (!(done)) { if (clicked) { yofx = mouseY; done = true; clicked = false; } else { xofy = mouseX; clicked = true; } } else { //Do nothing } }