Day 11th -2015-3-27-processing Tutorial-api-First lecture-map (), table,loadtable (), Norm (), Lerp ()

Source: Internet
Author: User
Tags mathematical functions

Hi!! Today on-line found that I have a fan!! Wow, so happy!

But I broke my promise yesterday and didn't go on more ... Hope not to lose powder .....

But that is for a reason, I have been looking for data yesterday, and finally today to tidy up, I intend this weekend the whole. Then you can get a really powerful tutorial!!

Let me start with a tutorial that I'll come up with next, and then say what this is about today.

Next:

1, US unemployment data visualization

2, map data visualization case study (case from processing teaching book visualizing data)

3, regional analysis of Chinese college Entrance examination

4,api Tutorials

And talk about what it is today.

In simple terms, it is the same thing as reading notes. When I read the example of visualizaing data (which is actually included in the processing), I found

The author used a function I completely useless, that is, map,norm,lerp, and so on, these are some very useful mathematical functions----before they are all on their own silly calculation ...

Then I refer to the basic understanding of reference, and the test of their own, on the translation into Chinese packed up.

However, if you really want to see the API documentation, I do not recommend the direct use of my this: one, I this is only a first draft, the essence version is more meaningful, now just copy it

And come, just translated words, and someone did--I this API document is actually for my tutorial synchronization out, such as the last processing of the first example,

It uses a map, if you do not know how to refer to my document.

In addition, I also found a person's personal website, which has a lot of translated API, you can go to see:

http://hiprocessing.net/

But this site also has some bad places-first, pretending to be the official processing Chinese station, also provides the download;

Second, the level of translation is limited, but also not worthy of the picture (how to feel that I ... T_T)

There are also some suitable for learning processing website, I will say next time.

Everybody look first.

001
-------------------------------------------------------------------------------------------------------------
Map ()
-------------------------------------------------------------------------------------------------------------
Case

Size (200, 200);
float value = 25;
float m = map (value, 0, 0, width);
Ellipse (M, 200, 10, 10);
void Setup () {
Size (200, 200);
Nostroke ();
}

-------------

float value = 110;
float m = map (value, 0, 100,-20,-10);
println (m); Prints "-9.0"

-------------

void Setup () {
Size (200, 200);
Nostroke ();
}

void Draw () {
Background (204);
FLOAT x1 = Map (mousex, 0, Width, 50, 150);
Ellipse (x1, 75, 50, 50);
float x2 = map (mousex, 0, width, 0, 200);
Ellipse (x2, 125, 50, 50);
}

-------------------------------------------------------------------------------------------------------------
Describe

A function that maps a number from one range to another.

In the first example above, the range of 25 from 0 to 100 is converted to a range of 0 to width (screen width: 200).

As shown in the second example, numbers that go beyond the original specified range are not limited by the maximum minimum value, because values that are out of bounds are common and useful.

-------------------------------------------------------------------------------------------------------------
Grammar

Map (VALUE,START1,STOP1,START2,STOP2)

-------------------------------------------------------------------------------------------------------------
Parameters

Valuefloat: The value to be converted
Start1float: The lower limit of the current range
Stop1float: Upper limit of current range
Start2float: Lower limit of target range
Stop2float: Upper limit of target range
-------------------------------------------------------------------------------------------------------------
return value

Float

-------------------------------------------------------------------------------------------------------------
Related

Norm ()
Lerp ()

-------------------------------------------------------------------------------------------------------------


002
-------------------------------------------------------------------------------------------------------------
Table
-------------------------------------------------------------------------------------------------------------
Case


Table table;

void Setup () {

Table = new Table ();

Table.addcolumn ("id");
Table.addcolumn ("species");
Table.addcolumn ("name");

TableRow NewRow = Table.addrow ();
Newrow.setint ("id", Table.lastrowindex ());
newrow.setstring ("Species", "Panthera leo");
Newrow.setstring ("name", "Lion");

Savetable (table, "data/new.csv");
}

This program creates a table called "New.csv" with the following content:
Id,species,name
0,panthera leo,lion

-------------------------------------------------------------------------------------------------------------

Describe

The Table object, like a traditional table, stores data through multiple rows and columns. Where the data can be generated dynamically,
It can also be an existing data. As shown in the previous case, the Table object can also be stored on the hard disk as permanent data.


-------------------------------------------------------------------------------------------------------------

Method

AddColumn () Add a new column to the table
Removecolumn () Delete a column in the form
getColumnCount () Gets the number of table columns
GetRowCount () Gets the number of table rows
Clearrows () removes data from all rows
AddRow () Add a new line to the table
Removerow () Delete a row in the table
GetRow () Get a row in the table
Rows () Gets many rows in the table
GetInt () Gets an integer from a specific position in the table
Setint () stores an integer in a specific position in a table
GetFloat () gets a floating-point number from a specific position in the table
SetFloat () stores a floating-point number in a specific position in a table
GetString () Gets a string from a specific position in the table
SetString () stores a string at a specific location in a table
Getstringcolumn () Get all values for a column
FindRow () finds a row with a specific value
FindRows () finds all rows with a specific value
Matchrow () Gets a row that satisfies a particular expression
Matchrows () gets all rows that satisfy a particular expression
Removetokens () Remove the word from the table
Trim () to remove a blank value from a value


