Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/content/reference/zh-Hans/p5/createAudio.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: createAudio
module: 文档对象模型
submodule: 文档对象模型
file: src/dom/dom.js
description: >
<p>创建一个用于简单音频播放的隐藏<code>&lt;audio&gt;</code>元素。</p>

<p><code>createAudio()</code>返回一个新的<a href="#/p5.MediaElement">p5.MediaElement</a>对象。</p>

<p>第一个参数<code>src</code>是音频的路径。如果传递了单个字符串,如<code>'assets/video.mp4'</code>,则加载单个音频。字符串数组可用于以不同格式加载同一音频。例如,<code>['assets/video.mp4', 'assets/video.ogv', 'assets/video.webm']</code>。这对于确保音频能够在不同的浏览器中播放很有用,因为不同的浏览器具有不同的功能。有关支持的格式的更多信息,请参见<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats" target="_blank">MDN</a>。</p>

<p>第二个参数<code>callback</code>是可选的。它是一旦音频准备好播放就会调用的函数。</p>
line: 2194
isConstructor: false
itemtype: method
example:
- |-

<div class='notest'>
<code>
function setup() {
noCanvas();

// Load the audio.
let beat = createAudio('/assets/beat.mp3');

// Show the default audio controls.
beat.showControls();

describe('An audio beat plays when the user double-clicks the square.');
}
</code>
</div>
class: p5
params:
- name: src
description: |
<p>音频文件的路径,或者为了支持不同浏览器的多个路径数组。</p>
type: '字符串|字符串[]'
optional: true
- name: callback
description: |
<p>一旦音频准备好播放即调用的函数。</p>
type: 函数
optional: true
return:
description: 新的<a href="#/p5.MediaElement">p5.MediaElement</a>对象。
type: p5.MediaElement
chainable: false
---


# createAudio
171 changes: 171 additions & 0 deletions src/content/reference/zh-Hans/p5/createCapture.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
title: createCapture
module: 文档对象模型
submodule: 文档对象模型
file: src/dom/dom.js
description: >
<p>创建一个 <code>&lt;video&gt;</code> 元素,用于“捕获”来自

网络摄像头和麦克风的音频/视频流。</p>

<p><code>createCapture()</code> 返回一个新的

<a href="#/p5.MediaElement">p5.MediaElement</a> 对象。视频默认显示,

可以通过调用 <code>capture.hide()</code> 来隐藏,并使用 <a href="./image">image()</a> 绘制到

画布上。</p>

<p>第一个参数,<code>type</code>,是可选的。它设置要使用的捕获类型。

默认情况下,<code>createCapture()</code> 捕获音频和视频。
如果传入 <code>VIDEO</code>,

如 <code>createCapture(VIDEO)</code>,则只捕获视频。

如果传入 <code>AUDIO</code>,如 <code>createCapture(AUDIO)</code>,则只捕获

音频。也可以传入一个约束对象来自定义流。

查看 <a
href="http://w3c.github.io/mediacapture-main/getusermedia.html#media-track-constraints"
target="_blank">

W3C 文档</a> 了解可能的属性。不同的浏览器支持

不同的属性。</p>

<p>'flipped' 属性是一个可选属性,可以设置为
<code>{flipped:true}</code>

来镜像视频输出。如果为 true,则意味着视频将被

镜像或翻转,如果没有提及,则默认为 <code>false</code>。</p>

<p>第二个参数,<code>callback</code>,是可选的。它是一个准备好使用时调用的函数。回调函数应该有一个

参数,<code>stream</code>,是一个

<a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream"
target="_blank">MediaStream</a> 对象。</p>

<p>注意:<code>createCapture()</code> 只在本地运行草图或使用 HTTPS 时有效。了解更多

<a
href="http://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https"
target="_blank">这里</a>

和 <a
href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia"
target="_blank">这里</a>。</p>
line: 2276
isConstructor: false
itemtype: method
example:
- |-

<div class='notest'>
<code>
function setup() {
noCanvas();

// Create the video capture.
createCapture(VIDEO);

describe('A video stream from the webcam.');
}
</code>
</div>

<div class='notest'>
<code>
let capture;

function setup() {
createCanvas(100, 100);

// Create the video capture and hide the element.
capture = createCapture(VIDEO);
capture.hide();

describe('A video stream from the webcam with inverted colors.');
}

