首页 > 文档 > createShape()创建形状函数
2017
07-12

createShape()创建形状函数

createShape()

Name

名称

createShape()

创建形状函数

Examples

例子

PShape square; // The PShape object

void setup() {

size(100, 100);

// Creating the PShape as a square. The

// numeric arguments are similar to rect().

square = createShape(RECT, 0, 0, 50, 50);

square.setFill(color(0, 0, 255));

square.setStroke(false);

}

void draw() {

shape(square, 25, 25);

}

createShape()创建形状函数 - 第1张  | Processing编程艺术

PShape s; // The PShape object

void setup() {

size(100, 100);

// Creating a custom PShape as a square, by

// specifying a series of vertices.

s = createShape();

s.beginShape();

s.fill(0, 0, 255);

s.noStroke();

s.vertex(0, 0);

s.vertex(0, 50);

s.vertex(50, 50);

s.vertex(50, 0);

s.endShape(CLOSE);

}

void draw() {

shape(s, 25, 25);

}

createShape()创建形状函数 - 第2张  | Processing编程艺术

PShape s;

void setup() {

size(100, 100, P2D);

s = createShape();

s.beginShape(TRIANGLE_STRIP);

s.vertex(30, 75);

s.vertex(40, 20);

s.vertex(50, 75);

s.vertex(60, 20);

s.vertex(70, 75);

s.vertex(80, 20);

s.vertex(90, 75);

s.endShape();

}

void draw() {

shape(s, 0, 0);

}

createShape()创建形状函数 - 第3张  | Processing编程艺术

PShape alien, head, body;

void setup() {

size(100, 100);

// Create the shape group

alien = createShape(GROUP);

// Make two shapes

head = createShape(ELLIPSE, -25, 0, 50, 50);

head.setFill(color(255));

body = createShape(RECT, -25, 45, 50, 40);

body.setFill(color(0));

// Add the two “child” shapes to the parent group

alien.addChild(body);

alien.addChild(head);

}

void draw() {

background(204);

translate(50, 15);

shape(alien); // Draw the group

}

Description

描述

The createShape() function is used to define a new shape. Once created, this shape can be drawn with the shape() function. The basic way to use the function defines new primitive shapes. One of the following parameters are used as the first parameter: ELLIPSE, RECT, ARC, TRIANGLE, SPHERE, BOX,QUAD, or LINE. The parameters for each of these different shapes are the same as their corresponding functions: ellipse(), rect(), arc(), triangle(), sphere(), box(), and line(). The first example above clarifies how this works.

createShape()函数用于创建一个新的形状。一旦创建,这个形状就可以用shape()函数进行绘制(显示)。使用新的函数的基本方法是定义一个新的原始形状。可以使用以下参数作为第一个参数:ELLIPSE(椭圆), RECT(矩形), ARC(圆弧), TRIANGLE(三角形), SPHERE(球), BOX(盒子),QUAD(正方形), 或者 LINE(线)。这些不同形状的参数与它们对应的函数相匹配:ellipse(), rect(), arc(), triangle(), sphere(), box(), and line()。上面的第一个例证明了这一点。


Custom, unique shapes can be made by using
 createShape() without a parameter. After the shapes started, the drawing attributes and geometry can be set directly to the shape within the beginShape() and endShape() methods. See the second example above for specifics, and the reference for beginShape() for all of its options.

可以通过createShape()自定义形状而不需要设置第一个参数。在创建形状后,可以在beginShape()和endShape()方法中直接设置绘图属性和几何图形。请参阅上面的第二个示例,并参考beginShape()方法的使用。

The createShape() function can also be used to make a complex shape made of other shapes. This is called a “group” and it’s created by using the parameter GROUP as the first parameter. See the fourth example above to see how it works.

createShape()函数还可以用于创造由其他形状构成的复杂形状。这被称为”组”,它是通过使用参数组作为第一个参数来创建的。请看上面的第四个例子,看看它是如何工作的。

After using createShape(), stroke and fill color can be set by calling methods like setFill() and setStroke(), as seen in the examples above. The complete list of methods and fields for the PShape class are in the Processing Javadoc.

使用createShape()创建图形后,描边和填充颜色可以通过setStroke()和setFill()来调用设置,如上面的示例所示。PShape类的方法和字段的完整列表在Processing Javadoc中。

Syntax

语法

createShape()

createShape(type)

createShape(kind, p)

Parameters

参数

Kind

形状类型

int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE
P

参数

float[]: parameters that match the kind of shape

参数需要与对应的形状匹配

Returns

返回值

PShape


最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。