-------------------------------------------------------------------------------------------------------------

constructor function

Table ()
Table (rows)

-------------------------------------------------------------------------------------------------------------

Related

Loadtable ()
Savetable ()
TableRow

-------------------------------------------------------------------------------------------------------------

003
-------------------------------------------------------------------------------------------------------------
Loadtable ()
-------------------------------------------------------------------------------------------------------------

Case

The mammals.csv to be used in this program is a short CSV file
It must be included in the "Data" folder or the same path as the source file
Its content is as follows
//
Id,species,name
0,capra hircus,goat
1,panthera Pardus,leopard
2,equus Zebra,zebra

Table table;

void Setup () {

Table = loadtable ("Mammals.csv", "header");

println (Table.getrowcount () + "Total rows in table");

For (TableRow row:table.rows ()) {

int id = row.getint ("id");
String species = row.getstring ("species");
String name = row.getstring ("name");

println (name + "(" + Species + ") has a ID of" + ID ");
}

}

Program output:
3 Total rows in table
Goat (Capra hircus) have an ID of 0
Leopard (Panthera pardus) have an ID of 1
Zebra (Equus Zebra) has an ID of 2

-------------------------------------------------------------------------------------------------------------

Describe

Reads the content from the specified file path or URL and creates a Table object with its values. If this file is specified,
Then it must be in the "Data" folder (or set up a good location), the file path can also use the URL to refer to the network
On the file.

By default, the Table object reads data using the comma-delimited format (comma-separated version,csv).
If you want to use a space-delimited data, use the TSV format (tab-separated VERSION,TSV) and declare it on optional parameters
(may not be declared or used)

If the file contains a header row, use "header" on the alternate parameter. If there is no header line in the file, ignore this parameter.

When you need to declare both the file format and the header line, you need to separate the optional arguments with commas, such as:
Loadtable ("Data.csv", "HEADER,TSV")

All files are read and stored by the processing API for UTF-8 encoding.

-------------------------------------------------------------------------------------------------------------

Grammar

loadtable (filename)
loadtable (filename, options)


-------------------------------------------------------------------------------------------------------------

Parameters

Filenamestring Type: File path name or URL

-------------------------------------------------------------------------------------------------------------

return value

Table

-------------------------------------------------------------------------------------------------------------

Related

Table
Savetable ()
Loadbytes ()
Loadstrings ()
LoadXML ()

-------------------------------------------------------------------------------------------------------------

004
-------------------------------------------------------------------------------------------------------------
Norm ()
-------------------------------------------------------------------------------------------------------------

Case

float value = 20;
float n = norm (value, 0, 50);
println (n); Print "0.4"

-------------

Float value =-10;
float n = norm (value, 0, 100);
println (n); Print "-0.1"

-------------------------------------------------------------------------------------------------------------

Describe

Map a number from a range to a range of 0-1 to standardize it.
In actual use and map (vale,low,high,0,1) exactly the same, and the same as map, the value of out of bounds will not be truncated,
Because many times those numbers are still useful.

-------------------------------------------------------------------------------------------------------------

Grammar

Norm (value, start, stop)

-------------------------------------------------------------------------------------------------------------

Parameters

Valuefloat:the incoming value to be converted
Startfloat:lower bound of the value ' s current range
Stopfloat:upper bound of the value ' s current range

-------------------------------------------------------------------------------------------------------------

return value

Float

-------------------------------------------------------------------------------------------------------------

Related

Map ()
Lerp ()

-------------------------------------------------------------------------------------------------------------


005
-------------------------------------------------------------------------------------------------------------
Lerp ()
-------------------------------------------------------------------------------------------------------------

Case

float a = 20;
float B = 80;
float C = Lerp (A, B,. 2);
Float d = Lerp (A, B,. 5);
float E = Lerp (A, B,. 8);
Beginshape (POINTS);
Vertex (A, 50);
Vertex (b, 50);
Vertex (c, 50);
Vertex (d, 50);
Vertex (E, 50);
Endshape ();

-------------

int x1 = 15;
int y1 = 10;
int x2 = 80;
int y2 = 90;
Line (x1, y1, x2, y2);
for (int i = 0; I <=; i++) {
float x = lerp (x1, x2, i/10.0) + 10;
Float y = lerp (y1, y2, i/10.0);
Point (x, y);
}


-------------------------------------------------------------------------------------------------------------

Describe

You can calculate a value that is at a special scale between two numbers. Where the Amt parameter is proportional, between 0 and 1,
0.1 is the distance of One-tenth, 0.5 is half. The Lerp () function calculates the easing on a line
Or it is convenient to draw a line made of dots.

-------------------------------------------------------------------------------------------------------------

Grammar

Lerp (Start, Stop, AMT)

-------------------------------------------------------------------------------------------------------------

Parameters

Startfloat: Start value
Stopfloat: End Value
amtfloat:0.0 to 1.0 (actually no value range limit)

-------------------------------------------------------------------------------------------------------------

Related

Curvepoint ()
Bezierpoint ()
Lerp ()
Lerpcolor ()

-------------------------------------------------------------------------------------------------------------

Day 11th -2015-3-27-processing Tutorial-api-First lecture-map (), table,loadtable (), Norm (), lerp ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.