function draw() {
// Draw the video capture within the canvas.
image(capture, 0, 0, width, width * capture.height / capture.width);

// Invert the colors in the stream.
filter(INVERT);
}
</code>
</div>
<div class='notest'>
<code>
let capture;

function setup() {
createCanvas(100, 100);

// Create the video capture with mirrored output.
capture = createCapture(VIDEO,{ flipped:true });
capture.size(100,100);

describe('A video stream from the webcam with flipped or mirrored output.');
}

</code>
</div>

<div class='notest norender'>
<code>
function setup() {
createCanvas(480, 120);

// Create a constraints object.
let constraints = {
video: {
mandatory: {
minWidth: 1280,
minHeight: 720
},
optional: [{ maxFrameRate: 10 }]
},
audio: false
};

// Create the video capture.
createCapture(constraints);

describe('A video stream from the webcam.');
}
</code>
</div>
class: p5
params:
- name: type
description: |
<p>捕获的类型,可以是 AUDIO 或 VIDEO,
或一个约束对象。默认情况下,视频和音频
流都被捕获。</p>
type: 字符串|常数|对象
optional: true
- name: flipped
description: >
<p>翻转捕获的视频并镜像输出,
<code>{flipped:true}</code>。默认情况下为 false。</p>
type: 对象
optional: true
- name: callback
description: |
<p>流加载完成后调用的函数。</p>
type: 函数
optional: true
return:
description: 新的 <a href="#/p5.MediaElement">p5.MediaElement</a> 对象。
type: p5.MediaElement
chainable: false
---


# createCapture
115 changes: 115 additions & 0 deletions src/content/reference/zh-Hans/p5/createCheckbox.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: createCheckbox
module: 文档对象模型
submodule: 文档对象模型
file: src/dom/dom.js
description: >
<p>创建一个复选框<code>&lt;input&gt;&lt;/input&gt;</code>元素。</p>

<p>复选框扩展了<a href="#/p5.Element">p5.Element</a>类,增加了一个<code>checked()</code>方法。调用<code>myBox.checked()</code>如果复选框被选中则返回<code>true</code>,否则返回<code>false</code>。</p>

<p>第一个参数,<code>label</code>,是可选的。它是一个字符串,用于设置显示在复选框旁边的标签。</p>

<p>第二个参数,<code>value</code>,也是可选的。它是一个布尔值,用于设置复选框的值。</p>
line: 1007
isConstructor: false
itemtype: method
example:
- |-

<div>
<code>
let checkbox;

function setup() {
createCanvas(100, 100);

// Create a checkbox and place it beneath the canvas.
checkbox = createCheckbox();
checkbox.position(0, 100);

describe('A black square with a checkbox beneath it. The square turns white when the box is checked.');
}

function draw() {
// Use the checkbox to set the background color.
if (checkbox.checked()) {
background(255);
} else {
background(0);
}
}
</code>
</div>

<div>
<code>
let checkbox;

function setup() {
createCanvas(100, 100);

// Create a checkbox and place it beneath the canvas.
// Label the checkbox "white".
checkbox = createCheckbox(' white');
checkbox.position(0, 100);

describe('A black square with a checkbox labeled "white" beneath it. The square turns white when the box is checked.');
}

function draw() {
// Use the checkbox to set the background color.
if (checkbox.checked()) {
background(255);
} else {
background(0);
}
}
</code>
</div>

<div>
<code>
let checkbox;

function setup() {
createCanvas(100, 100);

// Create a checkbox and place it beneath the canvas.
// Label the checkbox "white" and set its value to true.
checkbox = createCheckbox(' white', true);
checkbox.position(0, 100);

describe('A white square with a checkbox labeled "white" beneath it. The square turns black when the box is unchecked.');
}

function draw() {
// Use the checkbox to set the background color.
if (checkbox.checked()) {
background(255);
} else {
background(0);
}
}
</code>
</div>
class: p5
params:
- name: label
description: |
<p>复选框后显示的标签。</p>
type: 字符串
optional: true
- name: value
description: >
<p>复选框的值。选中为<code>true</code>,未选中为<code>false</code>。</p>
type: 布尔
optional: true
return:
description: 新的<a href="#/p5.Element">p5.Element</a>对象。
type: p5.Element
chainable: false
---


# createCheckbox
Loading