From f3da0ef272a98126b49d6038233eba58bf977985 Mon Sep 17 00:00:00 2001 From: Stalgia Grigg Date: Wed, 28 Feb 2024 14:11:10 -0800 Subject: [PATCH] Working build --- src/content/reference/en/JSON/stringify.mdx | 38 + src/content/reference/en/console/log.mdx | 63 ++ src/content/reference/en/index.mdx | 727 ++++++++++++++++++ .../reference/en/p5.Amplitude/getLevel.mdx | 58 ++ .../reference/en/p5.Amplitude/setInput.mdx | 66 ++ .../reference/en/p5.Amplitude/smooth.mdx | 22 + .../en/p5.Amplitude/toggleNormalize.mdx | 29 + src/content/reference/en/p5.AudioIn/amp.mdx | 26 + .../reference/en/p5.AudioIn/amplitude.mdx | 16 + .../reference/en/p5.AudioIn/connect.mdx | 24 + .../reference/en/p5.AudioIn/currentSource.mdx | 15 + .../reference/en/p5.AudioIn/disconnect.mdx | 18 + .../reference/en/p5.AudioIn/enabled.mdx | 17 + .../reference/en/p5.AudioIn/getLevel.mdx | 30 + .../reference/en/p5.AudioIn/getSources.mdx | 60 ++ src/content/reference/en/p5.AudioIn/input.mdx | 15 + .../reference/en/p5.AudioIn/mediaStream.mdx | 15 + .../reference/en/p5.AudioIn/output.mdx | 15 + .../reference/en/p5.AudioIn/setSource.mdx | 47 ++ src/content/reference/en/p5.AudioIn/start.mdx | 38 + src/content/reference/en/p5.AudioIn/stop.mdx | 17 + .../reference/en/p5.AudioIn/stream.mdx | 15 + .../reference/en/p5.AudioVoice/connect.mdx | 20 + .../reference/en/p5.AudioVoice/disconnect.mdx | 16 + src/content/reference/en/p5.Camera/camera.mdx | 96 +++ .../reference/en/p5.Camera/centerX.mdx | 38 + .../reference/en/p5.Camera/centerY.mdx | 38 + .../reference/en/p5.Camera/centerZ.mdx | 38 + src/content/reference/en/p5.Camera/eyeX.mdx | 38 + src/content/reference/en/p5.Camera/eyeY.mdx | 37 + src/content/reference/en/p5.Camera/eyeZ.mdx | 37 + .../reference/en/p5.Camera/frustum.mdx | 57 ++ src/content/reference/en/p5.Camera/lookAt.mdx | 73 ++ src/content/reference/en/p5.Camera/move.mdx | 76 ++ src/content/reference/en/p5.Camera/ortho.mdx | 58 ++ src/content/reference/en/p5.Camera/pan.mdx | 71 ++ .../reference/en/p5.Camera/perspective.mdx | 58 ++ src/content/reference/en/p5.Camera/set.mdx | 67 ++ .../reference/en/p5.Camera/setPosition.mdx | 68 ++ src/content/reference/en/p5.Camera/slerp.mdx | 158 ++++ src/content/reference/en/p5.Camera/tilt.mdx | 71 ++ src/content/reference/en/p5.Camera/upX.mdx | 33 + src/content/reference/en/p5.Camera/upY.mdx | 33 + src/content/reference/en/p5.Camera/upZ.mdx | 33 + .../reference/en/p5.Color/setAlpha.mdx | 41 + src/content/reference/en/p5.Color/setBlue.mdx | 41 + .../reference/en/p5.Color/setGreen.mdx | 41 + src/content/reference/en/p5.Color/setRed.mdx | 41 + .../reference/en/p5.Color/toString.mdx | 63 ++ .../reference/en/p5.Compressor/attack.mdx | 28 + .../reference/en/p5.Compressor/compressor.mdx | 19 + .../reference/en/p5.Compressor/knee.mdx | 29 + .../reference/en/p5.Compressor/process.mdx | 53 ++ .../reference/en/p5.Compressor/ratio.mdx | 28 + .../reference/en/p5.Compressor/reduction.mdx | 19 + .../reference/en/p5.Compressor/release.mdx | 27 + .../reference/en/p5.Compressor/set.mdx | 43 ++ .../reference/en/p5.Compressor/threshold.mdx | 27 + .../reference/en/p5.Convolver/addImpulse.mdx | 32 + .../en/p5.Convolver/convolverNode.mdx | 18 + .../reference/en/p5.Convolver/impulses.mdx | 18 + .../reference/en/p5.Convolver/process.mdx | 59 ++ .../en/p5.Convolver/resetImpulse.mdx | 31 + .../en/p5.Convolver/toggleImpulse.mdx | 34 + src/content/reference/en/p5.Delay/amp.mdx | 32 + src/content/reference/en/p5.Delay/connect.mdx | 20 + .../reference/en/p5.Delay/delayTime.mdx | 22 + .../reference/en/p5.Delay/disconnect.mdx | 16 + .../reference/en/p5.Delay/feedback.mdx | 30 + src/content/reference/en/p5.Delay/filter.mdx | 31 + .../reference/en/p5.Delay/leftDelay.mdx | 18 + src/content/reference/en/p5.Delay/process.mdx | 43 ++ .../reference/en/p5.Delay/rightDelay.mdx | 18 + src/content/reference/en/p5.Delay/setType.mdx | 23 + .../en/p5.Distortion/WaveShaperNode.mdx | 18 + .../reference/en/p5.Distortion/getAmount.mdx | 21 + .../en/p5.Distortion/getOversample.mdx | 19 + .../reference/en/p5.Distortion/process.mdx | 31 + .../reference/en/p5.Distortion/set.mdx | 30 + src/content/reference/en/p5.EQ/bands.mdx | 20 + src/content/reference/en/p5.EQ/process.mdx | 21 + src/content/reference/en/p5.Effect/amp.mdx | 32 + src/content/reference/en/p5.Effect/chain.mdx | 24 + .../reference/en/p5.Effect/connect.mdx | 21 + .../reference/en/p5.Effect/disconnect.mdx | 16 + src/content/reference/en/p5.Effect/drywet.mdx | 22 + .../reference/en/p5.Element/addClass.mdx | 28 + .../reference/en/p5.Element/attribute.mdx | 91 +++ .../reference/en/p5.Element/center.mdx | 35 + src/content/reference/en/p5.Element/child.mdx | 42 + src/content/reference/en/p5.Element/class.mdx | 51 ++ .../reference/en/p5.Element/doubleClicked.mdx | 73 ++ .../reference/en/p5.Element/dragLeave.mdx | 76 ++ .../reference/en/p5.Element/dragOver.mdx | 74 ++ .../reference/en/p5.Element/draggable.mdx | 64 ++ src/content/reference/en/p5.Element/drop.mdx | 140 ++++ src/content/reference/en/p5.Element/elt.mdx | 41 + .../reference/en/p5.Element/hasClass.mdx | 41 + .../reference/en/p5.Element/height.mdx | 15 + src/content/reference/en/p5.Element/hide.mdx | 37 + src/content/reference/en/p5.Element/html.mdx | 34 + src/content/reference/en/p5.Element/id.mdx | 43 ++ .../reference/en/p5.Element/mouseClicked.mdx | 75 ++ .../reference/en/p5.Element/mouseMoved.mdx | 73 ++ .../reference/en/p5.Element/mouseOut.mdx | 74 ++ .../reference/en/p5.Element/mouseOver.mdx | 74 ++ .../reference/en/p5.Element/mousePressed.mdx | 75 ++ .../reference/en/p5.Element/mouseReleased.mdx | 75 ++ .../reference/en/p5.Element/mouseWheel.mdx | 126 +++ .../reference/en/p5.Element/parent.mdx | 130 ++++ .../reference/en/p5.Element/position.mdx | 49 ++ .../reference/en/p5.Element/remove.mdx | 40 + .../en/p5.Element/removeAttribute.mdx | 54 ++ .../reference/en/p5.Element/removeClass.mdx | 37 + src/content/reference/en/p5.Element/show.mdx | 40 + src/content/reference/en/p5.Element/size.mdx | 132 ++++ src/content/reference/en/p5.Element/style.mdx | 127 +++ .../reference/en/p5.Element/toggleClass.mdx | 34 + .../reference/en/p5.Element/touchEnded.mdx | 77 ++ .../reference/en/p5.Element/touchMoved.mdx | 77 ++ .../reference/en/p5.Element/touchStarted.mdx | 75 ++ src/content/reference/en/p5.Element/value.mdx | 83 ++ src/content/reference/en/p5.Element/width.mdx | 15 + src/content/reference/en/p5.Envelope/add.mdx | 28 + .../reference/en/p5.Envelope/attackLevel.mdx | 16 + .../reference/en/p5.Envelope/attackTime.mdx | 16 + .../reference/en/p5.Envelope/decayLevel.mdx | 16 + .../reference/en/p5.Envelope/decayTime.mdx | 16 + src/content/reference/en/p5.Envelope/mult.mdx | 28 + src/content/reference/en/p5.Envelope/play.mdx | 80 ++ src/content/reference/en/p5.Envelope/ramp.mdx | 84 ++ .../reference/en/p5.Envelope/releaseLevel.mdx | 16 + .../reference/en/p5.Envelope/releaseTime.mdx | 16 + .../reference/en/p5.Envelope/scale.mdx | 40 + src/content/reference/en/p5.Envelope/set.mdx | 80 ++ .../reference/en/p5.Envelope/setADSR.mdx | 89 +++ .../reference/en/p5.Envelope/setExp.mdx | 23 + .../reference/en/p5.Envelope/setInput.mdx | 27 + .../reference/en/p5.Envelope/setRange.mdx | 62 ++ .../en/p5.Envelope/triggerAttack.mdx | 73 ++ .../en/p5.Envelope/triggerRelease.mdx | 70 ++ src/content/reference/en/p5.FFT/analyze.mdx | 92 +++ .../reference/en/p5.FFT/getCentroid.mdx | 77 ++ src/content/reference/en/p5.FFT/getEnergy.mdx | 49 ++ .../reference/en/p5.FFT/getOctaveBands.mdx | 40 + .../reference/en/p5.FFT/linAverages.mdx | 28 + .../reference/en/p5.FFT/logAverages.mdx | 29 + src/content/reference/en/p5.FFT/setInput.mdx | 23 + src/content/reference/en/p5.FFT/smooth.mdx | 22 + src/content/reference/en/p5.FFT/waveform.mdx | 38 + src/content/reference/en/p5.File/data.mdx | 50 ++ src/content/reference/en/p5.File/file.mdx | 55 ++ src/content/reference/en/p5.File/name.mdx | 46 ++ src/content/reference/en/p5.File/size.mdx | 46 ++ src/content/reference/en/p5.File/subtype.mdx | 53 ++ src/content/reference/en/p5.File/type.mdx | 53 ++ .../reference/en/p5.Filter/biquadFilter.mdx | 18 + src/content/reference/en/p5.Filter/freq.mdx | 32 + src/content/reference/en/p5.Filter/gain.mdx | 26 + .../reference/en/p5.Filter/process.mdx | 33 + src/content/reference/en/p5.Filter/res.mdx | 32 + src/content/reference/en/p5.Filter/set.mdx | 33 + .../reference/en/p5.Filter/setType.mdx | 23 + src/content/reference/en/p5.Filter/toggle.mdx | 19 + src/content/reference/en/p5.Font/font.mdx | 18 + .../reference/en/p5.Font/textBounds.mdx | 132 ++++ .../reference/en/p5.Font/textToPoints.mdx | 104 +++ .../reference/en/p5.Framebuffer/autoSized.mdx | 26 + .../reference/en/p5.Framebuffer/begin.mdx | 54 ++ .../reference/en/p5.Framebuffer/color.mdx | 49 ++ .../en/p5.Framebuffer/createCamera.mdx | 22 + .../reference/en/p5.Framebuffer/depth.mdx | 96 +++ .../reference/en/p5.Framebuffer/draw.mdx | 63 ++ .../reference/en/p5.Framebuffer/end.mdx | 20 + .../reference/en/p5.Framebuffer/get.mdx | 40 + .../en/p5.Framebuffer/pixelDensity.mdx | 27 + .../reference/en/p5.Framebuffer/pixels.mdx | 35 + .../reference/en/p5.Framebuffer/remove.mdx | 54 ++ .../reference/en/p5.Framebuffer/resize.mdx | 60 ++ src/content/reference/en/p5.Gain/amp.mdx | 32 + src/content/reference/en/p5.Gain/connect.mdx | 20 + .../reference/en/p5.Gain/disconnect.mdx | 16 + src/content/reference/en/p5.Gain/setInput.mdx | 22 + .../en/p5.Geometry/averageNormals.mdx | 17 + .../en/p5.Geometry/averagePoleNormals.mdx | 16 + .../reference/en/p5.Geometry/clearColors.mdx | 66 ++ .../reference/en/p5.Geometry/computeFaces.mdx | 16 + .../en/p5.Geometry/computeNormals.mdx | 127 +++ .../reference/en/p5.Geometry/flipU.mdx | 76 ++ .../reference/en/p5.Geometry/flipV.mdx | 76 ++ .../reference/en/p5.Geometry/normalize.mdx | 16 + .../en/p5.Graphics/createFramebuffer.mdx | 26 + .../reference/en/p5.Graphics/remove.mdx | 65 ++ .../reference/en/p5.Graphics/reset.mdx | 65 ++ src/content/reference/en/p5.Image/blend.mdx | 83 ++ src/content/reference/en/p5.Image/copy.mdx | 55 ++ src/content/reference/en/p5.Image/delay.mdx | 81 ++ src/content/reference/en/p5.Image/filter.mdx | 189 +++++ src/content/reference/en/p5.Image/get.mdx | 111 +++ .../reference/en/p5.Image/getCurrentFrame.mdx | 39 + src/content/reference/en/p5.Image/height.mdx | 38 + .../reference/en/p5.Image/loadPixels.mdx | 61 ++ src/content/reference/en/p5.Image/mask.mdx | 45 ++ .../reference/en/p5.Image/numFrames.mdx | 40 + src/content/reference/en/p5.Image/pause.mdx | 44 ++ .../reference/en/p5.Image/pixelDensity.mdx | 32 + src/content/reference/en/p5.Image/pixels.mdx | 101 +++ src/content/reference/en/p5.Image/play.mdx | 44 ++ src/content/reference/en/p5.Image/reset.mdx | 39 + src/content/reference/en/p5.Image/resize.mdx | 92 +++ src/content/reference/en/p5.Image/save.mdx | 80 ++ src/content/reference/en/p5.Image/set.mdx | 161 ++++ .../reference/en/p5.Image/setFrame.mdx | 49 ++ .../reference/en/p5.Image/updatePixels.mdx | 82 ++ src/content/reference/en/p5.Image/width.mdx | 38 + .../reference/en/p5.MediaElement/addCue.mdx | 84 ++ .../reference/en/p5.MediaElement/autoplay.mdx | 72 ++ .../en/p5.MediaElement/clearCues.mdx | 63 ++ .../reference/en/p5.MediaElement/connect.mdx | 26 + .../en/p5.MediaElement/disconnect.mdx | 18 + .../reference/en/p5.MediaElement/duration.mdx | 52 ++ .../en/p5.MediaElement/hideControls.mdx | 63 ++ .../reference/en/p5.MediaElement/loop.mdx | 63 ++ .../reference/en/p5.MediaElement/noLoop.mdx | 64 ++ .../reference/en/p5.MediaElement/onended.mdx | 76 ++ .../reference/en/p5.MediaElement/pause.mdx | 64 ++ .../reference/en/p5.MediaElement/play.mdx | 42 + .../en/p5.MediaElement/removeCue.mdx | 68 ++ .../en/p5.MediaElement/showControls.mdx | 23 + .../reference/en/p5.MediaElement/speed.mdx | 70 ++ .../reference/en/p5.MediaElement/src.mdx | 41 + .../reference/en/p5.MediaElement/stop.mdx | 62 ++ .../reference/en/p5.MediaElement/time.mdx | 89 +++ .../reference/en/p5.MediaElement/volume.mdx | 67 ++ src/content/reference/en/p5.MonoSynth/amp.mdx | 29 + .../reference/en/p5.MonoSynth/attack.mdx | 16 + .../reference/en/p5.MonoSynth/connect.mdx | 21 + .../reference/en/p5.MonoSynth/decay.mdx | 15 + .../reference/en/p5.MonoSynth/disconnect.mdx | 16 + .../reference/en/p5.MonoSynth/dispose.mdx | 16 + .../reference/en/p5.MonoSynth/play.mdx | 72 ++ .../reference/en/p5.MonoSynth/release.mdx | 15 + .../reference/en/p5.MonoSynth/setADSR.mdx | 52 ++ .../reference/en/p5.MonoSynth/sustain.mdx | 15 + .../en/p5.MonoSynth/triggerAttack.mdx | 61 ++ .../en/p5.MonoSynth/triggerRelease.mdx | 47 ++ src/content/reference/en/p5.Noise/setType.mdx | 23 + .../reference/en/p5.NumberDict/add.mdx | 37 + .../reference/en/p5.NumberDict/div.mdx | 37 + .../reference/en/p5.NumberDict/maxKey.mdx | 30 + .../reference/en/p5.NumberDict/maxValue.mdx | 30 + .../reference/en/p5.NumberDict/minKey.mdx | 30 + .../reference/en/p5.NumberDict/minValue.mdx | 30 + .../reference/en/p5.NumberDict/mult.mdx | 37 + .../reference/en/p5.NumberDict/sub.mdx | 39 + .../reference/en/p5.Oscillator/add.mdx | 28 + .../reference/en/p5.Oscillator/amp.mdx | 42 + .../reference/en/p5.Oscillator/connect.mdx | 21 + .../reference/en/p5.Oscillator/disconnect.mdx | 16 + .../reference/en/p5.Oscillator/freq.mdx | 65 ++ .../reference/en/p5.Oscillator/getAmp.mdx | 19 + .../reference/en/p5.Oscillator/getFreq.mdx | 19 + .../reference/en/p5.Oscillator/getPan.mdx | 20 + .../reference/en/p5.Oscillator/getType.mdx | 20 + .../reference/en/p5.Oscillator/mult.mdx | 28 + .../reference/en/p5.Oscillator/pan.mdx | 26 + .../reference/en/p5.Oscillator/phase.mdx | 23 + .../reference/en/p5.Oscillator/scale.mdx | 40 + .../reference/en/p5.Oscillator/setType.mdx | 21 + .../reference/en/p5.Oscillator/start.mdx | 30 + .../reference/en/p5.Oscillator/stop.mdx | 23 + .../reference/en/p5.Panner3D/maxDist.mdx | 23 + .../reference/en/p5.Panner3D/orient.mdx | 32 + .../reference/en/p5.Panner3D/orientX.mdx | 19 + .../reference/en/p5.Panner3D/orientY.mdx | 19 + .../reference/en/p5.Panner3D/orientZ.mdx | 19 + .../reference/en/p5.Panner3D/panner.mdx | 23 + .../reference/en/p5.Panner3D/positionX.mdx | 19 + .../reference/en/p5.Panner3D/positionY.mdx | 19 + .../reference/en/p5.Panner3D/positionZ.mdx | 19 + .../reference/en/p5.Panner3D/process.mdx | 21 + .../reference/en/p5.Panner3D/rollof.mdx | 24 + src/content/reference/en/p5.Panner3D/set.mdx | 32 + .../reference/en/p5.Panner3D/setFalloff.mdx | 25 + .../reference/en/p5.Part/addPhrase.mdx | 21 + src/content/reference/en/p5.Part/getBPM.mdx | 19 + .../reference/en/p5.Part/getPhrase.mdx | 21 + src/content/reference/en/p5.Part/loop.mdx | 24 + src/content/reference/en/p5.Part/noLoop.mdx | 16 + src/content/reference/en/p5.Part/onStep.mdx | 24 + src/content/reference/en/p5.Part/pause.mdx | 22 + .../reference/en/p5.Part/removePhrase.mdx | 21 + .../reference/en/p5.Part/replaceSequence.mdx | 26 + src/content/reference/en/p5.Part/setBPM.mdx | 26 + src/content/reference/en/p5.Part/start.mdx | 24 + src/content/reference/en/p5.Part/stop.mdx | 23 + .../reference/en/p5.PeakDetect/isDetected.mdx | 16 + .../reference/en/p5.PeakDetect/onPeak.mdx | 84 ++ .../reference/en/p5.PeakDetect/update.mdx | 24 + .../reference/en/p5.Phrase/sequence.mdx | 20 + .../reference/en/p5.PolySynth/AudioVoice.mdx | 17 + .../reference/en/p5.PolySynth/connect.mdx | 21 + .../reference/en/p5.PolySynth/disconnect.mdx | 16 + .../reference/en/p5.PolySynth/dispose.mdx | 16 + .../reference/en/p5.PolySynth/noteADSR.mdx | 59 ++ .../reference/en/p5.PolySynth/noteAttack.mdx | 64 ++ .../reference/en/p5.PolySynth/noteRelease.mdx | 60 ++ .../reference/en/p5.PolySynth/notes.mdx | 20 + .../reference/en/p5.PolySynth/play.mdx | 70 ++ .../reference/en/p5.PolySynth/polyvalue.mdx | 16 + .../reference/en/p5.PolySynth/setADSR.mdx | 49 ++ .../reference/en/p5.PrintWriter/clear.mdx | 44 ++ .../reference/en/p5.PrintWriter/close.mdx | 37 + .../reference/en/p5.PrintWriter/print.mdx | 56 ++ .../reference/en/p5.PrintWriter/write.mdx | 74 ++ src/content/reference/en/p5.Pulse/width.mdx | 24 + src/content/reference/en/p5.Reverb/amp.mdx | 32 + .../reference/en/p5.Reverb/connect.mdx | 20 + .../reference/en/p5.Reverb/disconnect.mdx | 16 + .../reference/en/p5.Reverb/process.mdx | 39 + src/content/reference/en/p5.Reverb/set.mdx | 35 + src/content/reference/en/p5.Score/loop.mdx | 16 + src/content/reference/en/p5.Score/noLoop.mdx | 18 + src/content/reference/en/p5.Score/pause.mdx | 16 + src/content/reference/en/p5.Score/setBPM.mdx | 25 + src/content/reference/en/p5.Score/start.mdx | 16 + src/content/reference/en/p5.Score/stop.mdx | 16 + .../reference/en/p5.Shader/copyToContext.mdx | 41 + .../reference/en/p5.Shader/setUniform.mdx | 133 ++++ .../reference/en/p5.SoundFile/addCue.mdx | 82 ++ .../reference/en/p5.SoundFile/channels.mdx | 20 + .../reference/en/p5.SoundFile/clearCues.mdx | 17 + .../reference/en/p5.SoundFile/connect.mdx | 26 + .../reference/en/p5.SoundFile/currentTime.mdx | 24 + .../reference/en/p5.SoundFile/disconnect.mdx | 16 + .../reference/en/p5.SoundFile/duration.mdx | 19 + .../reference/en/p5.SoundFile/frames.mdx | 20 + .../reference/en/p5.SoundFile/getBlob.mdx | 64 ++ .../reference/en/p5.SoundFile/getPan.mdx | 22 + .../reference/en/p5.SoundFile/getPeaks.mdx | 32 + .../reference/en/p5.SoundFile/isLoaded.mdx | 19 + .../reference/en/p5.SoundFile/isLooping.mdx | 20 + .../reference/en/p5.SoundFile/isPaused.mdx | 20 + .../reference/en/p5.SoundFile/isPlaying.mdx | 20 + .../reference/en/p5.SoundFile/jump.mdx | 34 + .../reference/en/p5.SoundFile/loop.mdx | 71 ++ .../reference/en/p5.SoundFile/onended.mdx | 26 + src/content/reference/en/p5.SoundFile/pan.mdx | 58 ++ .../reference/en/p5.SoundFile/pause.mdx | 53 ++ .../reference/en/p5.SoundFile/play.mdx | 43 ++ .../reference/en/p5.SoundFile/playMode.mdx | 56 ++ .../reference/en/p5.SoundFile/rate.mdx | 60 ++ .../reference/en/p5.SoundFile/removeCue.mdx | 22 + .../en/p5.SoundFile/reverseBuffer.mdx | 40 + .../reference/en/p5.SoundFile/sampleRate.mdx | 19 + .../reference/en/p5.SoundFile/save.mdx | 43 ++ .../reference/en/p5.SoundFile/setBuffer.mdx | 23 + .../reference/en/p5.SoundFile/setLoop.mdx | 23 + .../reference/en/p5.SoundFile/setPath.mdx | 26 + .../reference/en/p5.SoundFile/setVolume.mdx | 40 + .../reference/en/p5.SoundFile/stop.mdx | 23 + src/content/reference/en/p5.SoundLoop/bpm.mdx | 21 + .../reference/en/p5.SoundLoop/interval.mdx | 16 + .../reference/en/p5.SoundLoop/iterations.mdx | 16 + .../en/p5.SoundLoop/maxIterations.mdx | 16 + .../en/p5.SoundLoop/musicalTimeMode.mdx | 19 + .../reference/en/p5.SoundLoop/pause.mdx | 22 + .../reference/en/p5.SoundLoop/start.mdx | 22 + .../reference/en/p5.SoundLoop/stop.mdx | 22 + .../reference/en/p5.SoundLoop/syncedStart.mdx | 34 + .../en/p5.SoundLoop/timeSignature.mdx | 16 + .../reference/en/p5.SoundRecorder/record.mdx | 38 + .../en/p5.SoundRecorder/setInput.mdx | 25 + .../reference/en/p5.SoundRecorder/stop.mdx | 19 + .../reference/en/p5.Table/addColumn.mdx | 65 ++ src/content/reference/en/p5.Table/addRow.mdx | 74 ++ .../reference/en/p5.Table/clearRows.mdx | 46 ++ src/content/reference/en/p5.Table/columns.mdx | 48 ++ src/content/reference/en/p5.Table/findRow.mdx | 63 ++ .../reference/en/p5.Table/findRows.mdx | 68 ++ src/content/reference/en/p5.Table/get.mdx | 61 ++ .../reference/en/p5.Table/getArray.mdx | 49 ++ .../reference/en/p5.Table/getColumn.mdx | 54 ++ .../reference/en/p5.Table/getColumnCount.mdx | 47 ++ src/content/reference/en/p5.Table/getNum.mdx | 59 ++ .../reference/en/p5.Table/getObject.mdx | 59 ++ src/content/reference/en/p5.Table/getRow.mdx | 60 ++ .../reference/en/p5.Table/getRowCount.mdx | 47 ++ src/content/reference/en/p5.Table/getRows.mdx | 58 ++ .../reference/en/p5.Table/getString.mdx | 66 ++ .../reference/en/p5.Table/matchRow.mdx | 62 ++ .../reference/en/p5.Table/matchRows.mdx | 72 ++ .../reference/en/p5.Table/removeColumn.mdx | 58 ++ .../reference/en/p5.Table/removeRow.mdx | 55 ++ .../reference/en/p5.Table/removeTokens.mdx | 56 ++ src/content/reference/en/p5.Table/rows.mdx | 20 + src/content/reference/en/p5.Table/set.mdx | 66 ++ src/content/reference/en/p5.Table/setNum.mdx | 63 ++ .../reference/en/p5.Table/setString.mdx | 63 ++ src/content/reference/en/p5.Table/trim.mdx | 52 ++ src/content/reference/en/p5.TableRow/get.mdx | 57 ++ .../reference/en/p5.TableRow/getNum.mdx | 59 ++ .../reference/en/p5.TableRow/getString.mdx | 61 ++ src/content/reference/en/p5.TableRow/set.mdx | 58 ++ .../reference/en/p5.TableRow/setNum.mdx | 58 ++ .../reference/en/p5.TableRow/setString.mdx | 59 ++ .../reference/en/p5.TypedDict/clear.mdx | 29 + .../reference/en/p5.TypedDict/create.mdx | 28 + src/content/reference/en/p5.TypedDict/get.mdx | 35 + .../reference/en/p5.TypedDict/hasKey.mdx | 35 + .../reference/en/p5.TypedDict/print.mdx | 30 + .../reference/en/p5.TypedDict/remove.mdx | 36 + .../reference/en/p5.TypedDict/saveJSON.mdx | 39 + .../reference/en/p5.TypedDict/saveTable.mdx | 39 + src/content/reference/en/p5.TypedDict/set.mdx | 35 + .../reference/en/p5.TypedDict/size.mdx | 32 + src/content/reference/en/p5.Vector/add.mdx | 151 ++++ .../reference/en/p5.Vector/angleBetween.mdx | 117 +++ src/content/reference/en/p5.Vector/array.mdx | 29 + src/content/reference/en/p5.Vector/copy.mdx | 33 + src/content/reference/en/p5.Vector/cross.mdx | 52 ++ src/content/reference/en/p5.Vector/dist.mdx | 89 +++ src/content/reference/en/p5.Vector/div.mdx | 199 +++++ src/content/reference/en/p5.Vector/dot.mdx | 99 +++ src/content/reference/en/p5.Vector/equals.mdx | 80 ++ .../reference/en/p5.Vector/fromAngle.mdx | 69 ++ .../reference/en/p5.Vector/fromAngles.mdx | 69 ++ .../reference/en/p5.Vector/heading.mdx | 95 +++ src/content/reference/en/p5.Vector/lerp.mdx | 97 +++ src/content/reference/en/p5.Vector/limit.mdx | 100 +++ src/content/reference/en/p5.Vector/mag.mdx | 42 + src/content/reference/en/p5.Vector/magSq.mdx | 42 + src/content/reference/en/p5.Vector/mult.mdx | 199 +++++ .../reference/en/p5.Vector/normalize.mdx | 110 +++ .../reference/en/p5.Vector/random2D.mdx | 61 ++ .../reference/en/p5.Vector/random3D.mdx | 30 + .../reference/en/p5.Vector/reflect.mdx | 85 ++ src/content/reference/en/p5.Vector/rem.mdx | 72 ++ src/content/reference/en/p5.Vector/rotate.mdx | 117 +++ src/content/reference/en/p5.Vector/set.mdx | 50 ++ .../reference/en/p5.Vector/setHeading.mdx | 85 ++ src/content/reference/en/p5.Vector/setMag.mdx | 80 ++ src/content/reference/en/p5.Vector/slerp.mdx | 125 +++ src/content/reference/en/p5.Vector/sub.mdx | 151 ++++ .../reference/en/p5.Vector/toString.mdx | 32 + src/content/reference/en/p5.Vector/x.mdx | 16 + src/content/reference/en/p5.Vector/y.mdx | 16 + src/content/reference/en/p5.Vector/z.mdx | 16 + src/content/reference/en/p5.XML/addChild.mdx | 66 ++ .../reference/en/p5.XML/getAttributeCount.mdx | 48 ++ src/content/reference/en/p5.XML/getChild.mdx | 69 ++ .../reference/en/p5.XML/getChildren.mdx | 63 ++ .../reference/en/p5.XML/getContent.mdx | 54 ++ src/content/reference/en/p5.XML/getName.mdx | 46 ++ src/content/reference/en/p5.XML/getNum.mdx | 60 ++ src/content/reference/en/p5.XML/getParent.mdx | 49 ++ src/content/reference/en/p5.XML/getString.mdx | 60 ++ .../reference/en/p5.XML/hasAttribute.mdx | 54 ++ .../reference/en/p5.XML/hasChildren.mdx | 47 ++ .../reference/en/p5.XML/listAttributes.mdx | 48 ++ .../reference/en/p5.XML/listChildren.mdx | 51 ++ .../reference/en/p5.XML/removeChild.mdx | 72 ++ src/content/reference/en/p5.XML/serialize.mdx | 41 + .../reference/en/p5.XML/setAttribute.mdx | 57 ++ .../reference/en/p5.XML/setContent.mdx | 52 ++ src/content/reference/en/p5.XML/setName.mdx | 51 ++ .../reference/en/p5.sound/p5.Amplitude.mdx | 51 ++ .../reference/en/p5.sound/p5.AudioIn.mdx | 112 +++ .../reference/en/p5.sound/p5.AudioVoice.mdx | 25 + .../reference/en/p5.sound/p5.BandPass.mdx | 17 + .../reference/en/p5.sound/p5.Compressor.mdx | 80 ++ .../reference/en/p5.sound/p5.Convolver.mdx | 90 +++ .../reference/en/p5.sound/p5.Delay.mdx | 98 +++ .../reference/en/p5.sound/p5.Distortion.mdx | 69 ++ src/content/reference/en/p5.sound/p5.EQ.mdx | 63 ++ .../reference/en/p5.sound/p5.Effect.mdx | 81 ++ .../reference/en/p5.sound/p5.Envelope.mdx | 160 ++++ src/content/reference/en/p5.sound/p5.FFT.mdx | 148 ++++ .../reference/en/p5.sound/p5.Filter.mdx | 101 +++ src/content/reference/en/p5.sound/p5.Gain.mdx | 32 + .../reference/en/p5.sound/p5.HighPass.mdx | 17 + .../reference/en/p5.sound/p5.LowPass.mdx | 17 + .../reference/en/p5.sound/p5.MonoSynth.mdx | 66 ++ .../reference/en/p5.sound/p5.Noise.mdx | 27 + .../reference/en/p5.sound/p5.OnsetDetect.mdx | 32 + .../reference/en/p5.sound/p5.Oscillator.mdx | 121 +++ .../reference/en/p5.sound/p5.Panner3D.mdx | 83 ++ src/content/reference/en/p5.sound/p5.Part.mdx | 88 +++ .../reference/en/p5.sound/p5.PeakDetect.mdx | 112 +++ .../reference/en/p5.sound/p5.Phrase.mdx | 57 ++ .../reference/en/p5.sound/p5.PolySynth.mdx | 103 +++ .../reference/en/p5.sound/p5.Pulse.mdx | 38 + .../reference/en/p5.sound/p5.Reverb.mdx | 59 ++ .../reference/en/p5.sound/p5.SawOsc.mdx | 25 + .../reference/en/p5.sound/p5.Score.mdx | 51 ++ .../reference/en/p5.sound/p5.SinOsc.mdx | 25 + .../reference/en/p5.sound/p5.SoundFile.mdx | 276 +++++++ .../reference/en/p5.sound/p5.SoundLoop.mdx | 83 ++ .../en/p5.sound/p5.SoundRecorder.mdx | 44 ++ .../reference/en/p5.sound/p5.SqrOsc.mdx | 25 + .../reference/en/p5.sound/p5.TriOsc.mdx | 25 + src/content/reference/en/p5/>.mdx | 35 + src/content/reference/en/p5/>=.mdx | 34 + src/content/reference/en/p5/<.mdx | 34 + src/content/reference/en/p5/<=.mdx | 34 + src/content/reference/en/p5/===.mdx | 49 ++ src/content/reference/en/p5/ADD.mdx | 15 + src/content/reference/en/p5/ALT.mdx | 15 + src/content/reference/en/p5/ARROW.mdx | 15 + src/content/reference/en/p5/AUTO.mdx | 22 + src/content/reference/en/p5/AXES.mdx | 15 + src/content/reference/en/p5/BACKSPACE.mdx | 15 + src/content/reference/en/p5/BASELINE.mdx | 15 + src/content/reference/en/p5/BEVEL.mdx | 15 + src/content/reference/en/p5/BLEND.mdx | 81 ++ src/content/reference/en/p5/BLUR.mdx | 15 + src/content/reference/en/p5/BOLD.mdx | 15 + src/content/reference/en/p5/BOLDITALIC.mdx | 15 + src/content/reference/en/p5/BOTTOM.mdx | 15 + src/content/reference/en/p5/BURN.mdx | 15 + src/content/reference/en/p5/CENTER.mdx | 15 + src/content/reference/en/p5/CHAR.mdx | 32 + src/content/reference/en/p5/CHORD.mdx | 15 + src/content/reference/en/p5/CLAMP.mdx | 15 + src/content/reference/en/p5/CLOSE.mdx | 15 + src/content/reference/en/p5/CONTAIN.mdx | 15 + src/content/reference/en/p5/CONTROL.mdx | 15 + src/content/reference/en/p5/CORNER.mdx | 15 + src/content/reference/en/p5/CORNERS.mdx | 15 + src/content/reference/en/p5/COVER.mdx | 15 + src/content/reference/en/p5/CROSS.mdx | 15 + src/content/reference/en/p5/DARKEST.mdx | 15 + src/content/reference/en/p5/DEGREES.mdx | 41 + src/content/reference/en/p5/DELETE.mdx | 15 + src/content/reference/en/p5/DIFFERENCE.mdx | 15 + src/content/reference/en/p5/DILATE.mdx | 15 + src/content/reference/en/p5/DODGE.mdx | 15 + src/content/reference/en/p5/DOWN_ARROW.mdx | 15 + src/content/reference/en/p5/ENTER.mdx | 15 + src/content/reference/en/p5/ERODE.mdx | 15 + src/content/reference/en/p5/ESCAPE.mdx | 15 + src/content/reference/en/p5/EXCLUSION.mdx | 15 + src/content/reference/en/p5/FALLBACK.mdx | 15 + src/content/reference/en/p5/FLAT.mdx | 15 + src/content/reference/en/p5/FLOAT.mdx | 43 ++ src/content/reference/en/p5/GRAY.mdx | 15 + src/content/reference/en/p5/GRID.mdx | 15 + src/content/reference/en/p5/HALF_FLOAT.mdx | 15 + src/content/reference/en/p5/HALF_PI.mdx | 30 + src/content/reference/en/p5/HAND.mdx | 15 + src/content/reference/en/p5/HARD_LIGHT.mdx | 15 + src/content/reference/en/p5/HSB.mdx | 21 + src/content/reference/en/p5/HSL.mdx | 15 + src/content/reference/en/p5/IMAGE.mdx | 191 +++++ src/content/reference/en/p5/IMMEDIATE.mdx | 15 + src/content/reference/en/p5/INVERT.mdx | 15 + src/content/reference/en/p5/ITALIC.mdx | 15 + src/content/reference/en/p5/LABEL.mdx | 15 + src/content/reference/en/p5/LANDSCAPE.mdx | 15 + src/content/reference/en/p5/LEFT.mdx | 15 + src/content/reference/en/p5/LEFT_ARROW.mdx | 15 + src/content/reference/en/p5/LIGHTEST.mdx | 15 + src/content/reference/en/p5/LINEAR.mdx | 15 + src/content/reference/en/p5/LINES.mdx | 15 + src/content/reference/en/p5/LINE_LOOP.mdx | 15 + src/content/reference/en/p5/LINE_STRIP.mdx | 15 + src/content/reference/en/p5/MIRROR.mdx | 15 + src/content/reference/en/p5/MITER.mdx | 15 + src/content/reference/en/p5/MOVE.mdx | 15 + src/content/reference/en/p5/MULTIPLY.mdx | 15 + src/content/reference/en/p5/NEAREST.mdx | 15 + src/content/reference/en/p5/OPAQUE.mdx | 15 + src/content/reference/en/p5/OPEN.mdx | 15 + src/content/reference/en/p5/OPTION.mdx | 15 + src/content/reference/en/p5/OVERLAY.mdx | 15 + src/content/reference/en/p5/P2D.mdx | 16 + src/content/reference/en/p5/PI.mdx | 30 + src/content/reference/en/p5/PIE.mdx | 15 + src/content/reference/en/p5/POINTS.mdx | 15 + src/content/reference/en/p5/PORTRAIT.mdx | 15 + src/content/reference/en/p5/POSTERIZE.mdx | 15 + src/content/reference/en/p5/PROJECT.mdx | 15 + src/content/reference/en/p5/QUADRATIC.mdx | 15 + src/content/reference/en/p5/QUADS.mdx | 15 + src/content/reference/en/p5/QUAD_STRIP.mdx | 15 + src/content/reference/en/p5/QUARTER_PI.mdx | 26 + src/content/reference/en/p5/RADIANS.mdx | 41 + src/content/reference/en/p5/RADIUS.mdx | 15 + src/content/reference/en/p5/REMOVE.mdx | 35 + src/content/reference/en/p5/REPEAT.mdx | 15 + src/content/reference/en/p5/REPLACE.mdx | 15 + src/content/reference/en/p5/RETURN.mdx | 34 + src/content/reference/en/p5/RGB.mdx | 15 + src/content/reference/en/p5/RGBA.mdx | 15 + src/content/reference/en/p5/RIGHT.mdx | 15 + src/content/reference/en/p5/RIGHT_ARROW.mdx | 15 + src/content/reference/en/p5/ROUND.mdx | 52 ++ src/content/reference/en/p5/SCREEN.mdx | 15 + src/content/reference/en/p5/SHIFT.mdx | 15 + src/content/reference/en/p5/SOFT_LIGHT.mdx | 15 + src/content/reference/en/p5/SUBTRACT.mdx | 15 + src/content/reference/en/p5/TAB.mdx | 15 + src/content/reference/en/p5/TAU.mdx | 30 + src/content/reference/en/p5/TESS.mdx | 15 + src/content/reference/en/p5/TEXT.mdx | 89 +++ src/content/reference/en/p5/TEXTURE.mdx | 144 ++++ src/content/reference/en/p5/THRESHOLD.mdx | 15 + src/content/reference/en/p5/TOP.mdx | 15 + src/content/reference/en/p5/TRIANGLES.mdx | 15 + src/content/reference/en/p5/TRIANGLE_FAN.mdx | 15 + .../reference/en/p5/TRIANGLE_STRIP.mdx | 15 + src/content/reference/en/p5/TWO_PI.mdx | 30 + src/content/reference/en/p5/UNSIGNED_BYTE.mdx | 15 + src/content/reference/en/p5/UNSIGNED_INT.mdx | 15 + src/content/reference/en/p5/UP_ARROW.mdx | 15 + src/content/reference/en/p5/VERSION.mdx | 16 + src/content/reference/en/p5/WAIT.mdx | 15 + src/content/reference/en/p5/WEBGL.mdx | 89 +++ src/content/reference/en/p5/WEBGL2.mdx | 18 + src/content/reference/en/p5/WORD.mdx | 15 + src/content/reference/en/p5/abs.mdx | 50 ++ src/content/reference/en/p5/accelerationX.mdx | 34 + src/content/reference/en/p5/accelerationY.mdx | 34 + src/content/reference/en/p5/accelerationZ.mdx | 34 + src/content/reference/en/p5/acos.mdx | 61 ++ src/content/reference/en/p5/alpha.mdx | 56 ++ src/content/reference/en/p5/ambientLight.mdx | 77 ++ .../reference/en/p5/ambientMaterial.mdx | 83 ++ src/content/reference/en/p5/angleMode.mdx | 61 ++ src/content/reference/en/p5/append.mdx | 41 + src/content/reference/en/p5/applyMatrix.mdx | 171 ++++ src/content/reference/en/p5/arc.mdx | 154 ++++ src/content/reference/en/p5/arrayCopy.mdx | 42 + src/content/reference/en/p5/asin.mdx | 63 ++ src/content/reference/en/p5/atan.mdx | 63 ++ src/content/reference/en/p5/atan2.mdx | 62 ++ src/content/reference/en/p5/background.mdx | 158 ++++ src/content/reference/en/p5/beginClip.mdx | 118 +++ src/content/reference/en/p5/beginContour.mdx | 70 ++ src/content/reference/en/p5/beginGeometry.mdx | 91 +++ src/content/reference/en/p5/beginShape.mdx | 244 ++++++ src/content/reference/en/p5/bezier.mdx | 15 + src/content/reference/en/p5/bezierDetail.mdx | 49 ++ src/content/reference/en/p5/bezierPoint.mdx | 79 ++ src/content/reference/en/p5/bezierTangent.mdx | 97 +++ src/content/reference/en/p5/bezierVertex.mdx | 101 +++ src/content/reference/en/p5/blendMode.mdx | 128 +++ src/content/reference/en/p5/blue.mdx | 53 ++ src/content/reference/en/p5/boolean.mdx | 39 + src/content/reference/en/p5/box.mdx | 66 ++ src/content/reference/en/p5/brightness.mdx | 88 +++ src/content/reference/en/p5/buildGeometry.mdx | 86 +++ src/content/reference/en/p5/byte.mdx | 40 + src/content/reference/en/p5/camera.mdx | 90 +++ src/content/reference/en/p5/ceil.mdx | 65 ++ src/content/reference/en/p5/changed.mdx | 76 ++ src/content/reference/en/p5/circle.mdx | 48 ++ src/content/reference/en/p5/class.mdx | 50 ++ src/content/reference/en/p5/clear.mdx | 96 +++ src/content/reference/en/p5/clearDepth.mdx | 92 +++ src/content/reference/en/p5/clearStorage.mdx | 34 + src/content/reference/en/p5/clip.mdx | 117 +++ src/content/reference/en/p5/color.mdx | 275 +++++++ src/content/reference/en/p5/colorMode.mdx | 149 ++++ src/content/reference/en/p5/concat.mdx | 47 ++ src/content/reference/en/p5/cone.mdx | 121 +++ src/content/reference/en/p5/const.mdx | 85 ++ src/content/reference/en/p5/constrain.mdx | 75 ++ src/content/reference/en/p5/copy.mdx | 46 ++ src/content/reference/en/p5/cos.mdx | 75 ++ src/content/reference/en/p5/createA.mdx | 89 +++ src/content/reference/en/p5/createAudio.mdx | 77 ++ src/content/reference/en/p5/createButton.mdx | 95 +++ src/content/reference/en/p5/createCamera.mdx | 81 ++ src/content/reference/en/p5/createCanvas.mdx | 84 ++ src/content/reference/en/p5/createCapture.mdx | 146 ++++ .../reference/en/p5/createCheckbox.mdx | 123 +++ .../reference/en/p5/createColorPicker.mdx | 90 +++ .../reference/en/p5/createConvolver.mdx | 75 ++ src/content/reference/en/p5/createDiv.mdx | 63 ++ src/content/reference/en/p5/createElement.mdx | 71 ++ .../reference/en/p5/createFileInput.mdx | 127 +++ .../reference/en/p5/createFilterShader.mdx | 119 +++ .../reference/en/p5/createFramebuffer.mdx | 131 ++++ .../reference/en/p5/createGraphics.mdx | 62 ++ src/content/reference/en/p5/createImage.mdx | 142 ++++ src/content/reference/en/p5/createImg.mdx | 74 ++ src/content/reference/en/p5/createInput.mdx | 86 +++ .../reference/en/p5/createNumberDict.mdx | 33 + src/content/reference/en/p5/createP.mdx | 47 ++ src/content/reference/en/p5/createRadio.mdx | 168 ++++ src/content/reference/en/p5/createSelect.mdx | 196 +++++ src/content/reference/en/p5/createShader.mdx | 105 +++ src/content/reference/en/p5/createSlider.mdx | 151 ++++ src/content/reference/en/p5/createSpan.mdx | 87 +++ .../reference/en/p5/createStringDict.mdx | 32 + src/content/reference/en/p5/createVector.mdx | 125 +++ src/content/reference/en/p5/createVideo.mdx | 127 +++ src/content/reference/en/p5/createWriter.mdx | 50 ++ src/content/reference/en/p5/cursor.mdx | 124 +++ src/content/reference/en/p5/curve.mdx | 15 + src/content/reference/en/p5/curveDetail.mdx | 43 ++ src/content/reference/en/p5/curvePoint.mdx | 68 ++ src/content/reference/en/p5/curveTangent.mdx | 64 ++ .../reference/en/p5/curveTightness.mdx | 61 ++ src/content/reference/en/p5/curveVertex.mdx | 64 ++ src/content/reference/en/p5/cylinder.mdx | 125 +++ src/content/reference/en/p5/day.mdx | 32 + src/content/reference/en/p5/debugMode.mdx | 162 ++++ src/content/reference/en/p5/deltaTime.mdx | 58 ++ src/content/reference/en/p5/describe.mdx | 132 ++++ .../reference/en/p5/describeElement.mdx | 119 +++ src/content/reference/en/p5/deviceMoved.mdx | 46 ++ .../reference/en/p5/deviceOrientation.mdx | 19 + src/content/reference/en/p5/deviceShaken.mdx | 47 ++ src/content/reference/en/p5/deviceTurned.mdx | 76 ++ .../reference/en/p5/directionalLight.mdx | 70 ++ .../reference/en/p5/disableFriendlyErrors.mdx | 43 ++ .../reference/en/p5/displayDensity.mdx | 52 ++ src/content/reference/en/p5/displayHeight.mdx | 37 + src/content/reference/en/p5/displayWidth.mdx | 37 + src/content/reference/en/p5/dist.mdx | 69 ++ src/content/reference/en/p5/doubleClicked.mdx | 81 ++ src/content/reference/en/p5/draw.mdx | 90 +++ .../reference/en/p5/drawingContext.mdx | 50 ++ src/content/reference/en/p5/ellipse.mdx | 41 + src/content/reference/en/p5/ellipseMode.mdx | 107 +++ src/content/reference/en/p5/ellipsoid.mdx | 120 +++ .../reference/en/p5/emissiveMaterial.mdx | 42 + src/content/reference/en/p5/endClip.mdx | 23 + src/content/reference/en/p5/endContour.mdx | 69 ++ src/content/reference/en/p5/endGeometry.mdx | 22 + src/content/reference/en/p5/endShape.mdx | 160 ++++ src/content/reference/en/p5/erase.mdx | 152 ++++ .../reference/en/p5/exitPointerLock.mdx | 44 ++ src/content/reference/en/p5/exp.mdx | 45 ++ src/content/reference/en/p5/fill.mdx | 15 + src/content/reference/en/p5/filter.mdx | 236 ++++++ src/content/reference/en/p5/floor.mdx | 61 ++ src/content/reference/en/p5/focused.mdx | 41 + src/content/reference/en/p5/for.mdx | 76 ++ src/content/reference/en/p5/fract.mdx | 38 + src/content/reference/en/p5/frameCount.mdx | 63 ++ src/content/reference/en/p5/frameRate.mdx | 83 ++ src/content/reference/en/p5/freeGeometry.mdx | 26 + src/content/reference/en/p5/freqToMidi.mdx | 26 + src/content/reference/en/p5/frustum.mdx | 95 +++ src/content/reference/en/p5/fullscreen.mdx | 60 ++ src/content/reference/en/p5/function.mdx | 55 ++ src/content/reference/en/p5/get.mdx | 108 +++ .../reference/en/p5/getAudioContext.mdx | 49 ++ src/content/reference/en/p5/getItem.mdx | 52 ++ .../reference/en/p5/getOutputVolume.mdx | 22 + .../reference/en/p5/getTargetFrameRate.mdx | 40 + src/content/reference/en/p5/getURL.mdx | 43 ++ src/content/reference/en/p5/getURLParams.mdx | 56 ++ src/content/reference/en/p5/getURLPath.mdx | 55 ++ src/content/reference/en/p5/green.mdx | 53 ++ src/content/reference/en/p5/gridOutput.mdx | 162 ++++ src/content/reference/en/p5/height.mdx | 83 ++ src/content/reference/en/p5/hex.mdx | 32 + src/content/reference/en/p5/hour.mdx | 32 + src/content/reference/en/p5/httpDo.mdx | 81 ++ src/content/reference/en/p5/httpGet.mdx | 65 ++ src/content/reference/en/p5/httpPost.mdx | 90 +++ src/content/reference/en/p5/hue.mdx | 50 ++ src/content/reference/en/p5/if-else.mdx | 53 ++ src/content/reference/en/p5/imageLight.mdx | 111 +++ src/content/reference/en/p5/imageMode.mdx | 103 +++ src/content/reference/en/p5/input.mdx | 76 ++ src/content/reference/en/p5/int.mdx | 34 + src/content/reference/en/p5/isLooping.mdx | 74 ++ src/content/reference/en/p5/join.mdx | 47 ++ src/content/reference/en/p5/key.mdx | 40 + src/content/reference/en/p5/keyCode.mdx | 48 ++ src/content/reference/en/p5/keyIsDown.mdx | 97 +++ src/content/reference/en/p5/keyIsPressed.mdx | 35 + src/content/reference/en/p5/keyPressed.mdx | 104 +++ src/content/reference/en/p5/keyReleased.mdx | 54 ++ src/content/reference/en/p5/keyTyped.mdx | 69 ++ src/content/reference/en/p5/lerp.mdx | 101 +++ src/content/reference/en/p5/lerpColor.mdx | 75 ++ src/content/reference/en/p5/let.mdx | 46 ++ src/content/reference/en/p5/lightFalloff.mdx | 78 ++ src/content/reference/en/p5/lightness.mdx | 58 ++ src/content/reference/en/p5/lights.mdx | 44 ++ src/content/reference/en/p5/line.mdx | 74 ++ src/content/reference/en/p5/loadBytes.mdx | 53 ++ src/content/reference/en/p5/loadFont.mdx | 165 ++++ src/content/reference/en/p5/loadImage.mdx | 117 +++ src/content/reference/en/p5/loadJSON.mdx | 107 +++ src/content/reference/en/p5/loadModel.mdx | 121 +++ src/content/reference/en/p5/loadPixels.mdx | 44 ++ src/content/reference/en/p5/loadShader.mdx | 87 +++ src/content/reference/en/p5/loadSound.mdx | 75 ++ src/content/reference/en/p5/loadStrings.mdx | 98 +++ src/content/reference/en/p5/loadTable.mdx | 120 +++ src/content/reference/en/p5/loadXML.mdx | 102 +++ src/content/reference/en/p5/log.mdx | 45 ++ src/content/reference/en/p5/loop.mdx | 59 ++ src/content/reference/en/p5/mag.mdx | 64 ++ src/content/reference/en/p5/map.mdx | 90 +++ src/content/reference/en/p5/match.mdx | 53 ++ src/content/reference/en/p5/matchAll.mdx | 52 ++ src/content/reference/en/p5/max.mdx | 105 +++ src/content/reference/en/p5/metalness.mdx | 113 +++ src/content/reference/en/p5/midiToFreq.mdx | 63 ++ src/content/reference/en/p5/millis.mdx | 34 + src/content/reference/en/p5/min.mdx | 105 +++ src/content/reference/en/p5/minute.mdx | 32 + src/content/reference/en/p5/model.mdx | 47 ++ src/content/reference/en/p5/month.mdx | 32 + src/content/reference/en/p5/mouseButton.mdx | 46 ++ src/content/reference/en/p5/mouseClicked.mdx | 83 ++ src/content/reference/en/p5/mouseDragged.mdx | 78 ++ .../reference/en/p5/mouseIsPressed.mdx | 38 + src/content/reference/en/p5/mouseMoved.mdx | 74 ++ src/content/reference/en/p5/mousePressed.mdx | 81 ++ src/content/reference/en/p5/mouseReleased.mdx | 78 ++ src/content/reference/en/p5/mouseWheel.mdx | 70 ++ src/content/reference/en/p5/mouseX.mdx | 33 + src/content/reference/en/p5/mouseY.mdx | 33 + src/content/reference/en/p5/movedX.mdx | 41 + src/content/reference/en/p5/movedY.mdx | 42 + src/content/reference/en/p5/nf.mdx | 62 ++ src/content/reference/en/p5/nfc.mdx | 48 ++ src/content/reference/en/p5/nfp.mdx | 54 ++ src/content/reference/en/p5/nfs.mdx | 81 ++ src/content/reference/en/p5/noCanvas.mdx | 28 + src/content/reference/en/p5/noCursor.mdx | 35 + src/content/reference/en/p5/noDebugMode.mdx | 48 ++ src/content/reference/en/p5/noErase.mdx | 48 ++ src/content/reference/en/p5/noFill.mdx | 63 ++ src/content/reference/en/p5/noLights.mdx | 58 ++ src/content/reference/en/p5/noLoop.mdx | 101 +++ src/content/reference/en/p5/noSmooth.mdx | 42 + src/content/reference/en/p5/noStroke.mdx | 47 ++ src/content/reference/en/p5/noTint.mdx | 37 + src/content/reference/en/p5/noise.mdx | 222 ++++++ src/content/reference/en/p5/noiseDetail.mdx | 92 +++ src/content/reference/en/p5/noiseSeed.mdx | 54 ++ src/content/reference/en/p5/norm.mdx | 59 ++ src/content/reference/en/p5/normal.mdx | 15 + .../reference/en/p5/normalMaterial.mdx | 40 + src/content/reference/en/p5/number.mdx | 33 + src/content/reference/en/p5/object.mdx | 38 + src/content/reference/en/p5/orbitControl.mdx | 100 +++ src/content/reference/en/p5/ortho.mdx | 101 +++ src/content/reference/en/p5/outputVolume.mdx | 48 ++ src/content/reference/en/p5/p5.Camera.mdx | 119 +++ src/content/reference/en/p5/p5.Color.mdx | 85 ++ src/content/reference/en/p5/p5.Element.mdx | 434 +++++++++++ src/content/reference/en/p5/p5.File.mdx | 69 ++ src/content/reference/en/p5/p5.Font.mdx | 94 +++ .../reference/en/p5/p5.Framebuffer.mdx | 186 +++++ src/content/reference/en/p5/p5.Geometry.mdx | 89 +++ src/content/reference/en/p5/p5.Graphics.mdx | 70 ++ src/content/reference/en/p5/p5.Image.mdx | 363 +++++++++ .../reference/en/p5/p5.MediaElement.mdx | 212 +++++ src/content/reference/en/p5/p5.NumberDict.mdx | 60 ++ .../reference/en/p5/p5.PrintWriter.mdx | 21 + src/content/reference/en/p5/p5.Renderer.mdx | 31 + src/content/reference/en/p5/p5.Shader.mdx | 95 +++ src/content/reference/en/p5/p5.StringDict.mdx | 14 + src/content/reference/en/p5/p5.Table.mdx | 207 +++++ src/content/reference/en/p5/p5.TableRow.mdx | 63 ++ src/content/reference/en/p5/p5.TypedDict.mdx | 63 ++ src/content/reference/en/p5/p5.Vector.mdx | 470 +++++++++++ src/content/reference/en/p5/p5.XML.mdx | 141 ++++ src/content/reference/en/p5/p5.mdx | 39 + .../reference/en/p5/pAccelerationX.mdx | 18 + .../reference/en/p5/pAccelerationY.mdx | 18 + .../reference/en/p5/pAccelerationZ.mdx | 18 + src/content/reference/en/p5/pRotationX.mdx | 53 ++ src/content/reference/en/p5/pRotationY.mdx | 52 ++ src/content/reference/en/p5/pRotationZ.mdx | 48 ++ src/content/reference/en/p5/perspective.mdx | 125 +++ src/content/reference/en/p5/pixelDensity.mdx | 62 ++ src/content/reference/en/p5/pixels.mdx | 124 +++ src/content/reference/en/p5/plane.mdx | 65 ++ src/content/reference/en/p5/pmouseX.mdx | 45 ++ src/content/reference/en/p5/pmouseY.mdx | 44 ++ src/content/reference/en/p5/point.mdx | 80 ++ src/content/reference/en/p5/pointLight.mdx | 57 ++ src/content/reference/en/p5/pop.mdx | 148 ++++ src/content/reference/en/p5/pow.mdx | 67 ++ src/content/reference/en/p5/preload.mdx | 63 ++ src/content/reference/en/p5/print.mdx | 52 ++ src/content/reference/en/p5/push.mdx | 148 ++++ src/content/reference/en/p5/pwinMouseX.mdx | 48 ++ src/content/reference/en/p5/pwinMouseY.mdx | 48 ++ src/content/reference/en/p5/quad.mdx | 64 ++ .../reference/en/p5/quadraticVertex.mdx | 83 ++ src/content/reference/en/p5/random.mdx | 20 + .../reference/en/p5/randomGaussian.mdx | 93 +++ src/content/reference/en/p5/randomSeed.mdx | 66 ++ src/content/reference/en/p5/rect.mdx | 85 ++ src/content/reference/en/p5/rectMode.mdx | 108 +++ src/content/reference/en/p5/red.mdx | 44 ++ src/content/reference/en/p5/redraw.mdx | 96 +++ .../reference/en/p5/removeElements.mdx | 74 ++ src/content/reference/en/p5/removeItem.mdx | 33 + .../reference/en/p5/requestPointerLock.mdx | 54 ++ src/content/reference/en/p5/resetMatrix.mdx | 30 + src/content/reference/en/p5/resetShader.mdx | 98 +++ src/content/reference/en/p5/resizeCanvas.mdx | 49 ++ src/content/reference/en/p5/reverse.mdx | 36 + src/content/reference/en/p5/rotate.mdx | 62 ++ src/content/reference/en/p5/rotateX.mdx | 49 ++ src/content/reference/en/p5/rotateY.mdx | 49 ++ src/content/reference/en/p5/rotateZ.mdx | 51 ++ src/content/reference/en/p5/rotationX.mdx | 42 + src/content/reference/en/p5/rotationY.mdx | 42 + src/content/reference/en/p5/rotationZ.mdx | 44 ++ src/content/reference/en/p5/sampleRate.mdx | 23 + src/content/reference/en/p5/saturation.mdx | 49 ++ src/content/reference/en/p5/save.mdx | 121 +++ src/content/reference/en/p5/saveCanvas.mdx | 79 ++ src/content/reference/en/p5/saveFrames.mdx | 127 +++ src/content/reference/en/p5/saveGif.mdx | 78 ++ src/content/reference/en/p5/saveJSON.mdx | 63 ++ src/content/reference/en/p5/saveSound.mdx | 32 + src/content/reference/en/p5/saveStrings.mdx | 66 ++ src/content/reference/en/p5/saveTable.mdx | 67 ++ src/content/reference/en/p5/scale.mdx | 60 ++ src/content/reference/en/p5/second.mdx | 32 + src/content/reference/en/p5/select.mdx | 106 +++ src/content/reference/en/p5/selectAll.mdx | 111 +++ src/content/reference/en/p5/set.mdx | 148 ++++ src/content/reference/en/p5/setAttributes.mdx | 143 ++++ src/content/reference/en/p5/setBPM.mdx | 26 + src/content/reference/en/p5/setCamera.mdx | 93 +++ .../reference/en/p5/setMoveThreshold.mdx | 56 ++ .../reference/en/p5/setShakeThreshold.mdx | 56 ++ src/content/reference/en/p5/setup.mdx | 48 ++ src/content/reference/en/p5/shader.mdx | 134 ++++ src/content/reference/en/p5/shearX.mdx | 57 ++ src/content/reference/en/p5/shearY.mdx | 57 ++ src/content/reference/en/p5/shininess.mdx | 50 ++ src/content/reference/en/p5/shorten.mdx | 37 + src/content/reference/en/p5/shuffle.mdx | 47 ++ src/content/reference/en/p5/sin.mdx | 74 ++ src/content/reference/en/p5/smooth.mdx | 15 + src/content/reference/en/p5/sort.mdx | 56 ++ src/content/reference/en/p5/soundFormats.mdx | 48 ++ src/content/reference/en/p5/soundOut.mdx | 23 + src/content/reference/en/p5/specularColor.mdx | 85 ++ .../reference/en/p5/specularMaterial.mdx | 71 ++ src/content/reference/en/p5/sphere.mdx | 104 +++ src/content/reference/en/p5/splice.mdx | 51 ++ src/content/reference/en/p5/split.mdx | 65 ++ src/content/reference/en/p5/splitTokens.mdx | 54 ++ src/content/reference/en/p5/spotLight.mdx | 87 +++ src/content/reference/en/p5/sq.mdx | 51 ++ src/content/reference/en/p5/sqrt.mdx | 52 ++ src/content/reference/en/p5/square.mdx | 15 + src/content/reference/en/p5/storeItem.mdx | 58 ++ src/content/reference/en/p5/str.mdx | 37 + src/content/reference/en/p5/string.mdx | 38 + src/content/reference/en/p5/stroke.mdx | 15 + src/content/reference/en/p5/strokeCap.mdx | 61 ++ src/content/reference/en/p5/strokeJoin.mdx | 120 +++ src/content/reference/en/p5/strokeWeight.mdx | 81 ++ src/content/reference/en/p5/subset.mdx | 52 ++ src/content/reference/en/p5/tan.mdx | 46 ++ src/content/reference/en/p5/textAlign.mdx | 122 +++ src/content/reference/en/p5/textAscent.mdx | 62 ++ src/content/reference/en/p5/textDescent.mdx | 62 ++ src/content/reference/en/p5/textFont.mdx | 104 +++ src/content/reference/en/p5/textLeading.mdx | 47 ++ src/content/reference/en/p5/textOutput.mdx | 158 ++++ src/content/reference/en/p5/textSize.mdx | 47 ++ src/content/reference/en/p5/textStyle.mdx | 61 ++ src/content/reference/en/p5/textWidth.mdx | 62 ++ src/content/reference/en/p5/textWrap.mdx | 75 ++ src/content/reference/en/p5/textureMode.mdx | 88 +++ src/content/reference/en/p5/textureWrap.mdx | 91 +++ src/content/reference/en/p5/tint.mdx | 121 +++ src/content/reference/en/p5/torus.mdx | 126 +++ src/content/reference/en/p5/touchEnded.mdx | 79 ++ src/content/reference/en/p5/touchMoved.mdx | 78 ++ src/content/reference/en/p5/touchStarted.mdx | 78 ++ src/content/reference/en/p5/touches.mdx | 38 + src/content/reference/en/p5/translate.mdx | 70 ++ src/content/reference/en/p5/triangle.mdx | 58 ++ src/content/reference/en/p5/trim.mdx | 31 + src/content/reference/en/p5/turnAxis.mdx | 51 ++ src/content/reference/en/p5/unchar.mdx | 29 + src/content/reference/en/p5/unhex.mdx | 29 + src/content/reference/en/p5/updatePixels.mdx | 75 ++ .../reference/en/p5/userStartAudio.mdx | 78 ++ src/content/reference/en/p5/vertex.mdx | 146 ++++ src/content/reference/en/p5/webglVersion.mdx | 100 +++ src/content/reference/en/p5/while.mdx | 66 ++ src/content/reference/en/p5/width.mdx | 83 ++ src/content/reference/en/p5/winMouseX.mdx | 46 ++ src/content/reference/en/p5/winMouseY.mdx | 46 ++ src/content/reference/en/p5/windowHeight.mdx | 38 + src/content/reference/en/p5/windowResized.mdx | 55 ++ src/content/reference/en/p5/windowWidth.mdx | 38 + src/content/reference/en/p5/year.mdx | 32 + src/scripts/builders/reference.ts | 7 +- 1002 files changed, 55995 insertions(+), 2 deletions(-) create mode 100644 src/content/reference/en/JSON/stringify.mdx create mode 100644 src/content/reference/en/console/log.mdx create mode 100644 src/content/reference/en/index.mdx create mode 100644 src/content/reference/en/p5.Amplitude/getLevel.mdx create mode 100644 src/content/reference/en/p5.Amplitude/setInput.mdx create mode 100644 src/content/reference/en/p5.Amplitude/smooth.mdx create mode 100644 src/content/reference/en/p5.Amplitude/toggleNormalize.mdx create mode 100644 src/content/reference/en/p5.AudioIn/amp.mdx create mode 100644 src/content/reference/en/p5.AudioIn/amplitude.mdx create mode 100644 src/content/reference/en/p5.AudioIn/connect.mdx create mode 100644 src/content/reference/en/p5.AudioIn/currentSource.mdx create mode 100644 src/content/reference/en/p5.AudioIn/disconnect.mdx create mode 100644 src/content/reference/en/p5.AudioIn/enabled.mdx create mode 100644 src/content/reference/en/p5.AudioIn/getLevel.mdx create mode 100644 src/content/reference/en/p5.AudioIn/getSources.mdx create mode 100644 src/content/reference/en/p5.AudioIn/input.mdx create mode 100644 src/content/reference/en/p5.AudioIn/mediaStream.mdx create mode 100644 src/content/reference/en/p5.AudioIn/output.mdx create mode 100644 src/content/reference/en/p5.AudioIn/setSource.mdx create mode 100644 src/content/reference/en/p5.AudioIn/start.mdx create mode 100644 src/content/reference/en/p5.AudioIn/stop.mdx create mode 100644 src/content/reference/en/p5.AudioIn/stream.mdx create mode 100644 src/content/reference/en/p5.AudioVoice/connect.mdx create mode 100644 src/content/reference/en/p5.AudioVoice/disconnect.mdx create mode 100644 src/content/reference/en/p5.Camera/camera.mdx create mode 100644 src/content/reference/en/p5.Camera/centerX.mdx create mode 100644 src/content/reference/en/p5.Camera/centerY.mdx create mode 100644 src/content/reference/en/p5.Camera/centerZ.mdx create mode 100644 src/content/reference/en/p5.Camera/eyeX.mdx create mode 100644 src/content/reference/en/p5.Camera/eyeY.mdx create mode 100644 src/content/reference/en/p5.Camera/eyeZ.mdx create mode 100644 src/content/reference/en/p5.Camera/frustum.mdx create mode 100644 src/content/reference/en/p5.Camera/lookAt.mdx create mode 100644 src/content/reference/en/p5.Camera/move.mdx create mode 100644 src/content/reference/en/p5.Camera/ortho.mdx create mode 100644 src/content/reference/en/p5.Camera/pan.mdx create mode 100644 src/content/reference/en/p5.Camera/perspective.mdx create mode 100644 src/content/reference/en/p5.Camera/set.mdx create mode 100644 src/content/reference/en/p5.Camera/setPosition.mdx create mode 100644 src/content/reference/en/p5.Camera/slerp.mdx create mode 100644 src/content/reference/en/p5.Camera/tilt.mdx create mode 100644 src/content/reference/en/p5.Camera/upX.mdx create mode 100644 src/content/reference/en/p5.Camera/upY.mdx create mode 100644 src/content/reference/en/p5.Camera/upZ.mdx create mode 100644 src/content/reference/en/p5.Color/setAlpha.mdx create mode 100644 src/content/reference/en/p5.Color/setBlue.mdx create mode 100644 src/content/reference/en/p5.Color/setGreen.mdx create mode 100644 src/content/reference/en/p5.Color/setRed.mdx create mode 100644 src/content/reference/en/p5.Color/toString.mdx create mode 100644 src/content/reference/en/p5.Compressor/attack.mdx create mode 100644 src/content/reference/en/p5.Compressor/compressor.mdx create mode 100644 src/content/reference/en/p5.Compressor/knee.mdx create mode 100644 src/content/reference/en/p5.Compressor/process.mdx create mode 100644 src/content/reference/en/p5.Compressor/ratio.mdx create mode 100644 src/content/reference/en/p5.Compressor/reduction.mdx create mode 100644 src/content/reference/en/p5.Compressor/release.mdx create mode 100644 src/content/reference/en/p5.Compressor/set.mdx create mode 100644 src/content/reference/en/p5.Compressor/threshold.mdx create mode 100644 src/content/reference/en/p5.Convolver/addImpulse.mdx create mode 100644 src/content/reference/en/p5.Convolver/convolverNode.mdx create mode 100644 src/content/reference/en/p5.Convolver/impulses.mdx create mode 100644 src/content/reference/en/p5.Convolver/process.mdx create mode 100644 src/content/reference/en/p5.Convolver/resetImpulse.mdx create mode 100644 src/content/reference/en/p5.Convolver/toggleImpulse.mdx create mode 100644 src/content/reference/en/p5.Delay/amp.mdx create mode 100644 src/content/reference/en/p5.Delay/connect.mdx create mode 100644 src/content/reference/en/p5.Delay/delayTime.mdx create mode 100644 src/content/reference/en/p5.Delay/disconnect.mdx create mode 100644 src/content/reference/en/p5.Delay/feedback.mdx create mode 100644 src/content/reference/en/p5.Delay/filter.mdx create mode 100644 src/content/reference/en/p5.Delay/leftDelay.mdx create mode 100644 src/content/reference/en/p5.Delay/process.mdx create mode 100644 src/content/reference/en/p5.Delay/rightDelay.mdx create mode 100644 src/content/reference/en/p5.Delay/setType.mdx create mode 100644 src/content/reference/en/p5.Distortion/WaveShaperNode.mdx create mode 100644 src/content/reference/en/p5.Distortion/getAmount.mdx create mode 100644 src/content/reference/en/p5.Distortion/getOversample.mdx create mode 100644 src/content/reference/en/p5.Distortion/process.mdx create mode 100644 src/content/reference/en/p5.Distortion/set.mdx create mode 100644 src/content/reference/en/p5.EQ/bands.mdx create mode 100644 src/content/reference/en/p5.EQ/process.mdx create mode 100644 src/content/reference/en/p5.Effect/amp.mdx create mode 100644 src/content/reference/en/p5.Effect/chain.mdx create mode 100644 src/content/reference/en/p5.Effect/connect.mdx create mode 100644 src/content/reference/en/p5.Effect/disconnect.mdx create mode 100644 src/content/reference/en/p5.Effect/drywet.mdx create mode 100644 src/content/reference/en/p5.Element/addClass.mdx create mode 100644 src/content/reference/en/p5.Element/attribute.mdx create mode 100644 src/content/reference/en/p5.Element/center.mdx create mode 100644 src/content/reference/en/p5.Element/child.mdx create mode 100644 src/content/reference/en/p5.Element/class.mdx create mode 100644 src/content/reference/en/p5.Element/doubleClicked.mdx create mode 100644 src/content/reference/en/p5.Element/dragLeave.mdx create mode 100644 src/content/reference/en/p5.Element/dragOver.mdx create mode 100644 src/content/reference/en/p5.Element/draggable.mdx create mode 100644 src/content/reference/en/p5.Element/drop.mdx create mode 100644 src/content/reference/en/p5.Element/elt.mdx create mode 100644 src/content/reference/en/p5.Element/hasClass.mdx create mode 100644 src/content/reference/en/p5.Element/height.mdx create mode 100644 src/content/reference/en/p5.Element/hide.mdx create mode 100644 src/content/reference/en/p5.Element/html.mdx create mode 100644 src/content/reference/en/p5.Element/id.mdx create mode 100644 src/content/reference/en/p5.Element/mouseClicked.mdx create mode 100644 src/content/reference/en/p5.Element/mouseMoved.mdx create mode 100644 src/content/reference/en/p5.Element/mouseOut.mdx create mode 100644 src/content/reference/en/p5.Element/mouseOver.mdx create mode 100644 src/content/reference/en/p5.Element/mousePressed.mdx create mode 100644 src/content/reference/en/p5.Element/mouseReleased.mdx create mode 100644 src/content/reference/en/p5.Element/mouseWheel.mdx create mode 100644 src/content/reference/en/p5.Element/parent.mdx create mode 100644 src/content/reference/en/p5.Element/position.mdx create mode 100644 src/content/reference/en/p5.Element/remove.mdx create mode 100644 src/content/reference/en/p5.Element/removeAttribute.mdx create mode 100644 src/content/reference/en/p5.Element/removeClass.mdx create mode 100644 src/content/reference/en/p5.Element/show.mdx create mode 100644 src/content/reference/en/p5.Element/size.mdx create mode 100644 src/content/reference/en/p5.Element/style.mdx create mode 100644 src/content/reference/en/p5.Element/toggleClass.mdx create mode 100644 src/content/reference/en/p5.Element/touchEnded.mdx create mode 100644 src/content/reference/en/p5.Element/touchMoved.mdx create mode 100644 src/content/reference/en/p5.Element/touchStarted.mdx create mode 100644 src/content/reference/en/p5.Element/value.mdx create mode 100644 src/content/reference/en/p5.Element/width.mdx create mode 100644 src/content/reference/en/p5.Envelope/add.mdx create mode 100644 src/content/reference/en/p5.Envelope/attackLevel.mdx create mode 100644 src/content/reference/en/p5.Envelope/attackTime.mdx create mode 100644 src/content/reference/en/p5.Envelope/decayLevel.mdx create mode 100644 src/content/reference/en/p5.Envelope/decayTime.mdx create mode 100644 src/content/reference/en/p5.Envelope/mult.mdx create mode 100644 src/content/reference/en/p5.Envelope/play.mdx create mode 100644 src/content/reference/en/p5.Envelope/ramp.mdx create mode 100644 src/content/reference/en/p5.Envelope/releaseLevel.mdx create mode 100644 src/content/reference/en/p5.Envelope/releaseTime.mdx create mode 100644 src/content/reference/en/p5.Envelope/scale.mdx create mode 100644 src/content/reference/en/p5.Envelope/set.mdx create mode 100644 src/content/reference/en/p5.Envelope/setADSR.mdx create mode 100644 src/content/reference/en/p5.Envelope/setExp.mdx create mode 100644 src/content/reference/en/p5.Envelope/setInput.mdx create mode 100644 src/content/reference/en/p5.Envelope/setRange.mdx create mode 100644 src/content/reference/en/p5.Envelope/triggerAttack.mdx create mode 100644 src/content/reference/en/p5.Envelope/triggerRelease.mdx create mode 100644 src/content/reference/en/p5.FFT/analyze.mdx create mode 100644 src/content/reference/en/p5.FFT/getCentroid.mdx create mode 100644 src/content/reference/en/p5.FFT/getEnergy.mdx create mode 100644 src/content/reference/en/p5.FFT/getOctaveBands.mdx create mode 100644 src/content/reference/en/p5.FFT/linAverages.mdx create mode 100644 src/content/reference/en/p5.FFT/logAverages.mdx create mode 100644 src/content/reference/en/p5.FFT/setInput.mdx create mode 100644 src/content/reference/en/p5.FFT/smooth.mdx create mode 100644 src/content/reference/en/p5.FFT/waveform.mdx create mode 100644 src/content/reference/en/p5.File/data.mdx create mode 100644 src/content/reference/en/p5.File/file.mdx create mode 100644 src/content/reference/en/p5.File/name.mdx create mode 100644 src/content/reference/en/p5.File/size.mdx create mode 100644 src/content/reference/en/p5.File/subtype.mdx create mode 100644 src/content/reference/en/p5.File/type.mdx create mode 100644 src/content/reference/en/p5.Filter/biquadFilter.mdx create mode 100644 src/content/reference/en/p5.Filter/freq.mdx create mode 100644 src/content/reference/en/p5.Filter/gain.mdx create mode 100644 src/content/reference/en/p5.Filter/process.mdx create mode 100644 src/content/reference/en/p5.Filter/res.mdx create mode 100644 src/content/reference/en/p5.Filter/set.mdx create mode 100644 src/content/reference/en/p5.Filter/setType.mdx create mode 100644 src/content/reference/en/p5.Filter/toggle.mdx create mode 100644 src/content/reference/en/p5.Font/font.mdx create mode 100644 src/content/reference/en/p5.Font/textBounds.mdx create mode 100644 src/content/reference/en/p5.Font/textToPoints.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/autoSized.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/begin.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/color.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/createCamera.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/depth.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/draw.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/end.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/get.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/pixelDensity.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/pixels.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/remove.mdx create mode 100644 src/content/reference/en/p5.Framebuffer/resize.mdx create mode 100644 src/content/reference/en/p5.Gain/amp.mdx create mode 100644 src/content/reference/en/p5.Gain/connect.mdx create mode 100644 src/content/reference/en/p5.Gain/disconnect.mdx create mode 100644 src/content/reference/en/p5.Gain/setInput.mdx create mode 100644 src/content/reference/en/p5.Geometry/averageNormals.mdx create mode 100644 src/content/reference/en/p5.Geometry/averagePoleNormals.mdx create mode 100644 src/content/reference/en/p5.Geometry/clearColors.mdx create mode 100644 src/content/reference/en/p5.Geometry/computeFaces.mdx create mode 100644 src/content/reference/en/p5.Geometry/computeNormals.mdx create mode 100644 src/content/reference/en/p5.Geometry/flipU.mdx create mode 100644 src/content/reference/en/p5.Geometry/flipV.mdx create mode 100644 src/content/reference/en/p5.Geometry/normalize.mdx create mode 100644 src/content/reference/en/p5.Graphics/createFramebuffer.mdx create mode 100644 src/content/reference/en/p5.Graphics/remove.mdx create mode 100644 src/content/reference/en/p5.Graphics/reset.mdx create mode 100644 src/content/reference/en/p5.Image/blend.mdx create mode 100644 src/content/reference/en/p5.Image/copy.mdx create mode 100644 src/content/reference/en/p5.Image/delay.mdx create mode 100644 src/content/reference/en/p5.Image/filter.mdx create mode 100644 src/content/reference/en/p5.Image/get.mdx create mode 100644 src/content/reference/en/p5.Image/getCurrentFrame.mdx create mode 100644 src/content/reference/en/p5.Image/height.mdx create mode 100644 src/content/reference/en/p5.Image/loadPixels.mdx create mode 100644 src/content/reference/en/p5.Image/mask.mdx create mode 100644 src/content/reference/en/p5.Image/numFrames.mdx create mode 100644 src/content/reference/en/p5.Image/pause.mdx create mode 100644 src/content/reference/en/p5.Image/pixelDensity.mdx create mode 100644 src/content/reference/en/p5.Image/pixels.mdx create mode 100644 src/content/reference/en/p5.Image/play.mdx create mode 100644 src/content/reference/en/p5.Image/reset.mdx create mode 100644 src/content/reference/en/p5.Image/resize.mdx create mode 100644 src/content/reference/en/p5.Image/save.mdx create mode 100644 src/content/reference/en/p5.Image/set.mdx create mode 100644 src/content/reference/en/p5.Image/setFrame.mdx create mode 100644 src/content/reference/en/p5.Image/updatePixels.mdx create mode 100644 src/content/reference/en/p5.Image/width.mdx create mode 100644 src/content/reference/en/p5.MediaElement/addCue.mdx create mode 100644 src/content/reference/en/p5.MediaElement/autoplay.mdx create mode 100644 src/content/reference/en/p5.MediaElement/clearCues.mdx create mode 100644 src/content/reference/en/p5.MediaElement/connect.mdx create mode 100644 src/content/reference/en/p5.MediaElement/disconnect.mdx create mode 100644 src/content/reference/en/p5.MediaElement/duration.mdx create mode 100644 src/content/reference/en/p5.MediaElement/hideControls.mdx create mode 100644 src/content/reference/en/p5.MediaElement/loop.mdx create mode 100644 src/content/reference/en/p5.MediaElement/noLoop.mdx create mode 100644 src/content/reference/en/p5.MediaElement/onended.mdx create mode 100644 src/content/reference/en/p5.MediaElement/pause.mdx create mode 100644 src/content/reference/en/p5.MediaElement/play.mdx create mode 100644 src/content/reference/en/p5.MediaElement/removeCue.mdx create mode 100644 src/content/reference/en/p5.MediaElement/showControls.mdx create mode 100644 src/content/reference/en/p5.MediaElement/speed.mdx create mode 100644 src/content/reference/en/p5.MediaElement/src.mdx create mode 100644 src/content/reference/en/p5.MediaElement/stop.mdx create mode 100644 src/content/reference/en/p5.MediaElement/time.mdx create mode 100644 src/content/reference/en/p5.MediaElement/volume.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/amp.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/attack.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/connect.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/decay.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/disconnect.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/dispose.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/play.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/release.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/setADSR.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/sustain.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/triggerAttack.mdx create mode 100644 src/content/reference/en/p5.MonoSynth/triggerRelease.mdx create mode 100644 src/content/reference/en/p5.Noise/setType.mdx create mode 100644 src/content/reference/en/p5.NumberDict/add.mdx create mode 100644 src/content/reference/en/p5.NumberDict/div.mdx create mode 100644 src/content/reference/en/p5.NumberDict/maxKey.mdx create mode 100644 src/content/reference/en/p5.NumberDict/maxValue.mdx create mode 100644 src/content/reference/en/p5.NumberDict/minKey.mdx create mode 100644 src/content/reference/en/p5.NumberDict/minValue.mdx create mode 100644 src/content/reference/en/p5.NumberDict/mult.mdx create mode 100644 src/content/reference/en/p5.NumberDict/sub.mdx create mode 100644 src/content/reference/en/p5.Oscillator/add.mdx create mode 100644 src/content/reference/en/p5.Oscillator/amp.mdx create mode 100644 src/content/reference/en/p5.Oscillator/connect.mdx create mode 100644 src/content/reference/en/p5.Oscillator/disconnect.mdx create mode 100644 src/content/reference/en/p5.Oscillator/freq.mdx create mode 100644 src/content/reference/en/p5.Oscillator/getAmp.mdx create mode 100644 src/content/reference/en/p5.Oscillator/getFreq.mdx create mode 100644 src/content/reference/en/p5.Oscillator/getPan.mdx create mode 100644 src/content/reference/en/p5.Oscillator/getType.mdx create mode 100644 src/content/reference/en/p5.Oscillator/mult.mdx create mode 100644 src/content/reference/en/p5.Oscillator/pan.mdx create mode 100644 src/content/reference/en/p5.Oscillator/phase.mdx create mode 100644 src/content/reference/en/p5.Oscillator/scale.mdx create mode 100644 src/content/reference/en/p5.Oscillator/setType.mdx create mode 100644 src/content/reference/en/p5.Oscillator/start.mdx create mode 100644 src/content/reference/en/p5.Oscillator/stop.mdx create mode 100644 src/content/reference/en/p5.Panner3D/maxDist.mdx create mode 100644 src/content/reference/en/p5.Panner3D/orient.mdx create mode 100644 src/content/reference/en/p5.Panner3D/orientX.mdx create mode 100644 src/content/reference/en/p5.Panner3D/orientY.mdx create mode 100644 src/content/reference/en/p5.Panner3D/orientZ.mdx create mode 100644 src/content/reference/en/p5.Panner3D/panner.mdx create mode 100644 src/content/reference/en/p5.Panner3D/positionX.mdx create mode 100644 src/content/reference/en/p5.Panner3D/positionY.mdx create mode 100644 src/content/reference/en/p5.Panner3D/positionZ.mdx create mode 100644 src/content/reference/en/p5.Panner3D/process.mdx create mode 100644 src/content/reference/en/p5.Panner3D/rollof.mdx create mode 100644 src/content/reference/en/p5.Panner3D/set.mdx create mode 100644 src/content/reference/en/p5.Panner3D/setFalloff.mdx create mode 100644 src/content/reference/en/p5.Part/addPhrase.mdx create mode 100644 src/content/reference/en/p5.Part/getBPM.mdx create mode 100644 src/content/reference/en/p5.Part/getPhrase.mdx create mode 100644 src/content/reference/en/p5.Part/loop.mdx create mode 100644 src/content/reference/en/p5.Part/noLoop.mdx create mode 100644 src/content/reference/en/p5.Part/onStep.mdx create mode 100644 src/content/reference/en/p5.Part/pause.mdx create mode 100644 src/content/reference/en/p5.Part/removePhrase.mdx create mode 100644 src/content/reference/en/p5.Part/replaceSequence.mdx create mode 100644 src/content/reference/en/p5.Part/setBPM.mdx create mode 100644 src/content/reference/en/p5.Part/start.mdx create mode 100644 src/content/reference/en/p5.Part/stop.mdx create mode 100644 src/content/reference/en/p5.PeakDetect/isDetected.mdx create mode 100644 src/content/reference/en/p5.PeakDetect/onPeak.mdx create mode 100644 src/content/reference/en/p5.PeakDetect/update.mdx create mode 100644 src/content/reference/en/p5.Phrase/sequence.mdx create mode 100644 src/content/reference/en/p5.PolySynth/AudioVoice.mdx create mode 100644 src/content/reference/en/p5.PolySynth/connect.mdx create mode 100644 src/content/reference/en/p5.PolySynth/disconnect.mdx create mode 100644 src/content/reference/en/p5.PolySynth/dispose.mdx create mode 100644 src/content/reference/en/p5.PolySynth/noteADSR.mdx create mode 100644 src/content/reference/en/p5.PolySynth/noteAttack.mdx create mode 100644 src/content/reference/en/p5.PolySynth/noteRelease.mdx create mode 100644 src/content/reference/en/p5.PolySynth/notes.mdx create mode 100644 src/content/reference/en/p5.PolySynth/play.mdx create mode 100644 src/content/reference/en/p5.PolySynth/polyvalue.mdx create mode 100644 src/content/reference/en/p5.PolySynth/setADSR.mdx create mode 100644 src/content/reference/en/p5.PrintWriter/clear.mdx create mode 100644 src/content/reference/en/p5.PrintWriter/close.mdx create mode 100644 src/content/reference/en/p5.PrintWriter/print.mdx create mode 100644 src/content/reference/en/p5.PrintWriter/write.mdx create mode 100644 src/content/reference/en/p5.Pulse/width.mdx create mode 100644 src/content/reference/en/p5.Reverb/amp.mdx create mode 100644 src/content/reference/en/p5.Reverb/connect.mdx create mode 100644 src/content/reference/en/p5.Reverb/disconnect.mdx create mode 100644 src/content/reference/en/p5.Reverb/process.mdx create mode 100644 src/content/reference/en/p5.Reverb/set.mdx create mode 100644 src/content/reference/en/p5.Score/loop.mdx create mode 100644 src/content/reference/en/p5.Score/noLoop.mdx create mode 100644 src/content/reference/en/p5.Score/pause.mdx create mode 100644 src/content/reference/en/p5.Score/setBPM.mdx create mode 100644 src/content/reference/en/p5.Score/start.mdx create mode 100644 src/content/reference/en/p5.Score/stop.mdx create mode 100644 src/content/reference/en/p5.Shader/copyToContext.mdx create mode 100644 src/content/reference/en/p5.Shader/setUniform.mdx create mode 100644 src/content/reference/en/p5.SoundFile/addCue.mdx create mode 100644 src/content/reference/en/p5.SoundFile/channels.mdx create mode 100644 src/content/reference/en/p5.SoundFile/clearCues.mdx create mode 100644 src/content/reference/en/p5.SoundFile/connect.mdx create mode 100644 src/content/reference/en/p5.SoundFile/currentTime.mdx create mode 100644 src/content/reference/en/p5.SoundFile/disconnect.mdx create mode 100644 src/content/reference/en/p5.SoundFile/duration.mdx create mode 100644 src/content/reference/en/p5.SoundFile/frames.mdx create mode 100644 src/content/reference/en/p5.SoundFile/getBlob.mdx create mode 100644 src/content/reference/en/p5.SoundFile/getPan.mdx create mode 100644 src/content/reference/en/p5.SoundFile/getPeaks.mdx create mode 100644 src/content/reference/en/p5.SoundFile/isLoaded.mdx create mode 100644 src/content/reference/en/p5.SoundFile/isLooping.mdx create mode 100644 src/content/reference/en/p5.SoundFile/isPaused.mdx create mode 100644 src/content/reference/en/p5.SoundFile/isPlaying.mdx create mode 100644 src/content/reference/en/p5.SoundFile/jump.mdx create mode 100644 src/content/reference/en/p5.SoundFile/loop.mdx create mode 100644 src/content/reference/en/p5.SoundFile/onended.mdx create mode 100644 src/content/reference/en/p5.SoundFile/pan.mdx create mode 100644 src/content/reference/en/p5.SoundFile/pause.mdx create mode 100644 src/content/reference/en/p5.SoundFile/play.mdx create mode 100644 src/content/reference/en/p5.SoundFile/playMode.mdx create mode 100644 src/content/reference/en/p5.SoundFile/rate.mdx create mode 100644 src/content/reference/en/p5.SoundFile/removeCue.mdx create mode 100644 src/content/reference/en/p5.SoundFile/reverseBuffer.mdx create mode 100644 src/content/reference/en/p5.SoundFile/sampleRate.mdx create mode 100644 src/content/reference/en/p5.SoundFile/save.mdx create mode 100644 src/content/reference/en/p5.SoundFile/setBuffer.mdx create mode 100644 src/content/reference/en/p5.SoundFile/setLoop.mdx create mode 100644 src/content/reference/en/p5.SoundFile/setPath.mdx create mode 100644 src/content/reference/en/p5.SoundFile/setVolume.mdx create mode 100644 src/content/reference/en/p5.SoundFile/stop.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/bpm.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/interval.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/iterations.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/maxIterations.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/musicalTimeMode.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/pause.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/start.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/stop.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/syncedStart.mdx create mode 100644 src/content/reference/en/p5.SoundLoop/timeSignature.mdx create mode 100644 src/content/reference/en/p5.SoundRecorder/record.mdx create mode 100644 src/content/reference/en/p5.SoundRecorder/setInput.mdx create mode 100644 src/content/reference/en/p5.SoundRecorder/stop.mdx create mode 100644 src/content/reference/en/p5.Table/addColumn.mdx create mode 100644 src/content/reference/en/p5.Table/addRow.mdx create mode 100644 src/content/reference/en/p5.Table/clearRows.mdx create mode 100644 src/content/reference/en/p5.Table/columns.mdx create mode 100644 src/content/reference/en/p5.Table/findRow.mdx create mode 100644 src/content/reference/en/p5.Table/findRows.mdx create mode 100644 src/content/reference/en/p5.Table/get.mdx create mode 100644 src/content/reference/en/p5.Table/getArray.mdx create mode 100644 src/content/reference/en/p5.Table/getColumn.mdx create mode 100644 src/content/reference/en/p5.Table/getColumnCount.mdx create mode 100644 src/content/reference/en/p5.Table/getNum.mdx create mode 100644 src/content/reference/en/p5.Table/getObject.mdx create mode 100644 src/content/reference/en/p5.Table/getRow.mdx create mode 100644 src/content/reference/en/p5.Table/getRowCount.mdx create mode 100644 src/content/reference/en/p5.Table/getRows.mdx create mode 100644 src/content/reference/en/p5.Table/getString.mdx create mode 100644 src/content/reference/en/p5.Table/matchRow.mdx create mode 100644 src/content/reference/en/p5.Table/matchRows.mdx create mode 100644 src/content/reference/en/p5.Table/removeColumn.mdx create mode 100644 src/content/reference/en/p5.Table/removeRow.mdx create mode 100644 src/content/reference/en/p5.Table/removeTokens.mdx create mode 100644 src/content/reference/en/p5.Table/rows.mdx create mode 100644 src/content/reference/en/p5.Table/set.mdx create mode 100644 src/content/reference/en/p5.Table/setNum.mdx create mode 100644 src/content/reference/en/p5.Table/setString.mdx create mode 100644 src/content/reference/en/p5.Table/trim.mdx create mode 100644 src/content/reference/en/p5.TableRow/get.mdx create mode 100644 src/content/reference/en/p5.TableRow/getNum.mdx create mode 100644 src/content/reference/en/p5.TableRow/getString.mdx create mode 100644 src/content/reference/en/p5.TableRow/set.mdx create mode 100644 src/content/reference/en/p5.TableRow/setNum.mdx create mode 100644 src/content/reference/en/p5.TableRow/setString.mdx create mode 100644 src/content/reference/en/p5.TypedDict/clear.mdx create mode 100644 src/content/reference/en/p5.TypedDict/create.mdx create mode 100644 src/content/reference/en/p5.TypedDict/get.mdx create mode 100644 src/content/reference/en/p5.TypedDict/hasKey.mdx create mode 100644 src/content/reference/en/p5.TypedDict/print.mdx create mode 100644 src/content/reference/en/p5.TypedDict/remove.mdx create mode 100644 src/content/reference/en/p5.TypedDict/saveJSON.mdx create mode 100644 src/content/reference/en/p5.TypedDict/saveTable.mdx create mode 100644 src/content/reference/en/p5.TypedDict/set.mdx create mode 100644 src/content/reference/en/p5.TypedDict/size.mdx create mode 100644 src/content/reference/en/p5.Vector/add.mdx create mode 100644 src/content/reference/en/p5.Vector/angleBetween.mdx create mode 100644 src/content/reference/en/p5.Vector/array.mdx create mode 100644 src/content/reference/en/p5.Vector/copy.mdx create mode 100644 src/content/reference/en/p5.Vector/cross.mdx create mode 100644 src/content/reference/en/p5.Vector/dist.mdx create mode 100644 src/content/reference/en/p5.Vector/div.mdx create mode 100644 src/content/reference/en/p5.Vector/dot.mdx create mode 100644 src/content/reference/en/p5.Vector/equals.mdx create mode 100644 src/content/reference/en/p5.Vector/fromAngle.mdx create mode 100644 src/content/reference/en/p5.Vector/fromAngles.mdx create mode 100644 src/content/reference/en/p5.Vector/heading.mdx create mode 100644 src/content/reference/en/p5.Vector/lerp.mdx create mode 100644 src/content/reference/en/p5.Vector/limit.mdx create mode 100644 src/content/reference/en/p5.Vector/mag.mdx create mode 100644 src/content/reference/en/p5.Vector/magSq.mdx create mode 100644 src/content/reference/en/p5.Vector/mult.mdx create mode 100644 src/content/reference/en/p5.Vector/normalize.mdx create mode 100644 src/content/reference/en/p5.Vector/random2D.mdx create mode 100644 src/content/reference/en/p5.Vector/random3D.mdx create mode 100644 src/content/reference/en/p5.Vector/reflect.mdx create mode 100644 src/content/reference/en/p5.Vector/rem.mdx create mode 100644 src/content/reference/en/p5.Vector/rotate.mdx create mode 100644 src/content/reference/en/p5.Vector/set.mdx create mode 100644 src/content/reference/en/p5.Vector/setHeading.mdx create mode 100644 src/content/reference/en/p5.Vector/setMag.mdx create mode 100644 src/content/reference/en/p5.Vector/slerp.mdx create mode 100644 src/content/reference/en/p5.Vector/sub.mdx create mode 100644 src/content/reference/en/p5.Vector/toString.mdx create mode 100644 src/content/reference/en/p5.Vector/x.mdx create mode 100644 src/content/reference/en/p5.Vector/y.mdx create mode 100644 src/content/reference/en/p5.Vector/z.mdx create mode 100644 src/content/reference/en/p5.XML/addChild.mdx create mode 100644 src/content/reference/en/p5.XML/getAttributeCount.mdx create mode 100644 src/content/reference/en/p5.XML/getChild.mdx create mode 100644 src/content/reference/en/p5.XML/getChildren.mdx create mode 100644 src/content/reference/en/p5.XML/getContent.mdx create mode 100644 src/content/reference/en/p5.XML/getName.mdx create mode 100644 src/content/reference/en/p5.XML/getNum.mdx create mode 100644 src/content/reference/en/p5.XML/getParent.mdx create mode 100644 src/content/reference/en/p5.XML/getString.mdx create mode 100644 src/content/reference/en/p5.XML/hasAttribute.mdx create mode 100644 src/content/reference/en/p5.XML/hasChildren.mdx create mode 100644 src/content/reference/en/p5.XML/listAttributes.mdx create mode 100644 src/content/reference/en/p5.XML/listChildren.mdx create mode 100644 src/content/reference/en/p5.XML/removeChild.mdx create mode 100644 src/content/reference/en/p5.XML/serialize.mdx create mode 100644 src/content/reference/en/p5.XML/setAttribute.mdx create mode 100644 src/content/reference/en/p5.XML/setContent.mdx create mode 100644 src/content/reference/en/p5.XML/setName.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Amplitude.mdx create mode 100644 src/content/reference/en/p5.sound/p5.AudioIn.mdx create mode 100644 src/content/reference/en/p5.sound/p5.AudioVoice.mdx create mode 100644 src/content/reference/en/p5.sound/p5.BandPass.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Compressor.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Convolver.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Delay.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Distortion.mdx create mode 100644 src/content/reference/en/p5.sound/p5.EQ.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Effect.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Envelope.mdx create mode 100644 src/content/reference/en/p5.sound/p5.FFT.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Filter.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Gain.mdx create mode 100644 src/content/reference/en/p5.sound/p5.HighPass.mdx create mode 100644 src/content/reference/en/p5.sound/p5.LowPass.mdx create mode 100644 src/content/reference/en/p5.sound/p5.MonoSynth.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Noise.mdx create mode 100644 src/content/reference/en/p5.sound/p5.OnsetDetect.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Oscillator.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Panner3D.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Part.mdx create mode 100644 src/content/reference/en/p5.sound/p5.PeakDetect.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Phrase.mdx create mode 100644 src/content/reference/en/p5.sound/p5.PolySynth.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Pulse.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Reverb.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SawOsc.mdx create mode 100644 src/content/reference/en/p5.sound/p5.Score.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SinOsc.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SoundFile.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SoundLoop.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SoundRecorder.mdx create mode 100644 src/content/reference/en/p5.sound/p5.SqrOsc.mdx create mode 100644 src/content/reference/en/p5.sound/p5.TriOsc.mdx create mode 100644 src/content/reference/en/p5/>.mdx create mode 100644 src/content/reference/en/p5/>=.mdx create mode 100644 src/content/reference/en/p5/<.mdx create mode 100644 src/content/reference/en/p5/<=.mdx create mode 100644 src/content/reference/en/p5/===.mdx create mode 100644 src/content/reference/en/p5/ADD.mdx create mode 100644 src/content/reference/en/p5/ALT.mdx create mode 100644 src/content/reference/en/p5/ARROW.mdx create mode 100644 src/content/reference/en/p5/AUTO.mdx create mode 100644 src/content/reference/en/p5/AXES.mdx create mode 100644 src/content/reference/en/p5/BACKSPACE.mdx create mode 100644 src/content/reference/en/p5/BASELINE.mdx create mode 100644 src/content/reference/en/p5/BEVEL.mdx create mode 100644 src/content/reference/en/p5/BLEND.mdx create mode 100644 src/content/reference/en/p5/BLUR.mdx create mode 100644 src/content/reference/en/p5/BOLD.mdx create mode 100644 src/content/reference/en/p5/BOLDITALIC.mdx create mode 100644 src/content/reference/en/p5/BOTTOM.mdx create mode 100644 src/content/reference/en/p5/BURN.mdx create mode 100644 src/content/reference/en/p5/CENTER.mdx create mode 100644 src/content/reference/en/p5/CHAR.mdx create mode 100644 src/content/reference/en/p5/CHORD.mdx create mode 100644 src/content/reference/en/p5/CLAMP.mdx create mode 100644 src/content/reference/en/p5/CLOSE.mdx create mode 100644 src/content/reference/en/p5/CONTAIN.mdx create mode 100644 src/content/reference/en/p5/CONTROL.mdx create mode 100644 src/content/reference/en/p5/CORNER.mdx create mode 100644 src/content/reference/en/p5/CORNERS.mdx create mode 100644 src/content/reference/en/p5/COVER.mdx create mode 100644 src/content/reference/en/p5/CROSS.mdx create mode 100644 src/content/reference/en/p5/DARKEST.mdx create mode 100644 src/content/reference/en/p5/DEGREES.mdx create mode 100644 src/content/reference/en/p5/DELETE.mdx create mode 100644 src/content/reference/en/p5/DIFFERENCE.mdx create mode 100644 src/content/reference/en/p5/DILATE.mdx create mode 100644 src/content/reference/en/p5/DODGE.mdx create mode 100644 src/content/reference/en/p5/DOWN_ARROW.mdx create mode 100644 src/content/reference/en/p5/ENTER.mdx create mode 100644 src/content/reference/en/p5/ERODE.mdx create mode 100644 src/content/reference/en/p5/ESCAPE.mdx create mode 100644 src/content/reference/en/p5/EXCLUSION.mdx create mode 100644 src/content/reference/en/p5/FALLBACK.mdx create mode 100644 src/content/reference/en/p5/FLAT.mdx create mode 100644 src/content/reference/en/p5/FLOAT.mdx create mode 100644 src/content/reference/en/p5/GRAY.mdx create mode 100644 src/content/reference/en/p5/GRID.mdx create mode 100644 src/content/reference/en/p5/HALF_FLOAT.mdx create mode 100644 src/content/reference/en/p5/HALF_PI.mdx create mode 100644 src/content/reference/en/p5/HAND.mdx create mode 100644 src/content/reference/en/p5/HARD_LIGHT.mdx create mode 100644 src/content/reference/en/p5/HSB.mdx create mode 100644 src/content/reference/en/p5/HSL.mdx create mode 100644 src/content/reference/en/p5/IMAGE.mdx create mode 100644 src/content/reference/en/p5/IMMEDIATE.mdx create mode 100644 src/content/reference/en/p5/INVERT.mdx create mode 100644 src/content/reference/en/p5/ITALIC.mdx create mode 100644 src/content/reference/en/p5/LABEL.mdx create mode 100644 src/content/reference/en/p5/LANDSCAPE.mdx create mode 100644 src/content/reference/en/p5/LEFT.mdx create mode 100644 src/content/reference/en/p5/LEFT_ARROW.mdx create mode 100644 src/content/reference/en/p5/LIGHTEST.mdx create mode 100644 src/content/reference/en/p5/LINEAR.mdx create mode 100644 src/content/reference/en/p5/LINES.mdx create mode 100644 src/content/reference/en/p5/LINE_LOOP.mdx create mode 100644 src/content/reference/en/p5/LINE_STRIP.mdx create mode 100644 src/content/reference/en/p5/MIRROR.mdx create mode 100644 src/content/reference/en/p5/MITER.mdx create mode 100644 src/content/reference/en/p5/MOVE.mdx create mode 100644 src/content/reference/en/p5/MULTIPLY.mdx create mode 100644 src/content/reference/en/p5/NEAREST.mdx create mode 100644 src/content/reference/en/p5/OPAQUE.mdx create mode 100644 src/content/reference/en/p5/OPEN.mdx create mode 100644 src/content/reference/en/p5/OPTION.mdx create mode 100644 src/content/reference/en/p5/OVERLAY.mdx create mode 100644 src/content/reference/en/p5/P2D.mdx create mode 100644 src/content/reference/en/p5/PI.mdx create mode 100644 src/content/reference/en/p5/PIE.mdx create mode 100644 src/content/reference/en/p5/POINTS.mdx create mode 100644 src/content/reference/en/p5/PORTRAIT.mdx create mode 100644 src/content/reference/en/p5/POSTERIZE.mdx create mode 100644 src/content/reference/en/p5/PROJECT.mdx create mode 100644 src/content/reference/en/p5/QUADRATIC.mdx create mode 100644 src/content/reference/en/p5/QUADS.mdx create mode 100644 src/content/reference/en/p5/QUAD_STRIP.mdx create mode 100644 src/content/reference/en/p5/QUARTER_PI.mdx create mode 100644 src/content/reference/en/p5/RADIANS.mdx create mode 100644 src/content/reference/en/p5/RADIUS.mdx create mode 100644 src/content/reference/en/p5/REMOVE.mdx create mode 100644 src/content/reference/en/p5/REPEAT.mdx create mode 100644 src/content/reference/en/p5/REPLACE.mdx create mode 100644 src/content/reference/en/p5/RETURN.mdx create mode 100644 src/content/reference/en/p5/RGB.mdx create mode 100644 src/content/reference/en/p5/RGBA.mdx create mode 100644 src/content/reference/en/p5/RIGHT.mdx create mode 100644 src/content/reference/en/p5/RIGHT_ARROW.mdx create mode 100644 src/content/reference/en/p5/ROUND.mdx create mode 100644 src/content/reference/en/p5/SCREEN.mdx create mode 100644 src/content/reference/en/p5/SHIFT.mdx create mode 100644 src/content/reference/en/p5/SOFT_LIGHT.mdx create mode 100644 src/content/reference/en/p5/SUBTRACT.mdx create mode 100644 src/content/reference/en/p5/TAB.mdx create mode 100644 src/content/reference/en/p5/TAU.mdx create mode 100644 src/content/reference/en/p5/TESS.mdx create mode 100644 src/content/reference/en/p5/TEXT.mdx create mode 100644 src/content/reference/en/p5/TEXTURE.mdx create mode 100644 src/content/reference/en/p5/THRESHOLD.mdx create mode 100644 src/content/reference/en/p5/TOP.mdx create mode 100644 src/content/reference/en/p5/TRIANGLES.mdx create mode 100644 src/content/reference/en/p5/TRIANGLE_FAN.mdx create mode 100644 src/content/reference/en/p5/TRIANGLE_STRIP.mdx create mode 100644 src/content/reference/en/p5/TWO_PI.mdx create mode 100644 src/content/reference/en/p5/UNSIGNED_BYTE.mdx create mode 100644 src/content/reference/en/p5/UNSIGNED_INT.mdx create mode 100644 src/content/reference/en/p5/UP_ARROW.mdx create mode 100644 src/content/reference/en/p5/VERSION.mdx create mode 100644 src/content/reference/en/p5/WAIT.mdx create mode 100644 src/content/reference/en/p5/WEBGL.mdx create mode 100644 src/content/reference/en/p5/WEBGL2.mdx create mode 100644 src/content/reference/en/p5/WORD.mdx create mode 100644 src/content/reference/en/p5/abs.mdx create mode 100644 src/content/reference/en/p5/accelerationX.mdx create mode 100644 src/content/reference/en/p5/accelerationY.mdx create mode 100644 src/content/reference/en/p5/accelerationZ.mdx create mode 100644 src/content/reference/en/p5/acos.mdx create mode 100644 src/content/reference/en/p5/alpha.mdx create mode 100644 src/content/reference/en/p5/ambientLight.mdx create mode 100644 src/content/reference/en/p5/ambientMaterial.mdx create mode 100644 src/content/reference/en/p5/angleMode.mdx create mode 100644 src/content/reference/en/p5/append.mdx create mode 100644 src/content/reference/en/p5/applyMatrix.mdx create mode 100644 src/content/reference/en/p5/arc.mdx create mode 100644 src/content/reference/en/p5/arrayCopy.mdx create mode 100644 src/content/reference/en/p5/asin.mdx create mode 100644 src/content/reference/en/p5/atan.mdx create mode 100644 src/content/reference/en/p5/atan2.mdx create mode 100644 src/content/reference/en/p5/background.mdx create mode 100644 src/content/reference/en/p5/beginClip.mdx create mode 100644 src/content/reference/en/p5/beginContour.mdx create mode 100644 src/content/reference/en/p5/beginGeometry.mdx create mode 100644 src/content/reference/en/p5/beginShape.mdx create mode 100644 src/content/reference/en/p5/bezier.mdx create mode 100644 src/content/reference/en/p5/bezierDetail.mdx create mode 100644 src/content/reference/en/p5/bezierPoint.mdx create mode 100644 src/content/reference/en/p5/bezierTangent.mdx create mode 100644 src/content/reference/en/p5/bezierVertex.mdx create mode 100644 src/content/reference/en/p5/blendMode.mdx create mode 100644 src/content/reference/en/p5/blue.mdx create mode 100644 src/content/reference/en/p5/boolean.mdx create mode 100644 src/content/reference/en/p5/box.mdx create mode 100644 src/content/reference/en/p5/brightness.mdx create mode 100644 src/content/reference/en/p5/buildGeometry.mdx create mode 100644 src/content/reference/en/p5/byte.mdx create mode 100644 src/content/reference/en/p5/camera.mdx create mode 100644 src/content/reference/en/p5/ceil.mdx create mode 100644 src/content/reference/en/p5/changed.mdx create mode 100644 src/content/reference/en/p5/circle.mdx create mode 100644 src/content/reference/en/p5/class.mdx create mode 100644 src/content/reference/en/p5/clear.mdx create mode 100644 src/content/reference/en/p5/clearDepth.mdx create mode 100644 src/content/reference/en/p5/clearStorage.mdx create mode 100644 src/content/reference/en/p5/clip.mdx create mode 100644 src/content/reference/en/p5/color.mdx create mode 100644 src/content/reference/en/p5/colorMode.mdx create mode 100644 src/content/reference/en/p5/concat.mdx create mode 100644 src/content/reference/en/p5/cone.mdx create mode 100644 src/content/reference/en/p5/const.mdx create mode 100644 src/content/reference/en/p5/constrain.mdx create mode 100644 src/content/reference/en/p5/copy.mdx create mode 100644 src/content/reference/en/p5/cos.mdx create mode 100644 src/content/reference/en/p5/createA.mdx create mode 100644 src/content/reference/en/p5/createAudio.mdx create mode 100644 src/content/reference/en/p5/createButton.mdx create mode 100644 src/content/reference/en/p5/createCamera.mdx create mode 100644 src/content/reference/en/p5/createCanvas.mdx create mode 100644 src/content/reference/en/p5/createCapture.mdx create mode 100644 src/content/reference/en/p5/createCheckbox.mdx create mode 100644 src/content/reference/en/p5/createColorPicker.mdx create mode 100644 src/content/reference/en/p5/createConvolver.mdx create mode 100644 src/content/reference/en/p5/createDiv.mdx create mode 100644 src/content/reference/en/p5/createElement.mdx create mode 100644 src/content/reference/en/p5/createFileInput.mdx create mode 100644 src/content/reference/en/p5/createFilterShader.mdx create mode 100644 src/content/reference/en/p5/createFramebuffer.mdx create mode 100644 src/content/reference/en/p5/createGraphics.mdx create mode 100644 src/content/reference/en/p5/createImage.mdx create mode 100644 src/content/reference/en/p5/createImg.mdx create mode 100644 src/content/reference/en/p5/createInput.mdx create mode 100644 src/content/reference/en/p5/createNumberDict.mdx create mode 100644 src/content/reference/en/p5/createP.mdx create mode 100644 src/content/reference/en/p5/createRadio.mdx create mode 100644 src/content/reference/en/p5/createSelect.mdx create mode 100644 src/content/reference/en/p5/createShader.mdx create mode 100644 src/content/reference/en/p5/createSlider.mdx create mode 100644 src/content/reference/en/p5/createSpan.mdx create mode 100644 src/content/reference/en/p5/createStringDict.mdx create mode 100644 src/content/reference/en/p5/createVector.mdx create mode 100644 src/content/reference/en/p5/createVideo.mdx create mode 100644 src/content/reference/en/p5/createWriter.mdx create mode 100644 src/content/reference/en/p5/cursor.mdx create mode 100644 src/content/reference/en/p5/curve.mdx create mode 100644 src/content/reference/en/p5/curveDetail.mdx create mode 100644 src/content/reference/en/p5/curvePoint.mdx create mode 100644 src/content/reference/en/p5/curveTangent.mdx create mode 100644 src/content/reference/en/p5/curveTightness.mdx create mode 100644 src/content/reference/en/p5/curveVertex.mdx create mode 100644 src/content/reference/en/p5/cylinder.mdx create mode 100644 src/content/reference/en/p5/day.mdx create mode 100644 src/content/reference/en/p5/debugMode.mdx create mode 100644 src/content/reference/en/p5/deltaTime.mdx create mode 100644 src/content/reference/en/p5/describe.mdx create mode 100644 src/content/reference/en/p5/describeElement.mdx create mode 100644 src/content/reference/en/p5/deviceMoved.mdx create mode 100644 src/content/reference/en/p5/deviceOrientation.mdx create mode 100644 src/content/reference/en/p5/deviceShaken.mdx create mode 100644 src/content/reference/en/p5/deviceTurned.mdx create mode 100644 src/content/reference/en/p5/directionalLight.mdx create mode 100644 src/content/reference/en/p5/disableFriendlyErrors.mdx create mode 100644 src/content/reference/en/p5/displayDensity.mdx create mode 100644 src/content/reference/en/p5/displayHeight.mdx create mode 100644 src/content/reference/en/p5/displayWidth.mdx create mode 100644 src/content/reference/en/p5/dist.mdx create mode 100644 src/content/reference/en/p5/doubleClicked.mdx create mode 100644 src/content/reference/en/p5/draw.mdx create mode 100644 src/content/reference/en/p5/drawingContext.mdx create mode 100644 src/content/reference/en/p5/ellipse.mdx create mode 100644 src/content/reference/en/p5/ellipseMode.mdx create mode 100644 src/content/reference/en/p5/ellipsoid.mdx create mode 100644 src/content/reference/en/p5/emissiveMaterial.mdx create mode 100644 src/content/reference/en/p5/endClip.mdx create mode 100644 src/content/reference/en/p5/endContour.mdx create mode 100644 src/content/reference/en/p5/endGeometry.mdx create mode 100644 src/content/reference/en/p5/endShape.mdx create mode 100644 src/content/reference/en/p5/erase.mdx create mode 100644 src/content/reference/en/p5/exitPointerLock.mdx create mode 100644 src/content/reference/en/p5/exp.mdx create mode 100644 src/content/reference/en/p5/fill.mdx create mode 100644 src/content/reference/en/p5/filter.mdx create mode 100644 src/content/reference/en/p5/floor.mdx create mode 100644 src/content/reference/en/p5/focused.mdx create mode 100644 src/content/reference/en/p5/for.mdx create mode 100644 src/content/reference/en/p5/fract.mdx create mode 100644 src/content/reference/en/p5/frameCount.mdx create mode 100644 src/content/reference/en/p5/frameRate.mdx create mode 100644 src/content/reference/en/p5/freeGeometry.mdx create mode 100644 src/content/reference/en/p5/freqToMidi.mdx create mode 100644 src/content/reference/en/p5/frustum.mdx create mode 100644 src/content/reference/en/p5/fullscreen.mdx create mode 100644 src/content/reference/en/p5/function.mdx create mode 100644 src/content/reference/en/p5/get.mdx create mode 100644 src/content/reference/en/p5/getAudioContext.mdx create mode 100644 src/content/reference/en/p5/getItem.mdx create mode 100644 src/content/reference/en/p5/getOutputVolume.mdx create mode 100644 src/content/reference/en/p5/getTargetFrameRate.mdx create mode 100644 src/content/reference/en/p5/getURL.mdx create mode 100644 src/content/reference/en/p5/getURLParams.mdx create mode 100644 src/content/reference/en/p5/getURLPath.mdx create mode 100644 src/content/reference/en/p5/green.mdx create mode 100644 src/content/reference/en/p5/gridOutput.mdx create mode 100644 src/content/reference/en/p5/height.mdx create mode 100644 src/content/reference/en/p5/hex.mdx create mode 100644 src/content/reference/en/p5/hour.mdx create mode 100644 src/content/reference/en/p5/httpDo.mdx create mode 100644 src/content/reference/en/p5/httpGet.mdx create mode 100644 src/content/reference/en/p5/httpPost.mdx create mode 100644 src/content/reference/en/p5/hue.mdx create mode 100644 src/content/reference/en/p5/if-else.mdx create mode 100644 src/content/reference/en/p5/imageLight.mdx create mode 100644 src/content/reference/en/p5/imageMode.mdx create mode 100644 src/content/reference/en/p5/input.mdx create mode 100644 src/content/reference/en/p5/int.mdx create mode 100644 src/content/reference/en/p5/isLooping.mdx create mode 100644 src/content/reference/en/p5/join.mdx create mode 100644 src/content/reference/en/p5/key.mdx create mode 100644 src/content/reference/en/p5/keyCode.mdx create mode 100644 src/content/reference/en/p5/keyIsDown.mdx create mode 100644 src/content/reference/en/p5/keyIsPressed.mdx create mode 100644 src/content/reference/en/p5/keyPressed.mdx create mode 100644 src/content/reference/en/p5/keyReleased.mdx create mode 100644 src/content/reference/en/p5/keyTyped.mdx create mode 100644 src/content/reference/en/p5/lerp.mdx create mode 100644 src/content/reference/en/p5/lerpColor.mdx create mode 100644 src/content/reference/en/p5/let.mdx create mode 100644 src/content/reference/en/p5/lightFalloff.mdx create mode 100644 src/content/reference/en/p5/lightness.mdx create mode 100644 src/content/reference/en/p5/lights.mdx create mode 100644 src/content/reference/en/p5/line.mdx create mode 100644 src/content/reference/en/p5/loadBytes.mdx create mode 100644 src/content/reference/en/p5/loadFont.mdx create mode 100644 src/content/reference/en/p5/loadImage.mdx create mode 100644 src/content/reference/en/p5/loadJSON.mdx create mode 100644 src/content/reference/en/p5/loadModel.mdx create mode 100644 src/content/reference/en/p5/loadPixels.mdx create mode 100644 src/content/reference/en/p5/loadShader.mdx create mode 100644 src/content/reference/en/p5/loadSound.mdx create mode 100644 src/content/reference/en/p5/loadStrings.mdx create mode 100644 src/content/reference/en/p5/loadTable.mdx create mode 100644 src/content/reference/en/p5/loadXML.mdx create mode 100644 src/content/reference/en/p5/log.mdx create mode 100644 src/content/reference/en/p5/loop.mdx create mode 100644 src/content/reference/en/p5/mag.mdx create mode 100644 src/content/reference/en/p5/map.mdx create mode 100644 src/content/reference/en/p5/match.mdx create mode 100644 src/content/reference/en/p5/matchAll.mdx create mode 100644 src/content/reference/en/p5/max.mdx create mode 100644 src/content/reference/en/p5/metalness.mdx create mode 100644 src/content/reference/en/p5/midiToFreq.mdx create mode 100644 src/content/reference/en/p5/millis.mdx create mode 100644 src/content/reference/en/p5/min.mdx create mode 100644 src/content/reference/en/p5/minute.mdx create mode 100644 src/content/reference/en/p5/model.mdx create mode 100644 src/content/reference/en/p5/month.mdx create mode 100644 src/content/reference/en/p5/mouseButton.mdx create mode 100644 src/content/reference/en/p5/mouseClicked.mdx create mode 100644 src/content/reference/en/p5/mouseDragged.mdx create mode 100644 src/content/reference/en/p5/mouseIsPressed.mdx create mode 100644 src/content/reference/en/p5/mouseMoved.mdx create mode 100644 src/content/reference/en/p5/mousePressed.mdx create mode 100644 src/content/reference/en/p5/mouseReleased.mdx create mode 100644 src/content/reference/en/p5/mouseWheel.mdx create mode 100644 src/content/reference/en/p5/mouseX.mdx create mode 100644 src/content/reference/en/p5/mouseY.mdx create mode 100644 src/content/reference/en/p5/movedX.mdx create mode 100644 src/content/reference/en/p5/movedY.mdx create mode 100644 src/content/reference/en/p5/nf.mdx create mode 100644 src/content/reference/en/p5/nfc.mdx create mode 100644 src/content/reference/en/p5/nfp.mdx create mode 100644 src/content/reference/en/p5/nfs.mdx create mode 100644 src/content/reference/en/p5/noCanvas.mdx create mode 100644 src/content/reference/en/p5/noCursor.mdx create mode 100644 src/content/reference/en/p5/noDebugMode.mdx create mode 100644 src/content/reference/en/p5/noErase.mdx create mode 100644 src/content/reference/en/p5/noFill.mdx create mode 100644 src/content/reference/en/p5/noLights.mdx create mode 100644 src/content/reference/en/p5/noLoop.mdx create mode 100644 src/content/reference/en/p5/noSmooth.mdx create mode 100644 src/content/reference/en/p5/noStroke.mdx create mode 100644 src/content/reference/en/p5/noTint.mdx create mode 100644 src/content/reference/en/p5/noise.mdx create mode 100644 src/content/reference/en/p5/noiseDetail.mdx create mode 100644 src/content/reference/en/p5/noiseSeed.mdx create mode 100644 src/content/reference/en/p5/norm.mdx create mode 100644 src/content/reference/en/p5/normal.mdx create mode 100644 src/content/reference/en/p5/normalMaterial.mdx create mode 100644 src/content/reference/en/p5/number.mdx create mode 100644 src/content/reference/en/p5/object.mdx create mode 100644 src/content/reference/en/p5/orbitControl.mdx create mode 100644 src/content/reference/en/p5/ortho.mdx create mode 100644 src/content/reference/en/p5/outputVolume.mdx create mode 100644 src/content/reference/en/p5/p5.Camera.mdx create mode 100644 src/content/reference/en/p5/p5.Color.mdx create mode 100644 src/content/reference/en/p5/p5.Element.mdx create mode 100644 src/content/reference/en/p5/p5.File.mdx create mode 100644 src/content/reference/en/p5/p5.Font.mdx create mode 100644 src/content/reference/en/p5/p5.Framebuffer.mdx create mode 100644 src/content/reference/en/p5/p5.Geometry.mdx create mode 100644 src/content/reference/en/p5/p5.Graphics.mdx create mode 100644 src/content/reference/en/p5/p5.Image.mdx create mode 100644 src/content/reference/en/p5/p5.MediaElement.mdx create mode 100644 src/content/reference/en/p5/p5.NumberDict.mdx create mode 100644 src/content/reference/en/p5/p5.PrintWriter.mdx create mode 100644 src/content/reference/en/p5/p5.Renderer.mdx create mode 100644 src/content/reference/en/p5/p5.Shader.mdx create mode 100644 src/content/reference/en/p5/p5.StringDict.mdx create mode 100644 src/content/reference/en/p5/p5.Table.mdx create mode 100644 src/content/reference/en/p5/p5.TableRow.mdx create mode 100644 src/content/reference/en/p5/p5.TypedDict.mdx create mode 100644 src/content/reference/en/p5/p5.Vector.mdx create mode 100644 src/content/reference/en/p5/p5.XML.mdx create mode 100644 src/content/reference/en/p5/p5.mdx create mode 100644 src/content/reference/en/p5/pAccelerationX.mdx create mode 100644 src/content/reference/en/p5/pAccelerationY.mdx create mode 100644 src/content/reference/en/p5/pAccelerationZ.mdx create mode 100644 src/content/reference/en/p5/pRotationX.mdx create mode 100644 src/content/reference/en/p5/pRotationY.mdx create mode 100644 src/content/reference/en/p5/pRotationZ.mdx create mode 100644 src/content/reference/en/p5/perspective.mdx create mode 100644 src/content/reference/en/p5/pixelDensity.mdx create mode 100644 src/content/reference/en/p5/pixels.mdx create mode 100644 src/content/reference/en/p5/plane.mdx create mode 100644 src/content/reference/en/p5/pmouseX.mdx create mode 100644 src/content/reference/en/p5/pmouseY.mdx create mode 100644 src/content/reference/en/p5/point.mdx create mode 100644 src/content/reference/en/p5/pointLight.mdx create mode 100644 src/content/reference/en/p5/pop.mdx create mode 100644 src/content/reference/en/p5/pow.mdx create mode 100644 src/content/reference/en/p5/preload.mdx create mode 100644 src/content/reference/en/p5/print.mdx create mode 100644 src/content/reference/en/p5/push.mdx create mode 100644 src/content/reference/en/p5/pwinMouseX.mdx create mode 100644 src/content/reference/en/p5/pwinMouseY.mdx create mode 100644 src/content/reference/en/p5/quad.mdx create mode 100644 src/content/reference/en/p5/quadraticVertex.mdx create mode 100644 src/content/reference/en/p5/random.mdx create mode 100644 src/content/reference/en/p5/randomGaussian.mdx create mode 100644 src/content/reference/en/p5/randomSeed.mdx create mode 100644 src/content/reference/en/p5/rect.mdx create mode 100644 src/content/reference/en/p5/rectMode.mdx create mode 100644 src/content/reference/en/p5/red.mdx create mode 100644 src/content/reference/en/p5/redraw.mdx create mode 100644 src/content/reference/en/p5/removeElements.mdx create mode 100644 src/content/reference/en/p5/removeItem.mdx create mode 100644 src/content/reference/en/p5/requestPointerLock.mdx create mode 100644 src/content/reference/en/p5/resetMatrix.mdx create mode 100644 src/content/reference/en/p5/resetShader.mdx create mode 100644 src/content/reference/en/p5/resizeCanvas.mdx create mode 100644 src/content/reference/en/p5/reverse.mdx create mode 100644 src/content/reference/en/p5/rotate.mdx create mode 100644 src/content/reference/en/p5/rotateX.mdx create mode 100644 src/content/reference/en/p5/rotateY.mdx create mode 100644 src/content/reference/en/p5/rotateZ.mdx create mode 100644 src/content/reference/en/p5/rotationX.mdx create mode 100644 src/content/reference/en/p5/rotationY.mdx create mode 100644 src/content/reference/en/p5/rotationZ.mdx create mode 100644 src/content/reference/en/p5/sampleRate.mdx create mode 100644 src/content/reference/en/p5/saturation.mdx create mode 100644 src/content/reference/en/p5/save.mdx create mode 100644 src/content/reference/en/p5/saveCanvas.mdx create mode 100644 src/content/reference/en/p5/saveFrames.mdx create mode 100644 src/content/reference/en/p5/saveGif.mdx create mode 100644 src/content/reference/en/p5/saveJSON.mdx create mode 100644 src/content/reference/en/p5/saveSound.mdx create mode 100644 src/content/reference/en/p5/saveStrings.mdx create mode 100644 src/content/reference/en/p5/saveTable.mdx create mode 100644 src/content/reference/en/p5/scale.mdx create mode 100644 src/content/reference/en/p5/second.mdx create mode 100644 src/content/reference/en/p5/select.mdx create mode 100644 src/content/reference/en/p5/selectAll.mdx create mode 100644 src/content/reference/en/p5/set.mdx create mode 100644 src/content/reference/en/p5/setAttributes.mdx create mode 100644 src/content/reference/en/p5/setBPM.mdx create mode 100644 src/content/reference/en/p5/setCamera.mdx create mode 100644 src/content/reference/en/p5/setMoveThreshold.mdx create mode 100644 src/content/reference/en/p5/setShakeThreshold.mdx create mode 100644 src/content/reference/en/p5/setup.mdx create mode 100644 src/content/reference/en/p5/shader.mdx create mode 100644 src/content/reference/en/p5/shearX.mdx create mode 100644 src/content/reference/en/p5/shearY.mdx create mode 100644 src/content/reference/en/p5/shininess.mdx create mode 100644 src/content/reference/en/p5/shorten.mdx create mode 100644 src/content/reference/en/p5/shuffle.mdx create mode 100644 src/content/reference/en/p5/sin.mdx create mode 100644 src/content/reference/en/p5/smooth.mdx create mode 100644 src/content/reference/en/p5/sort.mdx create mode 100644 src/content/reference/en/p5/soundFormats.mdx create mode 100644 src/content/reference/en/p5/soundOut.mdx create mode 100644 src/content/reference/en/p5/specularColor.mdx create mode 100644 src/content/reference/en/p5/specularMaterial.mdx create mode 100644 src/content/reference/en/p5/sphere.mdx create mode 100644 src/content/reference/en/p5/splice.mdx create mode 100644 src/content/reference/en/p5/split.mdx create mode 100644 src/content/reference/en/p5/splitTokens.mdx create mode 100644 src/content/reference/en/p5/spotLight.mdx create mode 100644 src/content/reference/en/p5/sq.mdx create mode 100644 src/content/reference/en/p5/sqrt.mdx create mode 100644 src/content/reference/en/p5/square.mdx create mode 100644 src/content/reference/en/p5/storeItem.mdx create mode 100644 src/content/reference/en/p5/str.mdx create mode 100644 src/content/reference/en/p5/string.mdx create mode 100644 src/content/reference/en/p5/stroke.mdx create mode 100644 src/content/reference/en/p5/strokeCap.mdx create mode 100644 src/content/reference/en/p5/strokeJoin.mdx create mode 100644 src/content/reference/en/p5/strokeWeight.mdx create mode 100644 src/content/reference/en/p5/subset.mdx create mode 100644 src/content/reference/en/p5/tan.mdx create mode 100644 src/content/reference/en/p5/textAlign.mdx create mode 100644 src/content/reference/en/p5/textAscent.mdx create mode 100644 src/content/reference/en/p5/textDescent.mdx create mode 100644 src/content/reference/en/p5/textFont.mdx create mode 100644 src/content/reference/en/p5/textLeading.mdx create mode 100644 src/content/reference/en/p5/textOutput.mdx create mode 100644 src/content/reference/en/p5/textSize.mdx create mode 100644 src/content/reference/en/p5/textStyle.mdx create mode 100644 src/content/reference/en/p5/textWidth.mdx create mode 100644 src/content/reference/en/p5/textWrap.mdx create mode 100644 src/content/reference/en/p5/textureMode.mdx create mode 100644 src/content/reference/en/p5/textureWrap.mdx create mode 100644 src/content/reference/en/p5/tint.mdx create mode 100644 src/content/reference/en/p5/torus.mdx create mode 100644 src/content/reference/en/p5/touchEnded.mdx create mode 100644 src/content/reference/en/p5/touchMoved.mdx create mode 100644 src/content/reference/en/p5/touchStarted.mdx create mode 100644 src/content/reference/en/p5/touches.mdx create mode 100644 src/content/reference/en/p5/translate.mdx create mode 100644 src/content/reference/en/p5/triangle.mdx create mode 100644 src/content/reference/en/p5/trim.mdx create mode 100644 src/content/reference/en/p5/turnAxis.mdx create mode 100644 src/content/reference/en/p5/unchar.mdx create mode 100644 src/content/reference/en/p5/unhex.mdx create mode 100644 src/content/reference/en/p5/updatePixels.mdx create mode 100644 src/content/reference/en/p5/userStartAudio.mdx create mode 100644 src/content/reference/en/p5/vertex.mdx create mode 100644 src/content/reference/en/p5/webglVersion.mdx create mode 100644 src/content/reference/en/p5/while.mdx create mode 100644 src/content/reference/en/p5/width.mdx create mode 100644 src/content/reference/en/p5/winMouseX.mdx create mode 100644 src/content/reference/en/p5/winMouseY.mdx create mode 100644 src/content/reference/en/p5/windowHeight.mdx create mode 100644 src/content/reference/en/p5/windowResized.mdx create mode 100644 src/content/reference/en/p5/windowWidth.mdx create mode 100644 src/content/reference/en/p5/year.mdx diff --git a/src/content/reference/en/JSON/stringify.mdx b/src/content/reference/en/JSON/stringify.mdx new file mode 100644 index 0000000000..7713922071 --- /dev/null +++ b/src/content/reference/en/JSON/stringify.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stringify +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

From the + MDN entry: + + The JSON.stringify() method converts a JavaScript object or value to a JSON string.

+line: 490 +params: + - name: object + description: | +

:Javascript object that you would like to convert to JSON

+ type: Object +itemtype: method +class: JSON +example: + - |- + +
+ + let myObject = { x: 5, y: 6 }; + let myObjectAsString = JSON.stringify(myObject); + console.log(myObjectAsString); // prints "{"x":5,"y":6}" to the console + console.log(typeof myObjectAsString); // prints 'string' to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# stringify diff --git a/src/content/reference/en/console/log.mdx b/src/content/reference/en/console/log.mdx new file mode 100644 index 0000000000..6dc3c2b7d1 --- /dev/null +++ b/src/content/reference/en/console/log.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: log +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Prints a message to your browser's web console. When using p5, you can use + print + + and console.log interchangeably.

+ +

The console is opened differently depending on which browser you are using. + + Here are links on how to open the console in Firefox + + , Chrome, + Edge, + + and Safari. + + With the online p5 editor the console + + is embedded directly in the page underneath the code editor.

+ +

From the MDN + entry: + + The Console method log() outputs a message to the web console. The message may + + be a single string (with optional substitution + values), + + or it may be any one or more JavaScript objects.

+line: 512 +params: + - name: message + description: | +

:Message that you would like to print to the console

+ type: String|Expression|Object +itemtype: method +class: console +example: + - |- + +
+ + let myNum = 5; + console.log(myNum); // prints 5 to the console + console.log(myNum + 12); // prints 17 to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# log diff --git a/src/content/reference/en/index.mdx b/src/content/reference/en/index.mdx new file mode 100644 index 0000000000..ecdfc3b471 --- /dev/null +++ b/src/content/reference/en/index.mdx @@ -0,0 +1,727 @@ +--- +title: Reference +--- + + +# Reference + +## p5.sound + +### p5.sound + +* [getAudioContext](././src/content/reference/en//p5/getAudioContext/) +* [userStartAudio](././src/content/reference/en//p5/userStartAudio/) +* [getOutputVolume](././src/content/reference/en//p5/getOutputVolume/) +* [outputVolume](././src/content/reference/en//p5/outputVolume/) +* [soundOut](././src/content/reference/en//p5/soundOut/) +* [sampleRate](././src/content/reference/en//p5/sampleRate/) +* [freqToMidi](././src/content/reference/en//p5/freqToMidi/) +* [midiToFreq](././src/content/reference/en//p5/midiToFreq/) +* [soundFormats](././src/content/reference/en//p5/soundFormats/) +* [saveSound](././src/content/reference/en//p5/saveSound/) +* [loadSound](././src/content/reference/en//p5/loadSound/) +* [createConvolver](././src/content/reference/en//p5/createConvolver/) +* [setBPM](././src/content/reference/en//p5/setBPM/) +* [p5.sound](././src/content/reference/en//p5.sound/p5.sound/) +* [p5.SoundFile](././src/content/reference/en//p5.sound/p5.SoundFile/) +* [p5.Amplitude](././src/content/reference/en//p5.sound/p5.Amplitude/) +* [p5.FFT](././src/content/reference/en//p5.sound/p5.FFT/) +* [p5.Oscillator](././src/content/reference/en//p5.sound/p5.Oscillator/) +* [p5.SinOsc](././src/content/reference/en//p5.sound/p5.SinOsc/) +* [p5.TriOsc](././src/content/reference/en//p5.sound/p5.TriOsc/) +* [p5.SawOsc](././src/content/reference/en//p5.sound/p5.SawOsc/) +* [p5.SqrOsc](././src/content/reference/en//p5.sound/p5.SqrOsc/) +* [p5.Envelope](././src/content/reference/en//p5.sound/p5.Envelope/) +* [p5.Noise](././src/content/reference/en//p5.sound/p5.Noise/) +* [p5.Pulse](././src/content/reference/en//p5.sound/p5.Pulse/) +* [p5.AudioIn](././src/content/reference/en//p5.sound/p5.AudioIn/) +* [p5.Effect](././src/content/reference/en//p5.sound/p5.Effect/) +* [p5.Filter](././src/content/reference/en//p5.sound/p5.Filter/) +* [p5.LowPass](././src/content/reference/en//p5.sound/p5.LowPass/) +* [p5.HighPass](././src/content/reference/en//p5.sound/p5.HighPass/) +* [p5.BandPass](././src/content/reference/en//p5.sound/p5.BandPass/) +* [p5.EQ](././src/content/reference/en//p5.sound/p5.EQ/) +* [p5.Panner3D](././src/content/reference/en//p5.sound/p5.Panner3D/) +* [p5.Delay](././src/content/reference/en//p5.sound/p5.Delay/) +* [p5.Reverb](././src/content/reference/en//p5.sound/p5.Reverb/) +* [p5.Convolver](././src/content/reference/en//p5.sound/p5.Convolver/) +* [p5.Phrase](././src/content/reference/en//p5.sound/p5.Phrase/) +* [p5.Part](././src/content/reference/en//p5.sound/p5.Part/) +* [p5.Score](././src/content/reference/en//p5.sound/p5.Score/) +* [p5.SoundLoop](././src/content/reference/en//p5.sound/p5.SoundLoop/) +* [p5.Compressor](././src/content/reference/en//p5.sound/p5.Compressor/) +* [p5.PeakDetect](././src/content/reference/en//p5.sound/p5.PeakDetect/) +* [p5.SoundRecorder](././src/content/reference/en//p5.sound/p5.SoundRecorder/) +* [p5.Distortion](././src/content/reference/en//p5.sound/p5.Distortion/) +* [p5.Gain](././src/content/reference/en//p5.sound/p5.Gain/) +* [p5.AudioVoice](././src/content/reference/en//p5.sound/p5.AudioVoice/) +* [p5.MonoSynth](././src/content/reference/en//p5.sound/p5.MonoSynth/) +* [p5.OnsetDetect](././src/content/reference/en//p5.sound/p5.OnsetDetect/) +* [p5.PolySynth](././src/content/reference/en//p5.sound/p5.PolySynth/) + +## Environment + +### Environment + +* [describe](././src/content/reference/en//p5/describe/) +* [describeElement](././src/content/reference/en//p5/describeElement/) +* [textOutput](././src/content/reference/en//p5/textOutput/) +* [gridOutput](././src/content/reference/en//p5/gridOutput/) +* [print](././src/content/reference/en//p5/print/) +* [frameCount](././src/content/reference/en//p5/frameCount/) +* [deltaTime](././src/content/reference/en//p5/deltaTime/) +* [focused](././src/content/reference/en//p5/focused/) +* [cursor](././src/content/reference/en//p5/cursor/) +* [frameRate](././src/content/reference/en//p5/frameRate/) +* [getTargetFrameRate](././src/content/reference/en//p5/getTargetFrameRate/) +* [noCursor](././src/content/reference/en//p5/noCursor/) +* [webglVersion](././src/content/reference/en//p5/webglVersion/) +* [displayWidth](././src/content/reference/en//p5/displayWidth/) +* [displayHeight](././src/content/reference/en//p5/displayHeight/) +* [windowWidth](././src/content/reference/en//p5/windowWidth/) +* [windowHeight](././src/content/reference/en//p5/windowHeight/) +* [windowResized](././src/content/reference/en//p5/windowResized/) +* [width](././src/content/reference/en//p5/width/) +* [height](././src/content/reference/en//p5/height/) +* [fullscreen](././src/content/reference/en//p5/fullscreen/) +* [pixelDensity](././src/content/reference/en//p5/pixelDensity/) +* [displayDensity](././src/content/reference/en//p5/displayDensity/) +* [getURL](././src/content/reference/en//p5/getURL/) +* [getURLPath](././src/content/reference/en//p5/getURLPath/) +* [getURLParams](././src/content/reference/en//p5/getURLParams/) + +## Color + +### Creating & Reading + +* [alpha](././src/content/reference/en//p5/alpha/) +* [blue](././src/content/reference/en//p5/blue/) +* [brightness](././src/content/reference/en//p5/brightness/) +* [color](././src/content/reference/en//p5/color/) +* [green](././src/content/reference/en//p5/green/) +* [hue](././src/content/reference/en//p5/hue/) +* [lerpColor](././src/content/reference/en//p5/lerpColor/) +* [lightness](././src/content/reference/en//p5/lightness/) +* [red](././src/content/reference/en//p5/red/) +* [saturation](././src/content/reference/en//p5/saturation/) +* [p5.Color](././src/content/reference/en//p5/p5.Color/) + +### Setting + +* [beginClip](././src/content/reference/en//p5/beginClip/) +* [endClip](././src/content/reference/en//p5/endClip/) +* [clip](././src/content/reference/en//p5/clip/) +* [background](././src/content/reference/en//p5/background/) +* [clear](././src/content/reference/en//p5/clear/) +* [colorMode](././src/content/reference/en//p5/colorMode/) +* [fill](././src/content/reference/en//p5/fill/) +* [noFill](././src/content/reference/en//p5/noFill/) +* [noStroke](././src/content/reference/en//p5/noStroke/) +* [stroke](././src/content/reference/en//p5/stroke/) +* [erase](././src/content/reference/en//p5/erase/) +* [noErase](././src/content/reference/en//p5/noErase/) + +## Shape + +### 2D Primitives + +* [arc](././src/content/reference/en//p5/arc/) +* [ellipse](././src/content/reference/en//p5/ellipse/) +* [circle](././src/content/reference/en//p5/circle/) +* [line](././src/content/reference/en//p5/line/) +* [point](././src/content/reference/en//p5/point/) +* [quad](././src/content/reference/en//p5/quad/) +* [rect](././src/content/reference/en//p5/rect/) +* [square](././src/content/reference/en//p5/square/) +* [triangle](././src/content/reference/en//p5/triangle/) + +### Attributes + +* [ellipseMode](././src/content/reference/en//p5/ellipseMode/) +* [noSmooth](././src/content/reference/en//p5/noSmooth/) +* [rectMode](././src/content/reference/en//p5/rectMode/) +* [smooth](././src/content/reference/en//p5/smooth/) +* [strokeCap](././src/content/reference/en//p5/strokeCap/) +* [strokeJoin](././src/content/reference/en//p5/strokeJoin/) +* [strokeWeight](././src/content/reference/en//p5/strokeWeight/) + +### Curves + +* [bezier](././src/content/reference/en//p5/bezier/) +* [bezierDetail](././src/content/reference/en//p5/bezierDetail/) +* [bezierPoint](././src/content/reference/en//p5/bezierPoint/) +* [bezierTangent](././src/content/reference/en//p5/bezierTangent/) +* [curve](././src/content/reference/en//p5/curve/) +* [curveDetail](././src/content/reference/en//p5/curveDetail/) +* [curveTightness](././src/content/reference/en//p5/curveTightness/) +* [curvePoint](././src/content/reference/en//p5/curvePoint/) +* [curveTangent](././src/content/reference/en//p5/curveTangent/) + +### Vertex + +* [beginContour](././src/content/reference/en//p5/beginContour/) +* [beginShape](././src/content/reference/en//p5/beginShape/) +* [bezierVertex](././src/content/reference/en//p5/bezierVertex/) +* [curveVertex](././src/content/reference/en//p5/curveVertex/) +* [endContour](././src/content/reference/en//p5/endContour/) +* [endShape](././src/content/reference/en//p5/endShape/) +* [quadraticVertex](././src/content/reference/en//p5/quadraticVertex/) +* [vertex](././src/content/reference/en//p5/vertex/) +* [normal](././src/content/reference/en//p5/normal/) + +### 3D Primitives + +* [beginGeometry](././src/content/reference/en//p5/beginGeometry/) +* [endGeometry](././src/content/reference/en//p5/endGeometry/) +* [buildGeometry](././src/content/reference/en//p5/buildGeometry/) +* [freeGeometry](././src/content/reference/en//p5/freeGeometry/) +* [plane](././src/content/reference/en//p5/plane/) +* [box](././src/content/reference/en//p5/box/) +* [sphere](././src/content/reference/en//p5/sphere/) +* [cylinder](././src/content/reference/en//p5/cylinder/) +* [cone](././src/content/reference/en//p5/cone/) +* [ellipsoid](././src/content/reference/en//p5/ellipsoid/) +* [torus](././src/content/reference/en//p5/torus/) +* [p5.Geometry](././src/content/reference/en//p5/p5.Geometry/) + +### 3D Models + +* [loadModel](././src/content/reference/en//p5/loadModel/) +* [model](././src/content/reference/en//p5/model/) + +## Constants + +### Constants + +* [VERSION](././src/content/reference/en//p5/VERSION/) +* [P2D](././src/content/reference/en//p5/P2D/) +* [WEBGL](././src/content/reference/en//p5/WEBGL/) +* [WEBGL2](././src/content/reference/en//p5/WEBGL2/) +* [ARROW](././src/content/reference/en//p5/ARROW/) +* [CROSS](././src/content/reference/en//p5/CROSS/) +* [HAND](././src/content/reference/en//p5/HAND/) +* [MOVE](././src/content/reference/en//p5/MOVE/) +* [TEXT](././src/content/reference/en//p5/TEXT/) +* [WAIT](././src/content/reference/en//p5/WAIT/) +* [HALF\_PI](././src/content/reference/en//p5/HALF_PI/) +* [PI](././src/content/reference/en//p5/PI/) +* [QUARTER\_PI](././src/content/reference/en//p5/QUARTER_PI/) +* [TAU](././src/content/reference/en//p5/TAU/) +* [TWO\_PI](././src/content/reference/en//p5/TWO_PI/) +* [DEGREES](././src/content/reference/en//p5/DEGREES/) +* [RADIANS](././src/content/reference/en//p5/RADIANS/) +* [CORNER](././src/content/reference/en//p5/CORNER/) +* [CORNERS](././src/content/reference/en//p5/CORNERS/) +* [RADIUS](././src/content/reference/en//p5/RADIUS/) +* [RIGHT](././src/content/reference/en//p5/RIGHT/) +* [LEFT](././src/content/reference/en//p5/LEFT/) +* [CENTER](././src/content/reference/en//p5/CENTER/) +* [TOP](././src/content/reference/en//p5/TOP/) +* [BOTTOM](././src/content/reference/en//p5/BOTTOM/) +* [BASELINE](././src/content/reference/en//p5/BASELINE/) +* [POINTS](././src/content/reference/en//p5/POINTS/) +* [LINES](././src/content/reference/en//p5/LINES/) +* [LINE\_STRIP](././src/content/reference/en//p5/LINE_STRIP/) +* [LINE\_LOOP](././src/content/reference/en//p5/LINE_LOOP/) +* [TRIANGLES](././src/content/reference/en//p5/TRIANGLES/) +* [TRIANGLE\_FAN](././src/content/reference/en//p5/TRIANGLE_FAN/) +* [TRIANGLE\_STRIP](././src/content/reference/en//p5/TRIANGLE_STRIP/) +* [QUADS](././src/content/reference/en//p5/QUADS/) +* [QUAD\_STRIP](././src/content/reference/en//p5/QUAD_STRIP/) +* [TESS](././src/content/reference/en//p5/TESS/) +* [CLOSE](././src/content/reference/en//p5/CLOSE/) +* [OPEN](././src/content/reference/en//p5/OPEN/) +* [CHORD](././src/content/reference/en//p5/CHORD/) +* [PIE](././src/content/reference/en//p5/PIE/) +* [PROJECT](././src/content/reference/en//p5/PROJECT/) +* [SQUARE](././src/content/reference/en//p5/SQUARE/) +* [ROUND](././src/content/reference/en//p5/ROUND/) +* [BEVEL](././src/content/reference/en//p5/BEVEL/) +* [MITER](././src/content/reference/en//p5/MITER/) +* [RGB](././src/content/reference/en//p5/RGB/) +* [HSB](././src/content/reference/en//p5/HSB/) +* [HSL](././src/content/reference/en//p5/HSL/) +* [AUTO](././src/content/reference/en//p5/AUTO/) +* [ALT](././src/content/reference/en//p5/ALT/) +* [BACKSPACE](././src/content/reference/en//p5/BACKSPACE/) +* [CONTROL](././src/content/reference/en//p5/CONTROL/) +* [DELETE](././src/content/reference/en//p5/DELETE/) +* [DOWN\_ARROW](././src/content/reference/en//p5/DOWN_ARROW/) +* [ENTER](././src/content/reference/en//p5/ENTER/) +* [ESCAPE](././src/content/reference/en//p5/ESCAPE/) +* [LEFT\_ARROW](././src/content/reference/en//p5/LEFT_ARROW/) +* [OPTION](././src/content/reference/en//p5/OPTION/) +* [RETURN](././src/content/reference/en//p5/RETURN/) +* [RIGHT\_ARROW](././src/content/reference/en//p5/RIGHT_ARROW/) +* [SHIFT](././src/content/reference/en//p5/SHIFT/) +* [TAB](././src/content/reference/en//p5/TAB/) +* [UP\_ARROW](././src/content/reference/en//p5/UP_ARROW/) +* [BLEND](././src/content/reference/en//p5/BLEND/) +* [REMOVE](././src/content/reference/en//p5/REMOVE/) +* [ADD](././src/content/reference/en//p5/ADD/) +* [DARKEST](././src/content/reference/en//p5/DARKEST/) +* [LIGHTEST](././src/content/reference/en//p5/LIGHTEST/) +* [DIFFERENCE](././src/content/reference/en//p5/DIFFERENCE/) +* [SUBTRACT](././src/content/reference/en//p5/SUBTRACT/) +* [EXCLUSION](././src/content/reference/en//p5/EXCLUSION/) +* [MULTIPLY](././src/content/reference/en//p5/MULTIPLY/) +* [SCREEN](././src/content/reference/en//p5/SCREEN/) +* [REPLACE](././src/content/reference/en//p5/REPLACE/) +* [OVERLAY](././src/content/reference/en//p5/OVERLAY/) +* [HARD\_LIGHT](././src/content/reference/en//p5/HARD_LIGHT/) +* [SOFT\_LIGHT](././src/content/reference/en//p5/SOFT_LIGHT/) +* [DODGE](././src/content/reference/en//p5/DODGE/) +* [BURN](././src/content/reference/en//p5/BURN/) +* [THRESHOLD](././src/content/reference/en//p5/THRESHOLD/) +* [GRAY](././src/content/reference/en//p5/GRAY/) +* [OPAQUE](././src/content/reference/en//p5/OPAQUE/) +* [INVERT](././src/content/reference/en//p5/INVERT/) +* [POSTERIZE](././src/content/reference/en//p5/POSTERIZE/) +* [DILATE](././src/content/reference/en//p5/DILATE/) +* [ERODE](././src/content/reference/en//p5/ERODE/) +* [BLUR](././src/content/reference/en//p5/BLUR/) +* [NORMAL](././src/content/reference/en//p5/NORMAL/) +* [ITALIC](././src/content/reference/en//p5/ITALIC/) +* [BOLD](././src/content/reference/en//p5/BOLD/) +* [BOLDITALIC](././src/content/reference/en//p5/BOLDITALIC/) +* [CHAR](././src/content/reference/en//p5/CHAR/) +* [WORD](././src/content/reference/en//p5/WORD/) +* [LINEAR](././src/content/reference/en//p5/LINEAR/) +* [QUADRATIC](././src/content/reference/en//p5/QUADRATIC/) +* [BEZIER](././src/content/reference/en//p5/BEZIER/) +* [CURVE](././src/content/reference/en//p5/CURVE/) +* [STROKE](././src/content/reference/en//p5/STROKE/) +* [FILL](././src/content/reference/en//p5/FILL/) +* [TEXTURE](././src/content/reference/en//p5/TEXTURE/) +* [IMMEDIATE](././src/content/reference/en//p5/IMMEDIATE/) +* [IMAGE](././src/content/reference/en//p5/IMAGE/) +* [NEAREST](././src/content/reference/en//p5/NEAREST/) +* [REPEAT](././src/content/reference/en//p5/REPEAT/) +* [CLAMP](././src/content/reference/en//p5/CLAMP/) +* [MIRROR](././src/content/reference/en//p5/MIRROR/) +* [FLAT](././src/content/reference/en//p5/FLAT/) +* [SMOOTH](././src/content/reference/en//p5/SMOOTH/) +* [LANDSCAPE](././src/content/reference/en//p5/LANDSCAPE/) +* [PORTRAIT](././src/content/reference/en//p5/PORTRAIT/) +* [GRID](././src/content/reference/en//p5/GRID/) +* [AXES](././src/content/reference/en//p5/AXES/) +* [LABEL](././src/content/reference/en//p5/LABEL/) +* [FALLBACK](././src/content/reference/en//p5/FALLBACK/) +* [CONTAIN](././src/content/reference/en//p5/CONTAIN/) +* [COVER](././src/content/reference/en//p5/COVER/) +* [UNSIGNED\_BYTE](././src/content/reference/en//p5/UNSIGNED_BYTE/) +* [UNSIGNED\_INT](././src/content/reference/en//p5/UNSIGNED_INT/) +* [FLOAT](././src/content/reference/en//p5/FLOAT/) +* [HALF\_FLOAT](././src/content/reference/en//p5/HALF_FLOAT/) +* [RGBA](././src/content/reference/en//p5/RGBA/) + +## Structure + +### Structure + +* [preload](././src/content/reference/en//p5/preload/) +* [setup](././src/content/reference/en//p5/setup/) +* [draw](././src/content/reference/en//p5/draw/) +* [remove](././src/content/reference/en//p5/remove/) +* [disableFriendlyErrors](././src/content/reference/en//p5/disableFriendlyErrors/) +* [noLoop](././src/content/reference/en//p5/noLoop/) +* [loop](././src/content/reference/en//p5/loop/) +* [isLooping](././src/content/reference/en//p5/isLooping/) +* [push](././src/content/reference/en//p5/push/) +* [pop](././src/content/reference/en//p5/pop/) +* [redraw](././src/content/reference/en//p5/redraw/) +* [p5](././src/content/reference/en//p5/p5/) + +## Foundation + +### Foundation + +* [let](././src/content/reference/en//p5/let/) +* [const](././src/content/reference/en//p5/const/) +* [===](././src/content/reference/en//p5/===/) +* [>](././src/content/reference/en//p5/>/) +* [>=](././src/content/reference/en//p5/>=/) +* [\<](././src/content/reference/en//p5/\Returns a single Amplitude reading at the moment it is called. + For continuous readings, run in the draw loop.

+line: 3209 +params: + - name: channel + description: | +

Optionally return only channel 0 (left) or 1 (right)

+ type: Number + optional: true +itemtype: method +class: p5.Amplitude +example: + - |- + +
+ function preload(){ + sound = loadSound('assets/beat.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mouseClicked(toggleSound); + amplitude = new p5.Amplitude(); + } + + function draw() { + background(220, 150); + textAlign(CENTER); + text('tap to play', width/2, 20); + + let level = amplitude.getLevel(); + let size = map(level, 0, 1, 0, 200); + ellipse(width/2, height/2, size, size); + } + + function toggleSound(){ + if (sound.isPlaying()) { + sound.stop(); + } else { + sound.play(); + } + } +
+return: + description: Amplitude as a number between 0.0 and 1.0 + type: Number +chainable: false +--- + + +# getLevel diff --git a/src/content/reference/en/p5.Amplitude/setInput.mdx b/src/content/reference/en/p5.Amplitude/setInput.mdx new file mode 100644 index 0000000000..7d76706367 --- /dev/null +++ b/src/content/reference/en/p5.Amplitude/setInput.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setInput +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connects to the p5sound instance (main output) by default. + Optionally, you can pass in a specific source (i.e. a soundfile).

+line: 3117 +params: + - name: snd + description: | +

set the sound source + (optional, defaults to + main output)

+ type: SoundObject|undefined + optional: true + - name: smoothing + description: | +

a range between 0.0 and 1.0 + to smooth amplitude readings

+ type: Number|undefined + optional: true +itemtype: method +class: p5.Amplitude +example: + - |- + +
+ function preload(){ + sound1 = loadSound('assets/beat.mp3'); + sound2 = loadSound('assets/drum.mp3'); + } + function setup(){ + cnv = createCanvas(100, 100); + cnv.mouseClicked(toggleSound); + + amplitude = new p5.Amplitude(); + amplitude.setInput(sound2); + } + + function draw() { + background(220); + text('tap to play', 20, 20); + + let level = amplitude.getLevel(); + let size = map(level, 0, 1, 0, 200); + ellipse(width/2, height/2, size, size); + } + + function toggleSound(){ + if (sound1.isPlaying() && sound2.isPlaying()) { + sound1.stop(); + sound2.stop(); + } else { + sound1.play(); + sound2.play(); + } + } +
+chainable: false +--- + + +# setInput diff --git a/src/content/reference/en/p5.Amplitude/smooth.mdx b/src/content/reference/en/p5.Amplitude/smooth.mdx new file mode 100644 index 0000000000..68e6950792 --- /dev/null +++ b/src/content/reference/en/p5.Amplitude/smooth.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: smooth +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Smooth Amplitude analysis by averaging with the last analysis + frame. Off by default.

+line: 3293 +params: + - name: set + description: | +

smoothing from 0.0 <= 1

+ type: Number +itemtype: method +class: p5.Amplitude +chainable: false +--- + + +# smooth diff --git a/src/content/reference/en/p5.Amplitude/toggleNormalize.mdx b/src/content/reference/en/p5.Amplitude/toggleNormalize.mdx new file mode 100644 index 0000000000..b9d7204a21 --- /dev/null +++ b/src/content/reference/en/p5.Amplitude/toggleNormalize.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toggleNormalize +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Determines whether the results of Amplitude.process() will be + Normalized. To normalize, Amplitude finds the difference the + loudest reading it has processed and the maximum amplitude of + 1.0. Amplitude adds this difference to all values to produce + results that will reliably map between 0.0 and 1.0. However, + if a louder moment occurs, the amount that Normalize adds to + all the values will change. Accepts an optional boolean parameter + (true or false). Normalizing is off by default.

+line: 3264 +params: + - name: boolean + description: | +

set normalize to true (1) or false (0)

+ type: Boolean + optional: true +itemtype: method +class: p5.Amplitude +chainable: false +--- + + +# toggleNormalize diff --git a/src/content/reference/en/p5.AudioIn/amp.mdx b/src/content/reference/en/p5.AudioIn/amp.mdx new file mode 100644 index 0000000000..58d38b3d9a --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/amp.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set amplitude (volume) of a mic input between 0 and 1.0.

+line: 6257 +params: + - name: vol + description: | +

between 0 and 1.0

+ type: Number + - name: time + description: | +

ramp time (optional)

+ type: Number + optional: true +itemtype: method +class: p5.AudioIn +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.AudioIn/amplitude.mdx b/src/content/reference/en/p5.AudioIn/amplitude.mdx new file mode 100644 index 0000000000..5bfa93272d --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/amplitude.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amplitude +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Input amplitude, connect to it by default but not to master out

+line: 6098 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# amplitude diff --git a/src/content/reference/en/p5.AudioIn/connect.mdx b/src/content/reference/en/p5.AudioIn/connect.mdx new file mode 100644 index 0000000000..a08dc2d603 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/connect.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect to an audio unit. If no parameter is provided, will + connect to the main output (i.e. your speakers).

+line: 6191 +params: + - name: unit + description: | +

An object that accepts audio input, + such as an FFT

+ type: Object + optional: true +itemtype: method +class: p5.AudioIn +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.AudioIn/currentSource.mdx b/src/content/reference/en/p5.AudioIn/currentSource.mdx new file mode 100644 index 0000000000..6f501cfc1d --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/currentSource.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: currentSource +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 6085 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# currentSource diff --git a/src/content/reference/en/p5.AudioIn/disconnect.mdx b/src/content/reference/en/p5.AudioIn/disconnect.mdx new file mode 100644 index 0000000000..06bbb68a98 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/disconnect.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect the AudioIn from all audio units. For example, if + connect() had been called, disconnect() will stop sending + signal to your speakers.

+line: 6216 +itemtype: method +class: p5.AudioIn +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.AudioIn/enabled.mdx b/src/content/reference/en/p5.AudioIn/enabled.mdx new file mode 100644 index 0000000000..303204606b --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/enabled.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: enabled +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Client must allow browser to access their microphone / audioin source. + Default: false. Will become true when the client enables access.

+line: 6090 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# enabled diff --git a/src/content/reference/en/p5.AudioIn/getLevel.mdx b/src/content/reference/en/p5.AudioIn/getLevel.mdx new file mode 100644 index 0000000000..d8b0c8c4be --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/getLevel.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getLevel +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Read the Amplitude (volume level) of an AudioIn. The AudioIn + class contains its own instance of the Amplitude class to help + make it easy to get a microphone's volume level. Accepts an + optional smoothing value (0.0 < 1.0). NOTE: AudioIn must + .start() before using .getLevel().

+line: 6234 +params: + - name: smoothing + description: | +

Smoothing is 0.0 by default. + Smooths values based on previous values.

+ type: Number + optional: true +itemtype: method +class: p5.AudioIn +return: + description: Volume level (between 0.0 and 1.0) + type: Number +chainable: false +--- + + +# getLevel diff --git a/src/content/reference/en/p5.AudioIn/getSources.mdx b/src/content/reference/en/p5.AudioIn/getSources.mdx new file mode 100644 index 0000000000..23728ecc22 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/getSources.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getSources +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns a list of available input sources. This is a wrapper + for + MediaDevices.enumerateDevices() - Web APIs | MDN + and it returns a Promise.

+line: 6280 +params: + - name: successCallback + description: | +

This callback function handles the sources when they + have been enumerated. The callback function + receives the deviceList array as its only argument

+ type: Function + optional: true + - name: errorCallback + description: | +

This optional callback receives the error + message as its argument.

+ type: Function + optional: true +itemtype: method +class: p5.AudioIn +example: + - |2- + +
+ let audioIn; + + function setup(){ + text('getting sources...', 0, 20); + audioIn = new p5.AudioIn(); + audioIn.getSources(gotSources); + } + + function gotSources(deviceList) { + if (deviceList.length > 0) { + //set the source to the first item in the deviceList array + audioIn.setSource(0); + let currentSource = deviceList[audioIn.currentSource]; + text('set source to: ' + currentSource.deviceId, 5, 20, width); + } + } +
+return: + description: |- + Returns a Promise that can be used in place of the callbacks, similar + to the enumerateDevices() method + type: Promise +chainable: false +--- + + +# getSources diff --git a/src/content/reference/en/p5.AudioIn/input.mdx b/src/content/reference/en/p5.AudioIn/input.mdx new file mode 100644 index 0000000000..37f61b66ed --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/input.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: input +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 6066 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# input diff --git a/src/content/reference/en/p5.AudioIn/mediaStream.mdx b/src/content/reference/en/p5.AudioIn/mediaStream.mdx new file mode 100644 index 0000000000..497ad0ae08 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/mediaStream.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mediaStream +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 6080 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# mediaStream diff --git a/src/content/reference/en/p5.AudioIn/output.mdx b/src/content/reference/en/p5.AudioIn/output.mdx new file mode 100644 index 0000000000..40d61a1e94 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/output.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: output +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 6070 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# output diff --git a/src/content/reference/en/p5.AudioIn/setSource.mdx b/src/content/reference/en/p5.AudioIn/setSource.mdx new file mode 100644 index 0000000000..6315b48234 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/setSource.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setSource +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the input source. Accepts a number representing a + position in the array returned by getSources(). + This is only available in browsers that support + + navigator.mediaDevices.enumerateDevices()

+line: 6340 +params: + - name: num + description: | +

position of input source in the array

+ type: Number +itemtype: method +class: p5.AudioIn +example: + - |- + +
+ let audioIn; + + function setup(){ + text('getting sources...', 0, 20); + audioIn = new p5.AudioIn(); + audioIn.getSources(gotSources); + } + + function gotSources(deviceList) { + if (deviceList.length > 0) { + //set the source to the first item in the deviceList array + audioIn.setSource(0); + let currentSource = deviceList[audioIn.currentSource]; + text('set source to: ' + currentSource.deviceId, 5, 20, width); + } + } +
+chainable: false +--- + + +# setSource diff --git a/src/content/reference/en/p5.AudioIn/start.mdx b/src/content/reference/en/p5.AudioIn/start.mdx new file mode 100644 index 0000000000..07e9ec0774 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/start.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: start +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start processing audio input. This enables the use of other + AudioIn methods like getLevel(). Note that by default, AudioIn + is not connected to p5.sound's output. So you won't hear + anything unless you use the connect() method.

+

Certain browsers limit access to the user's microphone. For example, + Chrome only allows access from localhost and over https. For this reason, + you may want to include an errorCallback—a function that is called in case + the browser won't provide mic access.

+line: 6114 +params: + - name: successCallback + description: | +

Name of a function to call on + success.

+ type: Function + optional: true + - name: errorCallback + description: | +

Name of a function to call if + there was an error. For example, + some browsers do not support + getUserMedia.

+ type: Function + optional: true +itemtype: method +class: p5.AudioIn +chainable: false +--- + + +# start diff --git a/src/content/reference/en/p5.AudioIn/stop.mdx b/src/content/reference/en/p5.AudioIn/stop.mdx new file mode 100644 index 0000000000..52eb8d4cb4 --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/stop.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Turn the AudioIn off. If the AudioIn is stopped, it cannot getLevel(). + If re-starting, the user may be prompted for permission access.

+line: 6171 +itemtype: method +class: p5.AudioIn +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.AudioIn/stream.mdx b/src/content/reference/en/p5.AudioIn/stream.mdx new file mode 100644 index 0000000000..a2af40ce7a --- /dev/null +++ b/src/content/reference/en/p5.AudioIn/stream.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stream +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 6075 +itemtype: property +class: p5.AudioIn +chainable: false +--- + + +# stream diff --git a/src/content/reference/en/p5.AudioVoice/connect.mdx b/src/content/reference/en/p5.AudioVoice/connect.mdx new file mode 100644 index 0000000000..e7cf30fca3 --- /dev/null +++ b/src/content/reference/en/p5.AudioVoice/connect.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect to p5 objects or Web Audio Nodes

+line: 11181 +params: + - name: unit + description: '' + type: Object +itemtype: method +class: p5.AudioVoice +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.AudioVoice/disconnect.mdx b/src/content/reference/en/p5.AudioVoice/disconnect.mdx new file mode 100644 index 0000000000..439f83e508 --- /dev/null +++ b/src/content/reference/en/p5.AudioVoice/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect from soundOut

+line: 11194 +itemtype: method +class: p5.AudioVoice +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Camera/camera.mdx b/src/content/reference/en/p5.Camera/camera.mdx new file mode 100644 index 0000000000..79b3b1977a --- /dev/null +++ b/src/content/reference/en/p5.Camera/camera.mdx @@ -0,0 +1,96 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: camera +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets the camera's position and orientation. + Accepts the same parameters as the global + camera(). + More information on this function can be found there.

+line: 1250 +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + // Create a camera. + // createCamera() sets the newly created camera as + // the current (active) camera. + cam = createCamera(); + } + + function draw() { + background(204); + // Move the camera away from the plane by a sin wave + cam.camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0); + plane(10, 10); + } + +
+ - |- + +
+ + // move slider to see changes! + // sliders control the first 6 parameters of camera() + + let sliderGroup = []; + let X; + let Y; + let Z; + let centerX; + let centerY; + let centerZ; + let h = 20; + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + // create a camera + cam = createCamera(); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // create sliders + for (var i = 0; i < 6; i++) { + if (i === 2) { + sliderGroup[i] = createSlider(10, 400, 200); + } else { + sliderGroup[i] = createSlider(-400, 400, 0); + } + h = map(i, 0, 6, 5, 85); + sliderGroup[i].position(10, height + h); + sliderGroup[i].style('width', '80px'); + } + } + + function draw() { + background(60); + // assigning sliders' value to each parameters + X = sliderGroup[0].value(); + Y = sliderGroup[1].value(); + Z = sliderGroup[2].value(); + centerX = sliderGroup[3].value(); + centerY = sliderGroup[4].value(); + centerZ = sliderGroup[5].value(); + cam.camera(X, Y, Z, centerX, centerY, centerZ, 0, 1, 0); + stroke(255); + fill(255, 102, 94); + box(85); + } + +
+alt: |- + An interactive example of a red cube with 3 sliders for moving it across x, y, + z axis and 3 sliders for shifting its center. +chainable: false +--- + + +# camera diff --git a/src/content/reference/en/p5.Camera/centerX.mdx b/src/content/reference/en/p5.Camera/centerX.mdx new file mode 100644 index 0000000000..07226939e3 --- /dev/null +++ b/src/content/reference/en/p5.Camera/centerX.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: centerX +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

x coordinate representing center of the sketch

+line: 580 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + cam.lookAt(1, 0, 0); + div = createDiv('centerX = ' + cam.centerX); + div.position(0, 0); + div.style('color', 'white'); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# centerX diff --git a/src/content/reference/en/p5.Camera/centerY.mdx b/src/content/reference/en/p5.Camera/centerY.mdx new file mode 100644 index 0000000000..2d3929245f --- /dev/null +++ b/src/content/reference/en/p5.Camera/centerY.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: centerY +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

y coordinate representing center of the sketch

+line: 609 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + cam.lookAt(0, 1, 0); + div = createDiv('centerY = ' + cam.centerY); + div.position(0, 0); + div.style('color', 'white'); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# centerY diff --git a/src/content/reference/en/p5.Camera/centerZ.mdx b/src/content/reference/en/p5.Camera/centerZ.mdx new file mode 100644 index 0000000000..89219804cf --- /dev/null +++ b/src/content/reference/en/p5.Camera/centerZ.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: centerZ +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

z coordinate representing center of the sketch

+line: 638 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + cam.lookAt(0, 0, 1); + div = createDiv('centerZ = ' + cam.centerZ); + div.position(0, 0); + div.style('color', 'white'); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# centerZ diff --git a/src/content/reference/en/p5.Camera/eyeX.mdx b/src/content/reference/en/p5.Camera/eyeX.mdx new file mode 100644 index 0000000000..c5405bc06e --- /dev/null +++ b/src/content/reference/en/p5.Camera/eyeX.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: eyeX +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

camera position value on x axis. default value is 0

+line: 495 +itemtype: property +class: p5.Camera +example: + - |- + + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(0); + cam = createCamera(); + div = createDiv(); + div.position(0, 0); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + div.html('eyeX = ' + cam.eyeX); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# eyeX diff --git a/src/content/reference/en/p5.Camera/eyeY.mdx b/src/content/reference/en/p5.Camera/eyeY.mdx new file mode 100644 index 0000000000..d90b8291c4 --- /dev/null +++ b/src/content/reference/en/p5.Camera/eyeY.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: eyeY +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

camera position value on y axis. default value is 0

+line: 524 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(0); + cam = createCamera(); + div = createDiv(); + div.position(0, 0); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + div.html('eyeY = ' + cam.eyeY); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# eyeY diff --git a/src/content/reference/en/p5.Camera/eyeZ.mdx b/src/content/reference/en/p5.Camera/eyeZ.mdx new file mode 100644 index 0000000000..596ddfa502 --- /dev/null +++ b/src/content/reference/en/p5.Camera/eyeZ.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: eyeZ +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

camera position value on z axis. default value is 800

+line: 552 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(0); + cam = createCamera(); + div = createDiv(); + div.position(0, 0); + describe('An example showing the use of camera object properties'); + } + + function draw() { + orbitControl(); + box(10); + div.html('eyeZ = ' + cam.eyeZ); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# eyeZ diff --git a/src/content/reference/en/p5.Camera/frustum.mdx b/src/content/reference/en/p5.Camera/frustum.mdx new file mode 100644 index 0000000000..0c4ac07dac --- /dev/null +++ b/src/content/reference/en/p5.Camera/frustum.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: frustum +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets the camera's frustum. + Accepts the same parameters as the global + frustum(). + More information on this function can be found there.

+line: 930 +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam; + + function setup() { + x = createCanvas(100, 100, WEBGL); + setAttributes('antialias', true); + // create a camera + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + // set its frustum + cam.frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200); + } + + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateY(-0.2); + rotateX(-0.3); + push(); + translate(-15, 0, sin(frameCount / 30) * 25); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 25); + box(30); + pop(); + } + +
+alt: >- + two 3D boxes move back and forth along same plane, rotating as mouse is + dragged. +chainable: false +--- + + +# frustum diff --git a/src/content/reference/en/p5.Camera/lookAt.mdx b/src/content/reference/en/p5.Camera/lookAt.mdx new file mode 100644 index 0000000000..063ec855d7 --- /dev/null +++ b/src/content/reference/en/p5.Camera/lookAt.mdx @@ -0,0 +1,73 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lookAt +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Reorients the camera to look at a position in world space.

+line: 1181 +params: + - name: x + description: | +

x position of a point in world space

+ type: Number + - name: 'y' + description: | +

y position of a point in world space

+ type: Number + - name: z + description: | +

z position of a point in world space

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + + function draw() { + background(200); + + // look at a new random point every 60 frames + if (frameCount % 60 === 0) { + cam.lookAt(random(-100, 100), random(-50, 50), 0); + } + + rotateX(frameCount * 0.01); + translate(-100, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + } + +
+alt: |- + camera view of rotating 3D cubes changes to look at a new random + point every second . +chainable: false +--- + + +# lookAt diff --git a/src/content/reference/en/p5.Camera/move.mdx b/src/content/reference/en/p5.Camera/move.mdx new file mode 100644 index 0000000000..7524d98ee2 --- /dev/null +++ b/src/content/reference/en/p5.Camera/move.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: move +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

Move camera along its local axes while maintaining current camera + orientation.

+line: 1398 +params: + - name: x + description: | +

amount to move along camera's left-right axis

+ type: Number + - name: 'y' + description: | +

amount to move along camera's up-down axis

+ type: Number + - name: z + description: | +

amount to move along camera's forward-backward axis

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + // see the camera move along its own axes while maintaining its orientation + let cam; + let delta = 0.5; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + + function draw() { + background(200); + + // move the camera along its local axes + cam.move(delta, delta, 0); + + // every 100 frames, switch direction + if (frameCount % 150 === 0) { + delta *= -1; + } + + translate(-10, -10, 0); + box(50, 8, 50); + translate(15, 15, 0); + box(50, 8, 50); + translate(15, 15, 0); + box(50, 8, 50); + translate(15, 15, 0); + box(50, 8, 50); + translate(15, 15, 0); + box(50, 8, 50); + translate(15, 15, 0); + box(50, 8, 50); + } + +
+alt: |- + camera view moves along a series of 3D boxes, maintaining the same + orientation throughout the move +chainable: false +--- + + +# move diff --git a/src/content/reference/en/p5.Camera/ortho.mdx b/src/content/reference/en/p5.Camera/ortho.mdx new file mode 100644 index 0000000000..d1a400ca8f --- /dev/null +++ b/src/content/reference/en/p5.Camera/ortho.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ortho +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets an orthographic projection. + Accepts the same parameters as the global + ortho(). + More information on this function can be found there.

+line: 846 +itemtype: method +class: p5.Camera +example: + - |- + +
+ + // drag the mouse to look around! + // there's no vanishing point + + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + // create a camera + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + // give it an orthographic projection + cam.ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500); + } + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateX(0.2); + rotateY(-0.2); + push(); + translate(-15, 0, sin(frameCount / 30) * 65); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 65); + box(30); + pop(); + } + +
+alt: >- + two 3D boxes move back and forth along same plane, rotating as mouse is + dragged. +chainable: false +--- + + +# ortho diff --git a/src/content/reference/en/p5.Camera/pan.mdx b/src/content/reference/en/p5.Camera/pan.mdx new file mode 100644 index 0000000000..b7cfc8da27 --- /dev/null +++ b/src/content/reference/en/p5.Camera/pan.mdx @@ -0,0 +1,71 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pan +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Panning rotates the camera view to the left and right.

+line: 1061 +params: + - name: angle + description: | +

amount to rotate camera in current + angleMode units. + Greater than 0 values rotate counterclockwise (to the left).

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam; + let delta = 0.01; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // set initial pan angle + cam.pan(-0.8); + } + + function draw() { + background(200); + + // pan camera according to angle 'delta' + cam.pan(delta); + + // every 160 frames, switch direction + if (frameCount % 160 === 0) { + delta *= -1; + } + + rotateX(frameCount * 0.01); + translate(-100, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + } + +
+alt: camera view pans left and right across a series of rotating 3D boxes. +chainable: false +--- + + +# pan diff --git a/src/content/reference/en/p5.Camera/perspective.mdx b/src/content/reference/en/p5.Camera/perspective.mdx new file mode 100644 index 0000000000..4f0983e02a --- /dev/null +++ b/src/content/reference/en/p5.Camera/perspective.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: perspective +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets a perspective projection. + Accepts the same parameters as the global + perspective(). + More information on this function can be found there.

+line: 743 +itemtype: method +class: p5.Camera +example: + - |- + +
+ + // drag the mouse to look around! + + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + // create a camera + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + // give it a perspective projection + cam.perspective(PI / 3.0, width / height, 0.1, 500); + } + + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateX(-0.3); + rotateY(-0.2); + translate(0, 0, -50); + + push(); + translate(-15, 0, sin(frameCount / 30) * 65); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 65); + box(30); + pop(); + } + +
+alt: 'two colored 3D boxes move back and forth, rotating as mouse is dragged.' +chainable: false +--- + + +# perspective diff --git a/src/content/reference/en/p5.Camera/set.mdx b/src/content/reference/en/p5.Camera/set.mdx new file mode 100644 index 0000000000..782c8fdef6 --- /dev/null +++ b/src/content/reference/en/p5.Camera/set.mdx @@ -0,0 +1,67 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Copies information about the argument camera's view and projection to + the target camera. If the target camera is active, it will be reflected + on the screen.

+line: 1536 +params: + - name: cam + description: | +

source camera

+ type: p5.Camera +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam, initialCam; + + function setup() { + createCanvas(100, 100, WEBGL); + strokeWeight(3); + + // Set the initial state to initialCamera and set it to the camera + // used for drawing. Then set cam to be the active camera. + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + initialCam = createCamera(); + initialCam.camera(100, 100, 100, 0, 0, 0, 0, 0, -1); + initialCam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + cam.set(initialCam); + + setCamera(cam); + } + + function draw() { + orbitControl(); + background(255); + box(50); + translate(0, 0, -25); + plane(100); + } + + function doubleClicked(){ + // Double-click to return the camera to its initial position. + cam.set(initialCam); + } + +
+alt: |- + Prepare two cameras. One is the camera that sets the initial state, + and the other is the camera that moves with interaction. + Draw a plane and a box on top of it, operate the camera using orbitControl(). + Double-click to set the camera in the initial state and return to + the initial state. +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Camera/setPosition.mdx b/src/content/reference/en/p5.Camera/setPosition.mdx new file mode 100644 index 0000000000..babdebe1f6 --- /dev/null +++ b/src/content/reference/en/p5.Camera/setPosition.mdx @@ -0,0 +1,68 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setPosition +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Set camera position in world-space while maintaining current camera + orientation.

+line: 1472 +params: + - name: x + description: | +

x position of a point in world space

+ type: Number + - name: 'y' + description: | +

y position of a point in world space

+ type: Number + - name: z + description: | +

z position of a point in world space

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + // press '1' '2' or '3' keys to set camera position + + let cam; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + + function draw() { + background(200); + + // '1' key + if (keyIsDown(49)) { + cam.setPosition(30, 0, 80); + } + // '2' key + if (keyIsDown(50)) { + cam.setPosition(0, 0, 80); + } + // '3' key + if (keyIsDown(51)) { + cam.setPosition(-30, 0, 80); + } + + box(20); + } + +
+alt: 'camera position changes as the user presses keys, altering view of a 3D box' +chainable: false +--- + + +# setPosition diff --git a/src/content/reference/en/p5.Camera/slerp.mdx b/src/content/reference/en/p5.Camera/slerp.mdx new file mode 100644 index 0000000000..3d6edca967 --- /dev/null +++ b/src/content/reference/en/p5.Camera/slerp.mdx @@ -0,0 +1,158 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: slerp +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

For the cameras cam0 and cam1 with the given arguments, their view are + combined + + with the parameter amt that represents the quantity, and the obtained view is + applied. + + For example, if cam0 is looking straight ahead and cam1 is looking straight + + to the right and amt is 0.5, the applied camera will look to the halfway + + between front and right. + + If the applied camera is active, the applied result will be reflected on the + screen. + + When applying this function, all cameras involved must have exactly the same + projection + + settings. For example, if one is perspective, ortho, frustum, the other two + must also be + + perspective, ortho, frustum respectively. However, if all cameras have ortho + settings, + + interpolation is possible if the ratios of left, right, top and bottom are + equal to each other. + + For example, when it is changed by orbitControl().

+line: 1609 +params: + - name: cam0 + description: | +

first p5.Camera

+ type: p5.Camera + - name: cam1 + description: | +

second p5.Camera

+ type: p5.Camera + - name: amt + description: | +

amount to use for interpolation during slerp

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam0, cam1, cam; + function setup() { + createCanvas(100, 100, WEBGL); + strokeWeight(3); + + // camera for slerp. + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // cam0 is looking at the cube from the front. + cam0 = createCamera(); + cam0.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam0.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // cam1 is pointing straight to the right in the cube + // at the same position as cam0 by doing a pan(-PI/2). + cam1 = createCamera(); + cam1.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam1.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + cam1.pan(-PI/2); + + // we only use cam. + setCamera(cam); + } + + function draw() { + // calculate amount. + const amt = 0.5 - 0.5 * cos(frameCount * TAU / 120); + // slerp cam0 and cam1 with amt, set to cam. + // When amt moves from 0 to 1, cam moves from cam0 to cam1, + // shaking the camera to the right. + cam.slerp(cam0, cam1, amt); + + background(255); + // Every time the camera turns right, the cube drifts left. + box(40); + } + +
+ - |- + +
+ + let cam, lastCam, initialCam; + let countForReset = 30; + // This sample uses orbitControl() to move the camera. + // Double-clicking the canvas restores the camera to its initial state. + function setup() { + createCanvas(100, 100, WEBGL); + strokeWeight(3); + + // main camera + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // Camera for recording loc info before reset + lastCam = createCamera(); + lastCam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + lastCam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // Camera for recording the initial state + initialCam = createCamera(); + initialCam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + initialCam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + + setCamera(cam); // set main camera + } + + function draw() { + if (countForReset < 30) { + // if the reset count is less than 30, + // it will move closer to the original camera as it increases. + countForReset++; + cam.slerp(lastCam, initialCam, countForReset / 30); + } else { + // if the count is 30, + // you can freely move the main camera with orbitControl(). + orbitControl(); + } + + background(255); + box(40); + } + // A double-click sets countForReset to 0 and initiates a reset. + function doubleClicked() { + if (countForReset === 30) { + countForReset = 0; + lastCam.set(cam); + } + } + +
+alt: >- + There is a camera, drawing a cube. The camera can be moved freely with + + orbitControl(). Double-click to smoothly return the camera to its initial + state. + + The camera cannot be moved during that time. +chainable: false +--- + + +# slerp diff --git a/src/content/reference/en/p5.Camera/tilt.mdx b/src/content/reference/en/p5.Camera/tilt.mdx new file mode 100644 index 0000000000..49583abb1f --- /dev/null +++ b/src/content/reference/en/p5.Camera/tilt.mdx @@ -0,0 +1,71 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: tilt +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Tilting rotates the camera view up and down.

+line: 1121 +params: + - name: angle + description: | +

amount to rotate camera in current + angleMode units. + Greater than 0 values rotate counterclockwise (to the left).

+ type: Number +itemtype: method +class: p5.Camera +example: + - |- + +
+ + let cam; + let delta = 0.01; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // set initial tilt + cam.tilt(-0.8); + } + + function draw() { + background(200); + + // pan camera according to angle 'delta' + cam.tilt(delta); + + // every 160 frames, switch direction + if (frameCount % 160 === 0) { + delta *= -1; + } + + rotateY(frameCount * 0.01); + translate(0, -100, 0); + box(20); + translate(0, 35, 0); + box(20); + translate(0, 35, 0); + box(20); + translate(0, 35, 0); + box(20); + translate(0, 35, 0); + box(20); + translate(0, 35, 0); + box(20); + translate(0, 35, 0); + box(20); + } + +
+alt: camera view tilts up and down across a series of rotating 3D boxes. +chainable: false +--- + + +# tilt diff --git a/src/content/reference/en/p5.Camera/upX.mdx b/src/content/reference/en/p5.Camera/upX.mdx new file mode 100644 index 0000000000..417ddd1ff8 --- /dev/null +++ b/src/content/reference/en/p5.Camera/upX.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: upX +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

x component of direction 'up' from camera

+line: 667 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + div = createDiv('upX = ' + cam.upX); + div.position(0, 0); + div.style('color', 'blue'); + div.style('font-size', '18px'); + describe('An example showing the use of camera object properties'); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# upX diff --git a/src/content/reference/en/p5.Camera/upY.mdx b/src/content/reference/en/p5.Camera/upY.mdx new file mode 100644 index 0000000000..7f90610d26 --- /dev/null +++ b/src/content/reference/en/p5.Camera/upY.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: upY +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

y component of direction 'up' from camera

+line: 691 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + div = createDiv('upY = ' + cam.upY); + div.position(0, 0); + div.style('color', 'blue'); + div.style('font-size', '18px'); + describe('An example showing the use of camera object properties'); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# upY diff --git a/src/content/reference/en/p5.Camera/upZ.mdx b/src/content/reference/en/p5.Camera/upZ.mdx new file mode 100644 index 0000000000..e8f2346fcc --- /dev/null +++ b/src/content/reference/en/p5.Camera/upZ.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: upZ +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

z component of direction 'up' from camera

+line: 715 +itemtype: property +class: p5.Camera +example: + - |- + +
+ let cam, div; + function setup() { + createCanvas(100, 100, WEBGL); + background(255); + cam = createCamera(); + div = createDiv('upZ = ' + cam.upZ); + div.position(0, 0); + div.style('color', 'blue'); + div.style('font-size', '18px'); + describe('An example showing the use of camera object properties'); + } +
+alt: An example showing the use of camera object properties +chainable: false +--- + + +# upZ diff --git a/src/content/reference/en/p5.Color/setAlpha.mdx b/src/content/reference/en/p5.Color/setAlpha.mdx new file mode 100644 index 0000000000..957238129e --- /dev/null +++ b/src/content/reference/en/p5.Color/setAlpha.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setAlpha +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: | +

Sets the alpha (transparency) value of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+line: 653 +params: + - name: alpha + description: | +

the new alpha value.

+ type: Number +itemtype: method +class: p5.Color +example: + - |- + +
+ + function draw() { + clear(); + background(200); + const squareColor = color(100, 50, 100); + squareColor.setAlpha(128 + 128 * sin(millis() / 1000)); + fill(squareColor); + rect(13, 13, width - 26, height - 26); + describe( + 'A purple square with gradually changing opacity drawn on a gray background.' + ); + } + +
+chainable: false +--- + + +# setAlpha diff --git a/src/content/reference/en/p5.Color/setBlue.mdx b/src/content/reference/en/p5.Color/setBlue.mdx new file mode 100644 index 0000000000..fa35a9860c --- /dev/null +++ b/src/content/reference/en/p5.Color/setBlue.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setBlue +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: | +

Sets the blue component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+line: 623 +params: + - name: blue + description: | +

the new blue value.

+ type: Number +itemtype: method +class: p5.Color +example: + - |- + +
+ + let backgroundColor; + + function setup() { + backgroundColor = color(100, 50, 150); + } + + function draw() { + backgroundColor.setBlue(128 + 128 * sin(millis() / 1000)); + background(backgroundColor); + describe('A canvas with a gradually changing background color.'); + } + +
+chainable: false +--- + + +# setBlue diff --git a/src/content/reference/en/p5.Color/setGreen.mdx b/src/content/reference/en/p5.Color/setGreen.mdx new file mode 100644 index 0000000000..99f1379034 --- /dev/null +++ b/src/content/reference/en/p5.Color/setGreen.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setGreen +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: | +

Sets the green component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+line: 593 +params: + - name: green + description: | +

the new green value.

+ type: Number +itemtype: method +class: p5.Color +example: + - |- + +
+ + let backgroundColor; + + function setup() { + backgroundColor = color(100, 50, 150); + } + + function draw() { + backgroundColor.setGreen(128 + 128 * sin(millis() / 1000)); + background(backgroundColor); + describe('A canvas with a gradually changing background color.'); + } + +
+chainable: false +--- + + +# setGreen diff --git a/src/content/reference/en/p5.Color/setRed.mdx b/src/content/reference/en/p5.Color/setRed.mdx new file mode 100644 index 0000000000..c6906acb23 --- /dev/null +++ b/src/content/reference/en/p5.Color/setRed.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setRed +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: | +

Sets the red component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+line: 563 +params: + - name: red + description: | +

the new red value.

+ type: Number +itemtype: method +class: p5.Color +example: + - |- + +
+ + let backgroundColor; + + function setup() { + backgroundColor = color(100, 50, 150); + } + + function draw() { + backgroundColor.setRed(128 + 128 * sin(millis() / 1000)); + background(backgroundColor); + describe('A canvas with a gradually changing background color.'); + } + +
+chainable: false +--- + + +# setRed diff --git a/src/content/reference/en/p5.Color/toString.mdx b/src/content/reference/en/p5.Color/toString.mdx new file mode 100644 index 0000000000..83a2a1f240 --- /dev/null +++ b/src/content/reference/en/p5.Color/toString.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toString +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: | +

Returns the color formatted as a string. Doing so can be useful for + debugging, or for using p5.js with other libraries.

+line: 360 +params: + - name: format + description: > +

how the color string will be formatted. + + Leaving this empty formats the string as rgba(r, g, b, a). + + '#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color + codes. + + 'rgb' 'hsb' and 'hsl' return the color formatted in the specified color + mode. + + 'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels. + + 'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as + percentages.

+ type: String + optional: true +itemtype: method +class: p5.Color +example: + - |- + +
+ + createCanvas(200, 100); + stroke(255); + const myColor = color(100, 100, 250); + fill(myColor); + rotate(HALF_PI); + text(myColor.toString(), 0, -5); + text(myColor.toString('#rrggbb'), 0, -30); + text(myColor.toString('rgba%'), 0, -55); + describe('Three text representation of a color written sideways.'); + +
+ +
+ + const myColor = color(100, 130, 250); + text(myColor.toString('#rrggbb'), 25, 25); + describe('A hexadecimal representation of a color.'); + +
+return: + description: the formatted string. + type: String +chainable: false +--- + + +# toString diff --git a/src/content/reference/en/p5.Compressor/attack.mdx b/src/content/reference/en/p5.Compressor/attack.mdx new file mode 100644 index 0000000000..aa639cd7a3 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/attack.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: attack +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get current attack or set value w/ time ramp

+line: 10152 +params: + - name: attack + description: | +

Attack is the amount of time (in seconds) to reduce the gain by 10dB, + default = .003, range 0 - 1

+ type: Number + optional: true + - name: time + description: | +

Assign time value to schedule the change in value

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# attack diff --git a/src/content/reference/en/p5.Compressor/compressor.mdx b/src/content/reference/en/p5.Compressor/compressor.mdx new file mode 100644 index 0000000000..6f6689e204 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/compressor.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: compressor +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

The p5.Compressor is built with a Web Audio Dynamics Compressor Node +

+line: 10068 +itemtype: property +class: p5.Compressor +chainable: false +--- + + +# compressor diff --git a/src/content/reference/en/p5.Compressor/knee.mdx b/src/content/reference/en/p5.Compressor/knee.mdx new file mode 100644 index 0000000000..19eb6e8fe6 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/knee.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: knee +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get current knee or set value w/ time ramp

+line: 10178 +params: + - name: knee + description: | +

A decibel value representing the range above the + threshold where the curve smoothly transitions to the "ratio" portion. + default = 30, range 0 - 40

+ type: Number + optional: true + - name: time + description: | +

Assign time value to schedule the change in value

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# knee diff --git a/src/content/reference/en/p5.Compressor/process.mdx b/src/content/reference/en/p5.Compressor/process.mdx new file mode 100644 index 0000000000..14a3349d71 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/process.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Performs the same function as .connect, but also accepts + optional parameters to set compressor's audioParams

+line: 10084 +params: + - name: src + description: | +

Sound source to be connected

+ type: Object + - name: attack + description: | +

The amount of time (in seconds) to reduce the gain by 10dB, + default = .003, range 0 - 1

+ type: Number + optional: true + - name: knee + description: | +

A decibel value representing the range above the + threshold where the curve smoothly transitions to the "ratio" portion. + default = 30, range 0 - 40

+ type: Number + optional: true + - name: ratio + description: | +

The amount of dB change in input for a 1 dB change in output + default = 12, range 1 - 20

+ type: Number + optional: true + - name: threshold + description: | +

The decibel value above which the compression will start taking effect + default = -24, range -100 - 0

+ type: Number + optional: true + - name: release + description: | +

The amount of time (in seconds) to increase the gain by 10dB + default = .25, range 0 - 1

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Compressor/ratio.mdx b/src/content/reference/en/p5.Compressor/ratio.mdx new file mode 100644 index 0000000000..59d6f6f182 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/ratio.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ratio +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get current ratio or set value w/ time ramp

+line: 10204 +params: + - name: ratio + description: | +

The amount of dB change in input for a 1 dB change in output + default = 12, range 1 - 20

+ type: Number + optional: true + - name: time + description: | +

Assign time value to schedule the change in value

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# ratio diff --git a/src/content/reference/en/p5.Compressor/reduction.mdx b/src/content/reference/en/p5.Compressor/reduction.mdx new file mode 100644 index 0000000000..f4a40e198b --- /dev/null +++ b/src/content/reference/en/p5.Compressor/reduction.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reduction +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the current reduction value

+line: 10277 +itemtype: method +class: p5.Compressor +return: + description: Value of the amount of gain reduction that is applied to the signal + type: Number +chainable: false +--- + + +# reduction diff --git a/src/content/reference/en/p5.Compressor/release.mdx b/src/content/reference/en/p5.Compressor/release.mdx new file mode 100644 index 0000000000..8061e63e7e --- /dev/null +++ b/src/content/reference/en/p5.Compressor/release.mdx @@ -0,0 +1,27 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: release +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get current release or set value w/ time ramp

+line: 10252 +params: + - name: release + description: | +

The amount of time (in seconds) to increase the gain by 10dB + default = .25, range 0 - 1

+ type: Number + - name: time + description: | +

Assign time value to schedule the change in value

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# release diff --git a/src/content/reference/en/p5.Compressor/set.mdx b/src/content/reference/en/p5.Compressor/set.mdx new file mode 100644 index 0000000000..e7478ab4d0 --- /dev/null +++ b/src/content/reference/en/p5.Compressor/set.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the paramters of a compressor.

+line: 10112 +params: + - name: attack + description: | +

The amount of time (in seconds) to reduce the gain by 10dB, + default = .003, range 0 - 1

+ type: Number + - name: knee + description: | +

A decibel value representing the range above the + threshold where the curve smoothly transitions to the "ratio" portion. + default = 30, range 0 - 40

+ type: Number + - name: ratio + description: | +

The amount of dB change in input for a 1 dB change in output + default = 12, range 1 - 20

+ type: Number + - name: threshold + description: | +

The decibel value above which the compression will start taking effect + default = -24, range -100 - 0

+ type: Number + - name: release + description: | +

The amount of time (in seconds) to increase the gain by 10dB + default = .25, range 0 - 1

+ type: Number +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Compressor/threshold.mdx b/src/content/reference/en/p5.Compressor/threshold.mdx new file mode 100644 index 0000000000..fd6116ac1c --- /dev/null +++ b/src/content/reference/en/p5.Compressor/threshold.mdx @@ -0,0 +1,27 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: threshold +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get current threshold or set value w/ time ramp

+line: 10228 +params: + - name: threshold + description: | +

The decibel value above which the compression will start taking effect + default = -24, range -100 - 0

+ type: Number + - name: time + description: | +

Assign time value to schedule the change in value

+ type: Number + optional: true +itemtype: method +class: p5.Compressor +chainable: false +--- + + +# threshold diff --git a/src/content/reference/en/p5.Convolver/addImpulse.mdx b/src/content/reference/en/p5.Convolver/addImpulse.mdx new file mode 100644 index 0000000000..412e6df000 --- /dev/null +++ b/src/content/reference/en/p5.Convolver/addImpulse.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addImpulse +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Load and assign a new Impulse Response to the p5.Convolver. + The impulse is added to the .impulses array. Previous + impulses can be accessed with the .toggleImpulse(id) + method.

+line: 8786 +params: + - name: path + description: | +

path to a sound file

+ type: String + - name: callback + description: | +

function (optional)

+ type: Function + - name: errorCallback + description: | +

function (optional)

+ type: Function +itemtype: method +class: p5.Convolver +chainable: false +--- + + +# addImpulse diff --git a/src/content/reference/en/p5.Convolver/convolverNode.mdx b/src/content/reference/en/p5.Convolver/convolverNode.mdx new file mode 100644 index 0000000000..b08fb175bf --- /dev/null +++ b/src/content/reference/en/p5.Convolver/convolverNode.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: convolverNode +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Internally, the p5.Convolver uses the a + + Web Audio Convolver Node.

+line: 8621 +itemtype: property +class: p5.Convolver +chainable: false +--- + + +# convolverNode diff --git a/src/content/reference/en/p5.Convolver/impulses.mdx b/src/content/reference/en/p5.Convolver/impulses.mdx new file mode 100644 index 0000000000..eb29328ebf --- /dev/null +++ b/src/content/reference/en/p5.Convolver/impulses.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: impulses +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

If you load multiple impulse files using the .addImpulse method, + they will be stored as Objects in this Array. Toggle between them + with the toggleImpulse(id) method.

+line: 8645 +itemtype: property +class: p5.Convolver +chainable: false +--- + + +# impulses diff --git a/src/content/reference/en/p5.Convolver/process.mdx b/src/content/reference/en/p5.Convolver/process.mdx new file mode 100644 index 0000000000..cd7b16f8de --- /dev/null +++ b/src/content/reference/en/p5.Convolver/process.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect a source to the convolver.

+line: 8737 +params: + - name: src + description: | +

p5.sound / Web Audio object with a sound + output.

+ type: Object +itemtype: method +class: p5.Convolver +example: + - |- + +
+ let cVerb, sound; + function preload() { + // We have both MP3 and OGG versions of all sound assets + soundFormats('ogg', 'mp3'); + + // Try replacing 'bx-spring' with other soundfiles like + // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox' + cVerb = createConvolver('assets/bx-spring.mp3'); + + // Try replacing 'Damscray_DancingTiger' with + // 'beat', 'doorbell', lucky_dragons_-_power_melody' + sound = loadSound('assets/Damscray_DancingTiger.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playSound); + background(220); + text('tap to play', 20, 20); + + // disconnect from main output... + sound.disconnect(); + + // ...and process with cVerb + // so that we only hear the convolution + cVerb.process(sound); + } + + function playSound() { + sound.play(); + } + +
+chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Convolver/resetImpulse.mdx b/src/content/reference/en/p5.Convolver/resetImpulse.mdx new file mode 100644 index 0000000000..f6be3a5a24 --- /dev/null +++ b/src/content/reference/en/p5.Convolver/resetImpulse.mdx @@ -0,0 +1,31 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resetImpulse +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Similar to .addImpulse, except that the .impulses + Array is reset to save memory. A new .impulses + array is created with this impulse as the only item.

+line: 8808 +params: + - name: path + description: | +

path to a sound file

+ type: String + - name: callback + description: | +

function (optional)

+ type: Function + - name: errorCallback + description: | +

function (optional)

+ type: Function +itemtype: method +class: p5.Convolver +chainable: false +--- + + +# resetImpulse diff --git a/src/content/reference/en/p5.Convolver/toggleImpulse.mdx b/src/content/reference/en/p5.Convolver/toggleImpulse.mdx new file mode 100644 index 0000000000..55bb6cfdd4 --- /dev/null +++ b/src/content/reference/en/p5.Convolver/toggleImpulse.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toggleImpulse +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

If you have used .addImpulse() to add multiple impulses + to a p5.Convolver, then you can use this method to toggle between + the items in the .impulses Array. Accepts a parameter + to identify which impulse you wish to use, identified either by its + original filename (String) or by its position in the .impulses + Array (Number).
+ You can access the objects in the .impulses Array directly. Each + Object has two attributes: an .audioBuffer (type: + Web Audio + AudioBuffer) and a .name, a String that corresponds + with the original filename.

+line: 8831 +params: + - name: id + description: | +

Identify the impulse by its original filename + (String), or by its position in the + .impulses Array (Number).

+ type: String|Number +itemtype: method +class: p5.Convolver +chainable: false +--- + + +# toggleImpulse diff --git a/src/content/reference/en/p5.Delay/amp.mdx b/src/content/reference/en/p5.Delay/amp.mdx new file mode 100644 index 0000000000..b72153a6b1 --- /dev/null +++ b/src/content/reference/en/p5.Delay/amp.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the output level of the delay effect.

+line: 8223 +params: + - name: volume + description: | +

amplitude between 0 and 1.0

+ type: Number + - name: rampTime + description: | +

create a fade that lasts rampTime

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Delay +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.Delay/connect.mdx b/src/content/reference/en/p5.Delay/connect.mdx new file mode 100644 index 0000000000..c3f6c60082 --- /dev/null +++ b/src/content/reference/en/p5.Delay/connect.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Send output to a p5.sound or web audio object

+line: 8234 +params: + - name: unit + description: '' + type: Object +itemtype: method +class: p5.Delay +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.Delay/delayTime.mdx b/src/content/reference/en/p5.Delay/delayTime.mdx new file mode 100644 index 0000000000..6789516540 --- /dev/null +++ b/src/content/reference/en/p5.Delay/delayTime.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: delayTime +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the delay (echo) time, in seconds. Usually this value will be + a floating point number between 0.0 and 1.0.

+line: 8094 +params: + - name: delayTime + description: | +

Time (in seconds) of the delay

+ type: Number +itemtype: method +class: p5.Delay +chainable: false +--- + + +# delayTime diff --git a/src/content/reference/en/p5.Delay/disconnect.mdx b/src/content/reference/en/p5.Delay/disconnect.mdx new file mode 100644 index 0000000000..43c2bf83e9 --- /dev/null +++ b/src/content/reference/en/p5.Delay/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all output.

+line: 8242 +itemtype: method +class: p5.Delay +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Delay/feedback.mdx b/src/content/reference/en/p5.Delay/feedback.mdx new file mode 100644 index 0000000000..b360e1d8b3 --- /dev/null +++ b/src/content/reference/en/p5.Delay/feedback.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: feedback +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Feedback occurs when Delay sends its signal back through its input + in a loop. The feedback amount determines how much signal to send each + time through the loop. A feedback greater than 1.0 is not desirable because + it will increase the overall output each time through the loop, + creating an infinite feedback loop. The default value is 0.5

+line: 8116 +params: + - name: feedback + description: | +

0.0 to 1.0, or an object such as an + Oscillator that can be used to + modulate this param

+ type: Number|Object +itemtype: method +class: p5.Delay +return: + description: Feedback value + type: Number +chainable: false +--- + + +# feedback diff --git a/src/content/reference/en/p5.Delay/filter.mdx b/src/content/reference/en/p5.Delay/filter.mdx new file mode 100644 index 0000000000..090e19e1eb --- /dev/null +++ b/src/content/reference/en/p5.Delay/filter.mdx @@ -0,0 +1,31 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: filter +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set a lowpass filter frequency for the delay. A lowpass filter + will cut off any frequencies higher than the filter frequency.

+line: 8148 +params: + - name: cutoffFreq + description: | +

A lowpass filter will cut off any + frequencies higher than the filter frequency.

+ type: Number|Object + - name: res + description: | +

Resonance of the filter frequency + cutoff, or an object (i.e. a p5.Oscillator) + that can be used to modulate this parameter. + High numbers (i.e. 15) will produce a resonance, + low numbers (i.e. .2) will produce a slope.

+ type: Number|Object +itemtype: method +class: p5.Delay +chainable: false +--- + + +# filter diff --git a/src/content/reference/en/p5.Delay/leftDelay.mdx b/src/content/reference/en/p5.Delay/leftDelay.mdx new file mode 100644 index 0000000000..7a3676f460 --- /dev/null +++ b/src/content/reference/en/p5.Delay/leftDelay.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: leftDelay +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The p5.Delay is built with two + + Web Audio Delay Nodes, one for each stereo channel.

+line: 7989 +itemtype: property +class: p5.Delay +chainable: false +--- + + +# leftDelay diff --git a/src/content/reference/en/p5.Delay/process.mdx b/src/content/reference/en/p5.Delay/process.mdx new file mode 100644 index 0000000000..92c8aa3395 --- /dev/null +++ b/src/content/reference/en/p5.Delay/process.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Add delay to an audio signal according to a set + of delay parameters.

+line: 8049 +params: + - name: Signal + description: | +

An object that outputs audio

+ type: Object + - name: delayTime + description: | +

Time (in seconds) of the delay/echo. + Some browsers limit delayTime to + 1 second.

+ type: Number + optional: true + - name: feedback + description: | +

sends the delay back through itself + in a loop that decreases in volume + each time.

+ type: Number + optional: true + - name: lowPass + description: | +

Cutoff frequency. Only frequencies + below the lowPass will be part of the + delay.

+ type: Number + optional: true +itemtype: method +class: p5.Delay +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Delay/rightDelay.mdx b/src/content/reference/en/p5.Delay/rightDelay.mdx new file mode 100644 index 0000000000..84396b6116 --- /dev/null +++ b/src/content/reference/en/p5.Delay/rightDelay.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rightDelay +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The p5.Delay is built with two + + Web Audio Delay Nodes, one for each stereo channel.

+line: 7999 +itemtype: property +class: p5.Delay +chainable: false +--- + + +# rightDelay diff --git a/src/content/reference/en/p5.Delay/setType.mdx b/src/content/reference/en/p5.Delay/setType.mdx new file mode 100644 index 0000000000..a95a6746d3 --- /dev/null +++ b/src/content/reference/en/p5.Delay/setType.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setType +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Choose a preset type of delay. 'pingPong' bounces the signal + from the left to the right channel to produce a stereo effect. + Any other parameter will revert to the default delay setting.

+line: 8170 +params: + - name: type + description: | +

'pingPong' (1) or 'default' (0)

+ type: String|Number +itemtype: method +class: p5.Delay +chainable: false +--- + + +# setType diff --git a/src/content/reference/en/p5.Distortion/WaveShaperNode.mdx b/src/content/reference/en/p5.Distortion/WaveShaperNode.mdx new file mode 100644 index 0000000000..a793819c50 --- /dev/null +++ b/src/content/reference/en/p5.Distortion/WaveShaperNode.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: WaveShaperNode +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The p5.Distortion is built with a + + Web Audio WaveShaper Node.

+line: 10864 +itemtype: property +class: p5.Distortion +chainable: false +--- + + +# WaveShaperNode diff --git a/src/content/reference/en/p5.Distortion/getAmount.mdx b/src/content/reference/en/p5.Distortion/getAmount.mdx new file mode 100644 index 0000000000..c998dff578 --- /dev/null +++ b/src/content/reference/en/p5.Distortion/getAmount.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getAmount +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the distortion amount, typically between 0-1.

+line: 10923 +itemtype: method +class: p5.Distortion +return: + description: |- + Unbounded distortion amount. + Normal values range from 0-1. + type: Number +chainable: false +--- + + +# getAmount diff --git a/src/content/reference/en/p5.Distortion/getOversample.mdx b/src/content/reference/en/p5.Distortion/getOversample.mdx new file mode 100644 index 0000000000..6b848d6cea --- /dev/null +++ b/src/content/reference/en/p5.Distortion/getOversample.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getOversample +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the oversampling.

+line: 10937 +itemtype: method +class: p5.Distortion +return: + description: 'Oversample can either be ''none'', ''2x'', or ''4x''.' + type: String +chainable: false +--- + + +# getOversample diff --git a/src/content/reference/en/p5.Distortion/process.mdx b/src/content/reference/en/p5.Distortion/process.mdx new file mode 100644 index 0000000000..4df770a511 --- /dev/null +++ b/src/content/reference/en/p5.Distortion/process.mdx @@ -0,0 +1,31 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Process a sound source, optionally specify amount and oversample + values.

+line: 10883 +params: + - name: amount + description: | +

Unbounded distortion amount. + Normal values range from 0-1.

+ type: Number + optional: true + optdefault: '0.25' + - name: oversample + description: | +

'none', '2x', or '4x'.

+ type: String + optional: true + optdefault: '''none''' +itemtype: method +class: p5.Distortion +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Distortion/set.mdx b/src/content/reference/en/p5.Distortion/set.mdx new file mode 100644 index 0000000000..e85bed80b6 --- /dev/null +++ b/src/content/reference/en/p5.Distortion/set.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the amount and oversample of the waveshaper distortion.

+line: 10900 +params: + - name: amount + description: | +

Unbounded distortion amount. + Normal values range from 0-1.

+ type: Number + optional: true + optdefault: '0.25' + - name: oversample + description: | +

'none', '2x', or '4x'.

+ type: String + optional: true + optdefault: '''none''' +itemtype: method +class: p5.Distortion +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.EQ/bands.mdx b/src/content/reference/en/p5.EQ/bands.mdx new file mode 100644 index 0000000000..308997bd9d --- /dev/null +++ b/src/content/reference/en/p5.EQ/bands.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bands +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The p5.EQ is built with abstracted p5.Filter objects. + To modify any bands, use methods of the + p5.Filter API, especially gain and freq. + Bands are stored in an array, with indices 0 - 3, or 0 - 7

+line: 7198 +itemtype: property +class: p5.EQ +chainable: false +--- + + +# bands diff --git a/src/content/reference/en/p5.EQ/process.mdx b/src/content/reference/en/p5.EQ/process.mdx new file mode 100644 index 0000000000..77557a0e89 --- /dev/null +++ b/src/content/reference/en/p5.EQ/process.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Process an input by connecting it to the EQ

+line: 7239 +params: + - name: src + description: | +

Audio source

+ type: Object +itemtype: method +class: p5.EQ +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Effect/amp.mdx b/src/content/reference/en/p5.Effect/amp.mdx new file mode 100644 index 0000000000..408e0072ca --- /dev/null +++ b/src/content/reference/en/p5.Effect/amp.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the output volume of the filter.

+line: 6478 +params: + - name: vol + description: | +

amplitude between 0 and 1.0

+ type: Number + optional: true + - name: rampTime + description: | +

create a fade that lasts until rampTime

+ type: Number + optional: true + - name: tFromNow + description: | +

schedule this event to happen in tFromNow seconds

+ type: Number + optional: true +itemtype: method +class: p5.Effect +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.Effect/chain.mdx b/src/content/reference/en/p5.Effect/chain.mdx new file mode 100644 index 0000000000..077ea991eb --- /dev/null +++ b/src/content/reference/en/p5.Effect/chain.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: chain +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Link effects together in a chain + Example usage: filter.chain(reverb, delay, panner); + May be used with an open-ended number of arguments

+line: 6502 +params: + - name: arguments + description: | +

Chain together multiple sound objects

+ type: Object + optional: true +itemtype: method +class: p5.Effect +chainable: false +--- + + +# chain diff --git a/src/content/reference/en/p5.Effect/connect.mdx b/src/content/reference/en/p5.Effect/connect.mdx new file mode 100644 index 0000000000..ede401e05a --- /dev/null +++ b/src/content/reference/en/p5.Effect/connect.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Send output to a p5.js-sound, Web Audio Node, or use signal to + control an AudioParam

+line: 6542 +params: + - name: unit + description: '' + type: Object +itemtype: method +class: p5.Effect +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.Effect/disconnect.mdx b/src/content/reference/en/p5.Effect/disconnect.mdx new file mode 100644 index 0000000000..81ad3a3a32 --- /dev/null +++ b/src/content/reference/en/p5.Effect/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all output.

+line: 6557 +itemtype: method +class: p5.Effect +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Effect/drywet.mdx b/src/content/reference/en/p5.Effect/drywet.mdx new file mode 100644 index 0000000000..ccb709c2ce --- /dev/null +++ b/src/content/reference/en/p5.Effect/drywet.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: drywet +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Adjust the dry/wet value.

+line: 6525 +params: + - name: fade + description: | +

The desired drywet value (0 - 1.0)

+ type: Number + optional: true +itemtype: method +class: p5.Effect +chainable: false +--- + + +# drywet diff --git a/src/content/reference/en/p5.Element/addClass.mdx b/src/content/reference/en/p5.Element/addClass.mdx new file mode 100644 index 0000000000..da8261743d --- /dev/null +++ b/src/content/reference/en/p5.Element/addClass.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addClass +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Adds specified class to the element.

+line: 2323 +params: + - name: class + description: | +

name of class to add

+ type: String +itemtype: method +class: p5.Element +example: + - |2- + +
+ let div = createDiv('div'); + div.addClass('myClass'); +
+chainable: true +--- + + +# addClass diff --git a/src/content/reference/en/p5.Element/attribute.mdx b/src/content/reference/en/p5.Element/attribute.mdx new file mode 100644 index 0000000000..11c307740e --- /dev/null +++ b/src/content/reference/en/p5.Element/attribute.mdx @@ -0,0 +1,91 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: attribute +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Adds an + + attribute + + to the element. This method is useful for advanced tasks.

+ +

Most commonly-used attributes, such as id, can be set with + their + + dedicated methods. For example, nextButton.id('next') sets an + element's + + id attribute.

+ +

The first parameter, attr, is the attribute's name as a + string. Calling + + myElement.attribute('align') returns the attribute's current + value as a + + string or null if it hasn't been set.

+ +

The second parameter, value, is optional. It's a string used + to set the + + attribute's value. For example, calling + + myElement.attribute('align', 'center') sets the element's + horizontal + + alignment to center.

+line: 2859 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a container div and + // place it at the top-left + // corner. + let container = createDiv(); + container.position(0, 0); + + // Create a paragraph element + // and place it within the container. + // Set its horizontal alignment to + // "left". + let p1 = createP('hi'); + p1.parent(container); + p1.attribute('align', 'left'); + + // Create a paragraph element + // and place it within the container. + // Set its horizontal alignment to + // "center". + let p2 = createP('hi'); + p2.parent(container); + p2.attribute('align', 'center'); + + // Create a paragraph element + // and place it within the container. + // Set its horizontal alignment to + // "right". + let p3 = createP('hi'); + p3.parent(container); + p3.attribute('align', 'right'); + + describe('A gray square with the text "hi" written on three separate lines, each placed further to the right.'); + } + +
+return: + description: value of the attribute. + type: String +chainable: false +--- + + +# attribute diff --git a/src/content/reference/en/p5.Element/center.mdx b/src/content/reference/en/p5.Element/center.mdx new file mode 100644 index 0000000000..d4b8c98e18 --- /dev/null +++ b/src/content/reference/en/p5.Element/center.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: center +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Centers a p5.Element either vertically, horizontally, + or both, relative to its parent or according to + the body if the p5.Element has no parent. If no argument is passed + the p5.Element is aligned both vertically and horizontally.

+line: 2494 +params: + - name: align + description: | +

passing 'vertical', 'horizontal' aligns element accordingly

+ type: String + optional: true +itemtype: method +class: p5.Element +example: + - |- + +
+ function setup() { + let div = createDiv('').size(10, 10); + div.style('background-color', 'orange'); + div.center(); + } +
+chainable: true +--- + + +# center diff --git a/src/content/reference/en/p5.Element/child.mdx b/src/content/reference/en/p5.Element/child.mdx new file mode 100644 index 0000000000..85da1f3743 --- /dev/null +++ b/src/content/reference/en/p5.Element/child.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: child +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Attaches the element as a child to the parent specified. + Accepts either a string ID, DOM node, or p5.Element. + If no argument is specified, an array of children DOM nodes is returned.

+line: 2441 +itemtype: method +class: p5.Element +example: + - |2- + +
+ let div0 = createDiv('this is the parent'); + let div1 = createDiv('this is the child'); + div0.child(div1); // use p5.Element +
+
+ let div0 = createDiv('this is the parent'); + let div1 = createDiv('this is the child'); + div1.id('apples'); + div0.child('apples'); // use id +
+
+ // this example assumes there is a div already on the page + // with id "myChildDiv" + let div0 = createDiv('this is the parent'); + let elt = document.getElementById('myChildDiv'); + div0.child(elt); // use element from page +
+return: + description: an array of child nodes + type: 'Node[]' +chainable: false +--- + + +# child diff --git a/src/content/reference/en/p5.Element/class.mdx b/src/content/reference/en/p5.Element/class.mdx new file mode 100644 index 0000000000..97a27cee73 --- /dev/null +++ b/src/content/reference/en/p5.Element/class.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: class +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

Adds a + + class attribute + + to the element.

+ +

Calling myElement.class() without an argument returns a string + with its current classes.

+line: 280 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Add the class "small" to the + // canvas element. + cnv.class('small'); + + // Get the canvas element's class + // and display it. + let c = cnv.class(); + text(c, 35, 54); + + describe('The word "small" written in black on a gray canvas.'); + + } + +
+chainable: true +--- + + +# class diff --git a/src/content/reference/en/p5.Element/doubleClicked.mdx b/src/content/reference/en/p5.Element/doubleClicked.mdx new file mode 100644 index 0000000000..d5d41c5b4a --- /dev/null +++ b/src/content/reference/en/p5.Element/doubleClicked.mdx @@ -0,0 +1,73 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: doubleClicked +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse is pressed twice over the element. + Calling myElement.doubleClicked(false) disables the function.

+line: 404 +params: + - name: fxn + description: | +

function to call when the mouse is + double clicked over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // canvas is double-clicked. + cnv.doubleClicked(randomColor); + + describe('A gray square changes color when the user double-clicks the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the canvas is double-clicked. + cnv.doubleClicked(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user double-clicks the canvas.'); + } + +
+chainable: true +--- + + +# doubleClicked diff --git a/src/content/reference/en/p5.Element/dragLeave.mdx b/src/content/reference/en/p5.Element/dragLeave.mdx new file mode 100644 index 0000000000..b493e16034 --- /dev/null +++ b/src/content/reference/en/p5.Element/dragLeave.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dragLeave +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when a file is dragged off the element. Calling + Calling myElement.dragLeave(false) disables the function.

+line: 1153 +params: + - name: fxn + description: | +

function to call when the file is + dragged off the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + // Drag a file over, then off + // the canvas to test. + + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call byeFile() when a + // file is dragged over, + // then off the canvas. + cnv.dragLeave(byeFile); + + describe('A gray square. The text "bye, file" appears when a file is dragged over, then off the square.'); + } + + function byeFile() { + text('bye, file', 50, 50); + } + +
+ +
+ + // Drag a file over, then off + // the canvas to test. + + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Say "bye, file" when a + // file is dragged over, + // then off the canvas. + cnv.dragLeave(() => { + text('bye, file', 50, 50); + }); + + describe('A gray square. The text "bye, file" appears when a file is dragged over, then off the square.'); + } + +
+chainable: true +--- + + +# dragLeave diff --git a/src/content/reference/en/p5.Element/dragOver.mdx b/src/content/reference/en/p5.Element/dragOver.mdx new file mode 100644 index 0000000000..b1e7723b36 --- /dev/null +++ b/src/content/reference/en/p5.Element/dragOver.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dragOver +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when a file is dragged over the element. Calling + myElement.dragOver(false) disables the function.

+line: 1090 +params: + - name: fxn + description: | +

function to call when the file is + dragged over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + // Drag a file over the canvas to test. + + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call helloFile() when a + // file is dragged over + // the canvas. + cnv.dragOver(helloFile); + + describe('A gray square. The text "hello, file" appears when a file is dragged over the square.'); + } + + function helloFile() { + text('hello, file', 50, 50); + } + +
+ +
+ + // Drag a file over the canvas to test. + + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Say "hello, file" when a + // file is dragged over + // the canvas. + cnv.dragOver(() => { + text('hello, file', 50, 50); + }); + + describe('A gray square. The text "hello, file" appears when a file is dragged over the square.'); + } + +
+chainable: true +--- + + +# dragOver diff --git a/src/content/reference/en/p5.Element/draggable.mdx b/src/content/reference/en/p5.Element/draggable.mdx new file mode 100644 index 0000000000..8edaa95331 --- /dev/null +++ b/src/content/reference/en/p5.Element/draggable.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: draggable +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Turns p5.Element into a draggable item. If an argument is given, it will + drag that p5.Element instead, ie. drag a entire GUI panel (parent container) + with the panel's title bar.

+line: 3511 +params: + - name: elmnt + description: | +

pass another p5.Element

+ type: p5.Element + optional: true +itemtype: method +class: p5.Element +example: + - |- + +
+ function setup() { + createCanvas(100, 100); + background(200); + + createDiv('Post-It') + .position(5, 5) + .size(75, 20) + .style('font-size', '16px') + .style('background', 'yellow') + .style('color', '#000') + .style('border', '1px solid #aaaa00') + .style('padding', '5px') + .draggable(); + // .style('cursor', 'help') // override cursor + + let gui = createDiv('') + .position(5, 40) + .size(85, 50) + .style('font-size', '16px') + .style('background', 'yellow') + .style('z-index', '100') + .style('border', '1px solid #00aaaa'); + + createDiv('= PANEL =') + .parent(gui) + .style('background', 'cyan') + .style('padding', '2px') + .style('text-align', 'center') + .draggable(gui); + + createSlider(0, 100, random(100)) + .style('cursor', 'pointer') + .size(80, 5) + .parent(gui); + } +
+chainable: true +--- + + +# draggable diff --git a/src/content/reference/en/p5.Element/drop.mdx b/src/content/reference/en/p5.Element/drop.mdx new file mode 100644 index 0000000000..33c9d45797 --- /dev/null +++ b/src/content/reference/en/p5.Element/drop.mdx @@ -0,0 +1,140 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: drop +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Sets a function to call when the user drops a file on the element.

+ +

The first parameter, callback, is a function to call once the + file loads. + + The callback function should have one parameter, file, that's a + + p5.File object. If the user drops multiple files on + + the element, callback, is called once for each file.

+ +

The second parameter, fxn, is a function to call when the + browser detects + + one or more dropped files. The callback function should have one + + parameter, event, that's a + + DragEvent.

+line: 3355 +params: + - name: callback + description: | +

called when a file loads. Called once for each file dropped.

+ type: Function + - name: fxn + description: | +

called once when any files are dropped.

+ type: Function + optional: true +itemtype: method +class: p5.Element +example: + - |- + +
+ + // Drop an image on the canvas to view + // this example. + let img; + + function setup() { + let c = createCanvas(100, 100); + + background(200); + + // Call a function when a file + // dropped on the canvas has + // loaded. + c.drop(file => { + // Remove the current image, if any. + if (img) { + img.remove(); + } + + // Create an element with the + // dropped file. + img = createImg(file.data, ''); + img.hide(); + + // Draw the image. + image(img, 0, 0, width, height); + }); + + describe('A gray square. When the user drops an image on the square, it is displayed.'); + } + +
+ +
+ + // Drop an image on the canvas to view + // this example. + let img; + let msg; + + function setup() { + let c = createCanvas(100, 100); + + background(200); + + // Call functions when the user + // drops a file on the canvas + // and when the file loads. + c.drop(handleFile, handleDrop); + + describe('A gray square. When the user drops an image on the square, it is displayed. The id attribute of canvas element is also displayed.'); + } + + function handleFile(file) { + // Remove the current image, if any. + if (img) { + img.remove(); + } + + // Create an element with the + // dropped file. + img = createImg(file.data, ''); + img.hide(); + + // Draw the image. + image(img, 0, 0, width, height); + } + + function handleDrop(event) { + // Remove current paragraph, if any. + if (msg) { + msg.remove(); + } + + // Use event to get the drop + // target's id. + let id = event.target.id; + + // Write the canvas' id + // beneath it. + msg = createP(id); + msg.position(0, 100); + + // Set the font color + // randomly for each drop. + let c = random(['red', 'green', 'blue']); + msg.style('color', c); + msg.style('font-size', '12px'); + } + +
+chainable: true +--- + + +# drop diff --git a/src/content/reference/en/p5.Element/elt.mdx b/src/content/reference/en/p5.Element/elt.mdx new file mode 100644 index 0000000000..e6a3a03034 --- /dev/null +++ b/src/content/reference/en/p5.Element/elt.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: elt +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

Underlying + + HTMLElement + + object. Its properties and methods can be used directly.

+line: 55 +itemtype: property +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Set the border style for the + // canvas. + cnv.elt.style.border = '5px dashed deeppink'; + + describe('A gray square with a pink border drawn with dashed lines.'); + } + +
+chainable: false +--- + + +# elt diff --git a/src/content/reference/en/p5.Element/hasClass.mdx b/src/content/reference/en/p5.Element/hasClass.mdx new file mode 100644 index 0000000000..bf3b0ee728 --- /dev/null +++ b/src/content/reference/en/p5.Element/hasClass.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hasClass +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Checks if specified class is already applied to element.

+line: 2379 +params: + - name: c + description: | +

class name of class to check

+ type: String +itemtype: method +class: p5.Element +example: + - |2- + +
+ let div; + function setup() { + div = createDiv('div'); + div.addClass('show'); + } + function mousePressed() { + if (div.hasClass('show')) { + div.addClass('show'); + } else { + div.removeClass('show'); + } + } +
+return: + description: a boolean value if element has specified class + type: Boolean +chainable: false +--- + + +# hasClass diff --git a/src/content/reference/en/p5.Element/height.mdx b/src/content/reference/en/p5.Element/height.mdx new file mode 100644 index 0000000000..fff7f50048 --- /dev/null +++ b/src/content/reference/en/p5.Element/height.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: height +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: '' +line: 97 +itemtype: property +class: p5.Element +chainable: false +--- + + +# height diff --git a/src/content/reference/en/p5.Element/hide.mdx b/src/content/reference/en/p5.Element/hide.mdx new file mode 100644 index 0000000000..9872a6c3bc --- /dev/null +++ b/src/content/reference/en/p5.Element/hide.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hide +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Hides the current element.

+line: 3110 +itemtype: method +class: p5.Element +example: + - |- + + let p; + + function setup() { + background(200); + + // Create a paragraph element. + p = createP('p5*js'); + p.position(10, 10); + + describe('The text "p5*js" at the center of a gray square. The text disappears when the user double-clicks the square.'); + } + + // Hide the paragraph when double-clicked. + function doubleClicked() { + p.hide(); + } + + +chainable: true +--- + + +# hide diff --git a/src/content/reference/en/p5.Element/html.mdx b/src/content/reference/en/p5.Element/html.mdx new file mode 100644 index 0000000000..4c493ff8ab --- /dev/null +++ b/src/content/reference/en/p5.Element/html.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: html +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

If an argument is given, sets the inner HTML of the element, + replacing any existing HTML. If true is included as a second + argument, HTML is appended instead of replacing existing HTML. + If no arguments are given, returns + the inner HTML of the element.

+line: 2545 +itemtype: method +class: p5.Element +example: + - |2- + +
+ let div = createDiv('').size(100, 100); + div.html('hi'); +
+
+ let div = createDiv('Hello ').size(100, 100); + div.html('World', true); +
+return: + description: the inner HTML of the element + type: String +chainable: false +--- + + +# html diff --git a/src/content/reference/en/p5.Element/id.mdx b/src/content/reference/en/p5.Element/id.mdx new file mode 100644 index 0000000000..b4ae7ef1cc --- /dev/null +++ b/src/content/reference/en/p5.Element/id.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: id +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

Sets this element's ID using a given string.

+ +

Calling myElement.id() without an argument returns its ID as a + string.

+line: 233 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Set the canvas' ID + // to "mycanvas". + cnv.id('mycanvas'); + + // Get the canvas' ID. + let id = cnv.id(); + text(id, 24, 54); + + describe('The text "mycanvas" written in black on a gray background.'); + } + +
+chainable: true +--- + + +# id diff --git a/src/content/reference/en/p5.Element/mouseClicked.mdx b/src/content/reference/en/p5.Element/mouseClicked.mdx new file mode 100644 index 0000000000..260b772820 --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseClicked.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseClicked +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse is pressed and released over the element. + Calling myElement.mouseReleased(false) disables the function.

+

Note: Some mobile browsers may also trigger this event when the element + receives a quick tap.

+line: 638 +params: + - name: fxn + description: | +

function to call when the mouse is + pressed and released over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when a + // mouse press ends. + cnv.mouseClicked(randomColor); + + describe('A gray square changes color when the user releases a mouse press.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when a mouse press ends. + cnv.mouseClicked(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user releases a mouse press.'); + } + +
+chainable: true +--- + + +# mouseClicked diff --git a/src/content/reference/en/p5.Element/mouseMoved.mdx b/src/content/reference/en/p5.Element/mouseMoved.mdx new file mode 100644 index 0000000000..dc657a5144 --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseMoved.mdx @@ -0,0 +1,73 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseMoved +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse moves over the element. Calling + myElement.mouseMoved(false) disables the function.

+line: 703 +params: + - name: fxn + description: | +

function to call when the mouse + moves over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // mouse moves. + cnv.mouseMoved(randomColor); + + describe('A gray square changes color when the mouse moves over the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the mouse moves. + cnv.mouseMoved(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the mouse moves over the canvas.'); + } + +
+chainable: true +--- + + +# mouseMoved diff --git a/src/content/reference/en/p5.Element/mouseOut.mdx b/src/content/reference/en/p5.Element/mouseOut.mdx new file mode 100644 index 0000000000..7a50b2a45e --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseOut.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseOut +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse moves off the element. Calling + myElement.mouseOut(false) disables the function.

+line: 828 +params: + - name: fxn + description: | +

function to call when the mouse + moves off the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // mouse moves off the canvas. + cnv.mouseOut(randomColor); + + describe('A gray square changes color when the mouse moves off the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the mouse moves off + // the canvas. + cnv.mouseOut(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the mouse moves off the canvas.'); + } + +
+chainable: true +--- + + +# mouseOut diff --git a/src/content/reference/en/p5.Element/mouseOver.mdx b/src/content/reference/en/p5.Element/mouseOver.mdx new file mode 100644 index 0000000000..a24d8c067e --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseOver.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseOver +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse moves onto the element. Calling + myElement.mouseOver(false) disables the function.

+line: 765 +params: + - name: fxn + description: | +

function to call when the mouse + moves onto the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // mouse moves onto the canvas. + cnv.mouseOver(randomColor); + + describe('A gray square changes color when the mouse moves onto the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the mouse moves onto + // the canvas. + cnv.mouseOver(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the mouse moves onto the canvas.'); + } + +
+chainable: true +--- + + +# mouseOver diff --git a/src/content/reference/en/p5.Element/mousePressed.mdx b/src/content/reference/en/p5.Element/mousePressed.mdx new file mode 100644 index 0000000000..8f89b9b9a3 --- /dev/null +++ b/src/content/reference/en/p5.Element/mousePressed.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mousePressed +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse is pressed over the element. + Calling myElement.mousePressed(false) disables the function.

+

Note: Some mobile browsers may also trigger this event when the element + receives a quick tap.

+line: 329 +params: + - name: fxn + description: | +

function to call when the mouse is + pressed over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the canvas + // is pressed. + cnv.mousePressed(randomColor); + + describe('A gray square changes color when the mouse is pressed.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the canvas is pressed. + cnv.mousePressed(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the mouse is pressed.'); + } + +
+chainable: true +--- + + +# mousePressed diff --git a/src/content/reference/en/p5.Element/mouseReleased.mdx b/src/content/reference/en/p5.Element/mouseReleased.mdx new file mode 100644 index 0000000000..e73fa3e9a9 --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseReleased.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseReleased +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the mouse is released over the element. Calling + myElement.mouseReleased(false) disables the function.

+

Note: Some mobile browsers may also trigger this event when the element + receives a quick tap.

+line: 573 +params: + - name: fxn + description: | +

function to call when the mouse is + pressed over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when a + // mouse press ends. + cnv.mouseReleased(randomColor); + + describe('A gray square changes color when the user releases a mouse press.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when a mouse press ends. + cnv.mouseReleased(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user releases a mouse press.'); + } + +
+chainable: true +--- + + +# mouseReleased diff --git a/src/content/reference/en/p5.Element/mouseWheel.mdx b/src/content/reference/en/p5.Element/mouseWheel.mdx new file mode 100644 index 0000000000..14cf44fb2e --- /dev/null +++ b/src/content/reference/en/p5.Element/mouseWheel.mdx @@ -0,0 +1,126 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseWheel +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

Calls a function when the mouse wheel scrolls over th element.

+ +

The callback function, fxn, is passed an event + object. event has + + two numeric properties, deltaY and deltaX. + event.deltaY is + + negative if the mouse wheel rotates away from the user. It's positive if + + the mouse wheel rotates toward the user. event.deltaX is positive + if + + the mouse wheel moves to the right. It's negative if the mouse wheel moves + + to the left.

+ +

Calling myElement.mouseWheel(false) disables the function.

+line: 466 +params: + - name: fxn + description: | +

function to call when the mouse wheel is + scrolled over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // mouse wheel moves. + cnv.mouseWheel(randomColor); + + describe('A gray square changes color when the user scrolls the mouse wheel over the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the mouse wheel moves. + cnv.mouseWheel(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user scrolls the mouse wheel over the canvas.'); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call changeBackground() when the + // mouse wheel moves. + cnv.mouseWheel(changeBackground); + + describe('A gray square. When the mouse wheel scrolls over the square, it changes color and displays shapes.'); + } + + function changeBackground(event) { + // Change the background color + // based on deltaY. + if (event.deltaY > 0) { + background('deeppink'); + } else if (event.deltaY < 0) { + background('cornflowerblue'); + } else { + background(200); + } + + // Draw a shape based on deltaX. + if (event.deltaX > 0) { + circle(50, 50, 20); + } else if (event.deltaX < 0) { + square(40, 40, 20); + } + } + +
+chainable: true +--- + + +# mouseWheel diff --git a/src/content/reference/en/p5.Element/parent.mdx b/src/content/reference/en/p5.Element/parent.mdx new file mode 100644 index 0000000000..0fff8904be --- /dev/null +++ b/src/content/reference/en/p5.Element/parent.mdx @@ -0,0 +1,130 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: parent +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

Attaches this element to a parent element.

+ +

For example, a <div></div> element may be used as + a box to + + hold two pieces of text, a header and a paragraph. The + + <div></div> is the parent element of both the header + and + + paragraph.

+ +

The parameter parent can have one of three types. + parent can be a + + string with the parent element's ID, as in + + myElement.parent('container'). It can also be another + + p5.Element object, as in + + myElement.parent(myDiv). Finally, parent can be an + HTMLElement + + object, as in myElement.parent(anotherElement).

+ +

Calling myElement.parent() without an argument returns this + element's + + parent.

+line: 105 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + background(200); + + // Create a div element. + let div = createDiv(); + // Place the div in the top-left corner. + div.position(10, 20); + // Set its width and height. + div.size(80, 60); + // Set its background color to white + div.style('background-color', 'white'); + // Align any text to the center. + div.style('text-align', 'center'); + // Set its ID to "container". + div.id('container'); + + // Create a paragraph element. + let p = createP('p5*js'); + // Make the div its parent + // using its ID "container". + p.parent('container'); + + describe('The text "p5*js" written in black at the center of a white rectangle. The rectangle is inside a gray square.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create rectangular div element. + let div = createDiv(); + // Place the div in the top-left corner. + div.position(10, 20); + // Set its width and height. + div.size(80, 60); + // Set its background color and align + // any text to the center. + div.style('background-color', 'white'); + div.style('text-align', 'center'); + + // Create a paragraph element. + let p = createP('p5*js'); + // Make the div its parent. + p.parent(div); + + describe('The text "p5*js" written in black at the center of a white rectangle. The rectangle is inside a gray square.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create rectangular div element. + let div = createDiv(); + // Place the div in the top-left corner. + div.position(10, 20); + // Set its width and height. + div.size(80, 60); + // Set its background color and align + // any text to the center. + div.style('background-color', 'white'); + div.style('text-align', 'center'); + + // Create a paragraph element. + let p = createP('p5*js'); + // Make the div its parent + // using the underlying + // HTMLElement. + p.parent(div.elt); + + describe('The text "p5*js" written in black at the center of a white rectangle. The rectangle is inside a gray square.'); + } + +
+chainable: true +--- + + +# parent diff --git a/src/content/reference/en/p5.Element/position.mdx b/src/content/reference/en/p5.Element/position.mdx new file mode 100644 index 0000000000..4e9f466726 --- /dev/null +++ b/src/content/reference/en/p5.Element/position.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: position +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Sets the position of the element. If no position type argument is given, + the + position will be relative to (0, 0) of the window. + Essentially, this sets position:absolute and left and top + properties of style. If an optional third argument specifying position type is given, + the x and y-coordinates will be interpreted based on the positioning scheme. + If no arguments given, the function returns the x and y position of the element. + found documentation on how to be more specific with object type + https://stackoverflow.com/questions/14714314/how-do-i-comment-object-literals-in-yuidoc

+line: 2584 +itemtype: method +class: p5.Element +example: + - |2- + +
+ function setup() { + let cnv = createCanvas(100, 100); + // positions canvas 50px to the right and 100px + // below upper left corner of the window + cnv.position(50, 100); + } +
+
+ function setup() { + let cnv = createCanvas(100, 100); + // positions canvas at upper left corner of the window + // with a 'fixed' position type + cnv.position(0, 0, 'fixed'); + } +
+return: + description: >- + object of form { x: 0, y: 0 } containing the position of the element in an + object + type: Object +chainable: false +--- + + +# position diff --git a/src/content/reference/en/p5.Element/remove.mdx b/src/content/reference/en/p5.Element/remove.mdx new file mode 100644 index 0000000000..a08929f00f --- /dev/null +++ b/src/content/reference/en/p5.Element/remove.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: remove +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Removes the element, stops all audio/video streams, and removes all + callback functions.

+line: 3299 +itemtype: method +class: p5.Element +example: + - |- + +
+ + let p; + + function setup() { + background(200); + + // Create a paragraph element. + p = createP('p5*js'); + p.position(10, 10); + + describe('The text "p5*js" written at the center of a gray square. '); + } + + // Remove the paragraph when double-clicked. + function doubleClicked() { + p.remove(); + } + +
+chainable: false +--- + + +# remove diff --git a/src/content/reference/en/p5.Element/removeAttribute.mdx b/src/content/reference/en/p5.Element/removeAttribute.mdx new file mode 100644 index 0000000000..869684638c --- /dev/null +++ b/src/content/reference/en/p5.Element/removeAttribute.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeAttribute +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Removes an attribute from the element.

+ +

The parameter attr is the attribute's name as a string. For + example, + + calling myElement.removeAttribute('align') removes its + align + + attribute if it's been set.

+line: 2948 +params: + - name: attr + description: | +

attribute to remove.

+ type: String +itemtype: method +class: p5.Element +example: + - |- + +
+ + let p; + + function setup() { + background(200); + + // Create a paragraph element and place it + // in the center of the canvas. + // Set its "align" attribute to "center". + p = createP('hi'); + p.position(0, 20); + p.attribute('align', 'center'); + + describe('The text "hi" written in black at the center of a gray square. The text moves to the left edge when double-clicked.'); + } + + function doubleClicked() { + p.removeAttribute('align'); + } + +
+chainable: true +--- + + +# removeAttribute diff --git a/src/content/reference/en/p5.Element/removeClass.mdx b/src/content/reference/en/p5.Element/removeClass.mdx new file mode 100644 index 0000000000..ec8442146f --- /dev/null +++ b/src/content/reference/en/p5.Element/removeClass.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeClass +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Removes specified class from the element.

+line: 2348 +params: + - name: class + description: | +

name of class to remove

+ type: String +itemtype: method +class: p5.Element +example: + - |2- + +
+ // In this example, a class is set when the div is created + // and removed when mouse is pressed. This could link up + // with a CSS style rule to toggle style properties. + let div; + function setup() { + div = createDiv('div'); + div.addClass('myClass'); + } + function mousePressed() { + div.removeClass('myClass'); + } +
+chainable: true +--- + + +# removeClass diff --git a/src/content/reference/en/p5.Element/show.mdx b/src/content/reference/en/p5.Element/show.mdx new file mode 100644 index 0000000000..6a5728ab41 --- /dev/null +++ b/src/content/reference/en/p5.Element/show.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: show +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Shows the current element.

+line: 3077 +itemtype: method +class: p5.Element +example: + - |- + +
+ + let p; + + function setup() { + background(200); + + // Create a paragraph element and hide it. + p = createP('p5*js'); + p.position(10, 10); + p.hide(); + + describe('A gray square. The text "p5*js" appears when the user double-clicks the square.'); + } + + // Show the paragraph when double-clicked. + function doubleClicked() { + p.show(); + } + +
+chainable: true +--- + + +# show diff --git a/src/content/reference/en/p5.Element/size.mdx b/src/content/reference/en/p5.Element/size.mdx new file mode 100644 index 0000000000..fcc70ae855 --- /dev/null +++ b/src/content/reference/en/p5.Element/size.mdx @@ -0,0 +1,132 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: size +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Sets the element's width and height.

+ +

Calling myElement.size() without an argument returns the + element's size + + as an object with the properties width and height. + For example, + { width: 20, height: 10 }.

+

The first parameter, width, is optional. It's a number used to + set the + + element's width. Calling myElement.size(10)

+ +

The second parameter, 'height, is also optional. It's a number used + to set the element's height. For example, calling myElement.size(20, + 10)` sets the element's width to 20 pixels and height + + to 10 pixels.

+ +

The constant AUTO can be used to adjust one dimension at a + time while + + maintaining the aspect ratio, which is width / height. For + example, + + consider an element that's 200 pixels wide and 100 pixels tall. Calling + + myElement.size(20, AUTO) sets the width to 20 pixels and height + to 10 + + pixels.

+ +

Note: In the case of elements that need to load data, such as images, wait + + to call myElement.size() until after the data loads.

+line: 3140 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + background(200); + + // Create a pink div element and place it at + // the top-left corner. + let div = createDiv(); + div.position(10, 10); + div.style('background-color', 'deeppink'); + + // Set the div's width to 80 pixels and + // height to 20 pixels. + div.size(80, 20); + + describe('A gray square with a pink rectangle near its top.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create a pink div element and place it at + // the top-left corner. + let div = createDiv(); + div.position(10, 10); + div.style('background-color', 'deeppink'); + + // Set the div's width to 80 pixels and + // height to 40 pixels. + div.size(80, 40); + + // Get the div's size as an object. + let s = div.size(); + // Write the div's dimensions. + div.html(`${s.width} x ${s.height}`); + + describe('A gray square with a pink rectangle near its top. The text "80 x 40" is written within the rectangle.'); + } + +
+ +
+ + function setup() { + background(200); + + // Load an image of an astronaut on the moon + // and place it at the top-left of the canvas. + let img1 = createImg( + 'assets/moonwalk.jpg', + 'An astronaut walking on the moon', + '' + ); + img1.position(0, 0); + + // Load an image of an astronaut on the moon + // and place it at the top-left of the canvas. + // Resize the image once it's loaded. + let img2 = createImg( + 'assets/moonwalk.jpg', + 'An astronaut walking on the moon', + '', + () => { + img2.size(50, AUTO); + } + ); + img2.position(0, 0); + + describe('A gray square two copies of a space image at the top-left. The copy in front is smaller.'); + } + +
+return: + description: width and height of the element in an object. + type: Object +chainable: false +--- + + +# size diff --git a/src/content/reference/en/p5.Element/style.mdx b/src/content/reference/en/p5.Element/style.mdx new file mode 100644 index 0000000000..0280b2ee1b --- /dev/null +++ b/src/content/reference/en/p5.Element/style.mdx @@ -0,0 +1,127 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: style +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Applies a style to an element by adding a + + CSS declaration.

+ +

The first parameter, property, is a string. If the name of a + style + + property is passed, as in myElement.style('color'), the method + returns + + the current value as a string or null if it hasn't been set. If a + + property:style string is passed, as in + + myElement.style('color:deeppink'), the method sets + property to + + value.

+ +

The second parameter, value, is optional. It sets the + property's value. + + value can be a string, as in + + myElement.style('color', 'deeppink'), or a + + p5.Color object, as in + + myElement.style('color', myColor).

+line: 2704 +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + background(200); + + // Create a paragraph element and + // set its font color to "deeppink". + let p = createP('p5*js'); + p.position(25, 20); + p.style('color', 'deeppink'); + + describe('The text p5*js written in pink on a gray background.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create a p5.Color object. + let c = color('deeppink'); + + // Create a paragraph element and + // set its font color using a + // p5.Color object. + let p = createP('p5*js'); + p.position(25, 20); + p.style('color', c); + + describe('The text p5*js written in pink on a gray background.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create a paragraph element and + // set its font color to "deeppink" + // using property:value syntax. + let p = createP('p5*js'); + p.position(25, 20); + p.style('color:deeppink'); + + describe('The text p5*js written in pink on a gray background.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create an empty paragraph element + // and set its font color to "deeppink". + let p = createP(); + p.position(5, 5); + p.style('color', 'deeppink'); + + // Get the element's color as an + // RGB color string. + let c = p.style('color'); + + // Set the element's inner HTML + // using the RGB color string. + p.html(c); + + describe('The text "rgb(255, 20, 147)" written in pink on a gray background.'); + } + +
+return: + description: value of the property. + type: String +chainable: false +--- + + +# style diff --git a/src/content/reference/en/p5.Element/toggleClass.mdx b/src/content/reference/en/p5.Element/toggleClass.mdx new file mode 100644 index 0000000000..620ead9e51 --- /dev/null +++ b/src/content/reference/en/p5.Element/toggleClass.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toggleClass +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Toggles element class.

+line: 2408 +params: + - name: c + description: | +

class name to toggle

+ type: String +itemtype: method +class: p5.Element +example: + - |2- + +
+ let div; + function setup() { + div = createDiv('div'); + div.addClass('show'); + } + function mousePressed() { + div.toggleClass('show'); + } +
+chainable: true +--- + + +# toggleClass diff --git a/src/content/reference/en/p5.Element/touchEnded.mdx b/src/content/reference/en/p5.Element/touchEnded.mdx new file mode 100644 index 0000000000..e414185b7d --- /dev/null +++ b/src/content/reference/en/p5.Element/touchEnded.mdx @@ -0,0 +1,77 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchEnded +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the user stops touching the element. Calling + myElement.touchMoved(false) disables the function.

+

Note: Touch functions only work on mobile devices.

+line: 1023 +params: + - name: fxn + description: | +

function to call when the touch + ends. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // user touches the canvas, + // then lifts their finger. + cnv.touchEnded(randomColor); + + describe('A gray square changes color when the user touches the canvas, then lifts their finger.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the user touches the + // canvas, then lifts their + // finger. + cnv.touchEnded(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user touches the canvas, then lifts their finger.'); + } + +
+chainable: true +--- + + +# touchEnded diff --git a/src/content/reference/en/p5.Element/touchMoved.mdx b/src/content/reference/en/p5.Element/touchMoved.mdx new file mode 100644 index 0000000000..ad57d4c3c5 --- /dev/null +++ b/src/content/reference/en/p5.Element/touchMoved.mdx @@ -0,0 +1,77 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchMoved +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the user touches the element and moves their + finger. Calling myElement.touchMoved(false) disables the + function.

+

Note: Touch functions only work on mobile devices.

+line: 956 +params: + - name: fxn + description: | +

function to call when the touch + moves over the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // user touches the canvas + // and moves. + cnv.touchMoved(randomColor); + + describe('A gray square changes color when the user touches the canvas and moves.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the user touches the + // canvas and moves. + cnv.touchMoved(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user touches the canvas and moves.'); + } + +
+chainable: true +--- + + +# touchMoved diff --git a/src/content/reference/en/p5.Element/touchStarted.mdx b/src/content/reference/en/p5.Element/touchStarted.mdx new file mode 100644 index 0000000000..cfc144f869 --- /dev/null +++ b/src/content/reference/en/p5.Element/touchStarted.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchStarted +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: | +

Calls a function when the element is touched. Calling + myElement.touchStarted(false) disables the function.

+

Note: Touch functions only work on mobile devices.

+line: 891 +params: + - name: fxn + description: | +

function to call when the touch + starts. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5.Element +example: + - |- + +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Call randomColor() when the + // user touches the canvas. + cnv.touchStarted(randomColor); + + describe('A gray square changes color when the user touches the canvas.'); + } + + // Paint the background either + // red, yellow, blue, or green. + function randomColor() { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + } + +
+ +
+ + function setup() { + // Create a canvas element and + // assign it to cnv. + let cnv = createCanvas(100, 100); + + background(200); + + // Paint the background either + // red, yellow, blue, or green + // when the user touches the + // canvas. + cnv.touchStarted(() => { + let c = random(['red', 'yellow', 'blue', 'green']); + background(c); + }); + + describe('A gray square changes color when the user touches the canvas.'); + } + +
+chainable: true +--- + + +# touchStarted diff --git a/src/content/reference/en/p5.Element/value.mdx b/src/content/reference/en/p5.Element/value.mdx new file mode 100644 index 0000000000..bbafec2ca2 --- /dev/null +++ b/src/content/reference/en/p5.Element/value.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: value +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Returns or sets the element's value.

+ +

Calling myElement.value() returns the element's current + value.

+ +

The parameter, value, is an optional number or string. If + provided, + + as in myElement.value(123), it's used to set the element's + value.

+line: 2997 +itemtype: method +class: p5.Element +example: + - |- + +
+ + let inp; + + function setup() { + // Create a text input and place it + // beneath the canvas. Set its default + // value to "hello". + inp = createInput('hello'); + inp.position(0, 100); + + describe('The text from an input box is displayed on a gray square.'); + } + + function draw() { + background(200); + + // Use the input's value to display a message. + let msg = inp.value(); + text(msg, 0, 55); + } + +
+ +
+ + let inp; + + function setup() { + // Create a text input and place it + // beneath the canvas. Set its default + // value to "hello". + inp = createInput('hello'); + inp.position(0, 100); + + describe('The text from an input box is displayed on a gray square. The text resets to "hello" when the user double-clicks the square.'); + } + + function draw() { + background(200); + + // Use the input's value to display a message. + let msg = inp.value(); + text(msg, 0, 55); + } + + // Reset the input's value. + function doubleClicked() { + inp.value('hello'); + } + +
+return: + description: value of the element. + type: String|Number +chainable: false +--- + + +# value diff --git a/src/content/reference/en/p5.Element/width.mdx b/src/content/reference/en/p5.Element/width.mdx new file mode 100644 index 0000000000..9bf960eb30 --- /dev/null +++ b/src/content/reference/en/p5.Element/width.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: width +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: '' +line: 91 +itemtype: property +class: p5.Element +chainable: false +--- + + +# width diff --git a/src/content/reference/en/p5.Envelope/add.mdx b/src/content/reference/en/p5.Envelope/add.mdx new file mode 100644 index 0000000000..d057c75fca --- /dev/null +++ b/src/content/reference/en/p5.Envelope/add.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: add +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Add a value to the p5.Oscillator's output amplitude, + and return the oscillator. Calling this method + again will override the initial add() with new values.

+line: 5460 +params: + - name: number + description: | +

Constant number to add

+ type: Number +itemtype: method +class: p5.Envelope +return: + description: |- + Envelope Returns this envelope + with scaled output + type: p5.Envelope +chainable: false +--- + + +# add diff --git a/src/content/reference/en/p5.Envelope/attackLevel.mdx b/src/content/reference/en/p5.Envelope/attackLevel.mdx new file mode 100644 index 0000000000..de25c50c37 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/attackLevel.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: attackLevel +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Level once attack is complete.

+line: 4772 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# attackLevel diff --git a/src/content/reference/en/p5.Envelope/attackTime.mdx b/src/content/reference/en/p5.Envelope/attackTime.mdx new file mode 100644 index 0000000000..6631e4854e --- /dev/null +++ b/src/content/reference/en/p5.Envelope/attackTime.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: attackTime +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Time until envelope reaches attackLevel

+line: 4767 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# attackTime diff --git a/src/content/reference/en/p5.Envelope/decayLevel.mdx b/src/content/reference/en/p5.Envelope/decayLevel.mdx new file mode 100644 index 0000000000..7e246aa737 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/decayLevel.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: decayLevel +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Level after decay. The envelope will sustain here until it is released.

+line: 4784 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# decayLevel diff --git a/src/content/reference/en/p5.Envelope/decayTime.mdx b/src/content/reference/en/p5.Envelope/decayTime.mdx new file mode 100644 index 0000000000..f564b2e51f --- /dev/null +++ b/src/content/reference/en/p5.Envelope/decayTime.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: decayTime +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Time until envelope reaches decayLevel.

+line: 4778 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# decayTime diff --git a/src/content/reference/en/p5.Envelope/mult.mdx b/src/content/reference/en/p5.Envelope/mult.mdx new file mode 100644 index 0000000000..102e763528 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/mult.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mult +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Multiply the p5.Envelope's output amplitude + by a fixed value. Calling this method + again will override the initial mult() with new values.

+line: 5479 +params: + - name: number + description: | +

Constant number to multiply

+ type: Number +itemtype: method +class: p5.Envelope +return: + description: |- + Envelope Returns this envelope + with scaled output + type: p5.Envelope +chainable: false +--- + + +# mult diff --git a/src/content/reference/en/p5.Envelope/play.mdx b/src/content/reference/en/p5.Envelope/play.mdx new file mode 100644 index 0000000000..5ddcdd7197 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/play.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

Play tells the envelope to start acting on a given input. + If the input is a p5.sound object (i.e. AudioIn, Oscillator, + SoundFile), then Envelope will control its output volume. + Envelopes can also be used to control any + Web Audio Audio Param.

+line: 5078 +params: + - name: unit + description: | +

A p5.sound object or + Web Audio Param.

+ type: Object + - name: startTime + description: | +

time from now (in seconds) at which to play

+ type: Number + optional: true + - name: sustainTime + description: | +

time to sustain before releasing the envelope

+ type: Number + optional: true +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let attackLevel = 1.0; + let releaseLevel = 0; + + let attackTime = 0.001; + let decayTime = 0.2; + let susPercent = 0.2; + let releaseTime = 0.5; + + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playEnv); + + env = new p5.Envelope(); + triOsc = new p5.Oscillator('triangle'); + triOsc.amp(env); + triOsc.freq(220); + triOsc.start(); + } + + function draw() { + background(220); + text('tap here to play', 5, 20); + attackTime = map(mouseX, 0, width, 0, 1.0); + attackLevel = map(mouseY, height, 0, 0, 1.0); + text('attack time: ' + attackTime, 5, height - 40); + text('attack level: ' + attackLevel, 5, height - 20); + } + + function playEnv() { + // ensure that audio is enabled + userStartAudio(); + + env.setADSR(attackTime, decayTime, susPercent, releaseTime); + env.setRange(attackLevel, releaseLevel); + env.play(); + } +
+chainable: false +--- + + +# play diff --git a/src/content/reference/en/p5.Envelope/ramp.mdx b/src/content/reference/en/p5.Envelope/ramp.mdx new file mode 100644 index 0000000000..835d6b0e17 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/ramp.mdx @@ -0,0 +1,84 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ramp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Exponentially ramp to a value using the first two + + values from setADSR(attackTime, + decayTime) + + as + + time constants for simple exponential ramps. + + If the value is higher than current value, it uses attackTime, + + while a decrease uses decayTime.

+line: 5350 +params: + - name: unit + description: | +

p5.sound Object or Web Audio Param

+ type: Object + - name: secondsFromNow + description: | +

When to trigger the ramp

+ type: Number + - name: v + description: | +

Target value

+ type: Number + - name: v2 + description: | +

Second target value

+ type: Number + optional: true +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let env, osc, amp; + + let attackTime = 0.001; + let decayTime = 0.2; + let attackLevel = 1; + let decayLevel = 0; + + function setup() { + let cnv = createCanvas(100, 100); + fill(0,255,0); + noStroke(); + + env = new p5.Envelope(); + env.setADSR(attackTime, decayTime); + osc = new p5.Oscillator(); + osc.amp(env); + amp = new p5.Amplitude(); + + cnv.mousePressed(triggerRamp); + } + + function triggerRamp() { + // ensures audio is enabled. See also: `userStartAudio` + osc.start(); + + env.ramp(osc, 0, attackLevel, decayLevel); + } + + function draw() { + background(20); + text('tap to play', 10, 20); + let h = map(amp.getLevel(), 0, 0.4, 0, height);; + rect(0, height, width, -h); + } +
+chainable: false +--- + + +# ramp diff --git a/src/content/reference/en/p5.Envelope/releaseLevel.mdx b/src/content/reference/en/p5.Envelope/releaseLevel.mdx new file mode 100644 index 0000000000..de608998d6 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/releaseLevel.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: releaseLevel +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Level at the end of the release.

+line: 4796 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# releaseLevel diff --git a/src/content/reference/en/p5.Envelope/releaseTime.mdx b/src/content/reference/en/p5.Envelope/releaseTime.mdx new file mode 100644 index 0000000000..ebe59da63c --- /dev/null +++ b/src/content/reference/en/p5.Envelope/releaseTime.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: releaseTime +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Duration of the release portion of the envelope.

+line: 4790 +itemtype: property +class: p5.Envelope +chainable: false +--- + + +# releaseTime diff --git a/src/content/reference/en/p5.Envelope/scale.mdx b/src/content/reference/en/p5.Envelope/scale.mdx new file mode 100644 index 0000000000..b104333cd6 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/scale.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: scale +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Scale this envelope's amplitude values to a given + range, and return the envelope. Calling this method + again will override the initial scale() with new values.

+line: 5498 +params: + - name: inMin + description: | +

input range minumum

+ type: Number + - name: inMax + description: | +

input range maximum

+ type: Number + - name: outMin + description: | +

input range minumum

+ type: Number + - name: outMax + description: | +

input range maximum

+ type: Number +itemtype: method +class: p5.Envelope +return: + description: |- + Envelope Returns this envelope + with scaled output + type: p5.Envelope +chainable: false +--- + + +# scale diff --git a/src/content/reference/en/p5.Envelope/set.mdx b/src/content/reference/en/p5.Envelope/set.mdx new file mode 100644 index 0000000000..1fc81cdae7 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/set.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Reset the envelope with a series of time/value pairs.

+line: 4833 +params: + - name: attackTime + description: | +

Time (in seconds) before level + reaches attackLevel

+ type: Number + - name: attackLevel + description: | +

Typically an amplitude between + 0.0 and 1.0

+ type: Number + - name: decayTime + description: | +

Time

+ type: Number + - name: decayLevel + description: | +

Amplitude (In a standard ADSR envelope, + decayLevel = sustainLevel)

+ type: Number + - name: releaseTime + description: | +

Release Time (in seconds)

+ type: Number + - name: releaseLevel + description: | +

Amplitude

+ type: Number +itemtype: method +class: p5.Envelope +example: + - | + +
+ let attackTime; + let l1 = 0.7; // attack level 0.0 to 1.0 + let t2 = 0.3; // decay time in seconds + let l2 = 0.1; // decay level 0.0 to 1.0 + let l3 = 0.2; // release time in seconds + + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playSound); + + env = new p5.Envelope(); + triOsc = new p5.Oscillator('triangle'); + } + + function draw() { + background(220); + text('tap here to play', 5, 20); + + attackTime = map(mouseX, 0, width, 0.0, 1.0); + text('attack time: ' + attackTime, 5, height - 20); + } + + // mouseClick triggers envelope if over canvas + function playSound() { + env.set(attackTime, l1, t2, l2, l3); + + triOsc.start(); + env.play(triOsc); + } +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Envelope/setADSR.mdx b/src/content/reference/en/p5.Envelope/setADSR.mdx new file mode 100644 index 0000000000..8f818d80db --- /dev/null +++ b/src/content/reference/en/p5.Envelope/setADSR.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setADSR +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Set values like a traditional + + + + ADSR envelope + + .

+line: 4895 +params: + - name: attackTime + description: | +

Time (in seconds before envelope + reaches Attack Level

+ type: Number + - name: decayTime + description: | +

Time (in seconds) before envelope + reaches Decay/Sustain Level

+ type: Number + optional: true + - name: susRatio + description: | +

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1, + where 1.0 = attackLevel, 0.0 = releaseLevel. + The susRatio determines the decayLevel and the level at which the + sustain portion of the envelope will sustain. + For example, if attackLevel is 0.4, releaseLevel is 0, + and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is + increased to 1.0 (using setRange), + then decayLevel would increase proportionally, to become 0.5.

+ type: Number + optional: true + - name: releaseTime + description: | +

Time in seconds from now (defaults to 0)

+ type: Number + optional: true +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let attackLevel = 1.0; + let releaseLevel = 0; + + let attackTime = 0.001; + let decayTime = 0.2; + let susPercent = 0.2; + let releaseTime = 0.5; + + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playEnv); + + env = new p5.Envelope(); + triOsc = new p5.Oscillator('triangle'); + triOsc.amp(env); + triOsc.freq(220); + } + + function draw() { + background(220); + text('tap here to play', 5, 20); + attackTime = map(mouseX, 0, width, 0, 1.0); + text('attack time: ' + attackTime, 5, height - 40); + } + + function playEnv() { + triOsc.start(); + env.setADSR(attackTime, decayTime, susPercent, releaseTime); + env.play(); + } +
+chainable: false +--- + + +# setADSR diff --git a/src/content/reference/en/p5.Envelope/setExp.mdx b/src/content/reference/en/p5.Envelope/setExp.mdx new file mode 100644 index 0000000000..5aa3a5d710 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/setExp.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setExp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set whether the envelope ramp is linear (default) or exponential. + Exponential ramps can be useful because we perceive amplitude + and frequency logarithmically.

+line: 5055 +params: + - name: isExp + description: | +

true is exponential, false is linear

+ type: Boolean +itemtype: method +class: p5.Envelope +chainable: false +--- + + +# setExp diff --git a/src/content/reference/en/p5.Envelope/setInput.mdx b/src/content/reference/en/p5.Envelope/setInput.mdx new file mode 100644 index 0000000000..4b0403c71f --- /dev/null +++ b/src/content/reference/en/p5.Envelope/setInput.mdx @@ -0,0 +1,27 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setInput +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Assign a parameter to be controlled by this envelope. + If a p5.Sound object is given, then the p5.Envelope will control its + output gain. If multiple inputs are provided, the env will + control all of them.

+line: 5037 +params: + - name: inputs + description: | +

A p5.sound object or + Web Audio Param.

+ type: Object + optional: true + multiple: true +itemtype: method +class: p5.Envelope +chainable: false +--- + + +# setInput diff --git a/src/content/reference/en/p5.Envelope/setRange.mdx b/src/content/reference/en/p5.Envelope/setRange.mdx new file mode 100644 index 0000000000..5481ef2b54 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/setRange.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setRange +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set max (attackLevel) and min (releaseLevel) of envelope.

+line: 4964 +params: + - name: aLevel + description: | +

attack level (defaults to 1)

+ type: Number + - name: rLevel + description: | +

release level (defaults to 0)

+ type: Number +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let attackLevel = 1.0; + let releaseLevel = 0; + + let attackTime = 0.001; + let decayTime = 0.2; + let susPercent = 0.2; + let releaseTime = 0.5; + + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playEnv); + + env = new p5.Envelope(); + triOsc = new p5.Oscillator('triangle'); + triOsc.amp(env); + triOsc.freq(220); + } + + function draw() { + background(220); + text('tap here to play', 5, 20); + attackLevel = map(mouseY, height, 0, 0, 1.0); + text('attack level: ' + attackLevel, 5, height - 20); + } + + function playEnv() { + triOsc.start(); + env.setRange(attackLevel, releaseLevel); + env.play(); + } +
+chainable: false +--- + + +# setRange diff --git a/src/content/reference/en/p5.Envelope/triggerAttack.mdx b/src/content/reference/en/p5.Envelope/triggerAttack.mdx new file mode 100644 index 0000000000..740cca51e9 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/triggerAttack.mdx @@ -0,0 +1,73 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: triggerAttack +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the Attack, and Decay portion of the Envelope. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go. Input can be + any p5.sound object, or a + Web Audio Param.

+line: 5148 +params: + - name: unit + description: | +

p5.sound Object or Web Audio Param

+ type: Object + - name: secondsFromNow + description: | +

time from now (in seconds)

+ type: Number +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let attackTime = 0.001; + let decayTime = 0.2; + let susPercent = 0.3; + let releaseTime = 0.4; + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + background(220); + textAlign(CENTER); + textSize(10); + text('tap to triggerAttack', width/2, height/2); + + env = new p5.Envelope(); + env.setADSR(attackTime, decayTime, susPercent, releaseTime); + env.setRange(1.0, 0.0); + triOsc = new p5.Oscillator('triangle'); + triOsc.freq(220); + + cnv.mousePressed(envAttack); + } + + function envAttack() { + background(0, 255, 255); + text('release to release', width/2, height/2); + + // ensures audio is enabled. See also: `userStartAudio` + triOsc.start(); + + env.triggerAttack(triOsc); + } + + function mouseReleased() { + background(220); + text('tap to triggerAttack', width/2, height/2); + + env.triggerRelease(triOsc); + } +
+chainable: false +--- + + +# triggerAttack diff --git a/src/content/reference/en/p5.Envelope/triggerRelease.mdx b/src/content/reference/en/p5.Envelope/triggerRelease.mdx new file mode 100644 index 0000000000..8c38b4db03 --- /dev/null +++ b/src/content/reference/en/p5.Envelope/triggerRelease.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: triggerRelease +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the Release of the Envelope. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+line: 5256 +params: + - name: unit + description: | +

p5.sound Object or Web Audio Param

+ type: Object + - name: secondsFromNow + description: | +

time to trigger the release

+ type: Number +itemtype: method +class: p5.Envelope +example: + - |- + +
+ let attackTime = 0.001; + let decayTime = 0.2; + let susPercent = 0.3; + let releaseTime = 0.4; + let env, triOsc; + + function setup() { + let cnv = createCanvas(100, 100); + background(220); + textAlign(CENTER); + textSize(10); + text('tap to triggerAttack', width/2, height/2); + + env = new p5.Envelope(); + env.setADSR(attackTime, decayTime, susPercent, releaseTime); + env.setRange(1.0, 0.0); + triOsc = new p5.Oscillator('triangle'); + triOsc.freq(220); + + cnv.mousePressed(envAttack); + } + + function envAttack() { + background(0, 255, 255); + text('release to release', width/2, height/2); + + // ensures audio is enabled. See also: `userStartAudio` + triOsc.start(); + + env.triggerAttack(triOsc); + } + + function mouseReleased() { + background(220); + text('tap to triggerAttack', width/2, height/2); + + env.triggerRelease(triOsc); + } +
+chainable: false +--- + + +# triggerRelease diff --git a/src/content/reference/en/p5.FFT/analyze.mdx b/src/content/reference/en/p5.FFT/analyze.mdx new file mode 100644 index 0000000000..470376979e --- /dev/null +++ b/src/content/reference/en/p5.FFT/analyze.mdx @@ -0,0 +1,92 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: analyze +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns an array of amplitude values (between 0 and 255) + across the frequency spectrum. Length is equal to FFT bins + (1024 by default). The array indices correspond to frequencies + (i.e. pitches), from the lowest to the highest that humans can + hear. Each value represents amplitude at that slice of the + frequency spectrum. Must be called prior to using + getEnergy().

+line: 3553 +params: + - name: bins + description: | +

Must be a power of two between + 16 and 1024. Defaults to 1024.

+ type: Number + optional: true + - name: scale + description: | +

If "dB," returns decibel + float measurements between + -140 and 0 (max). + Otherwise returns integers from 0-255.

+ type: Number + optional: true +itemtype: method +class: p5.FFT +example: + - |+ + +
+ let osc, fft; + + function setup(){ + let cnv = createCanvas(100,100); + cnv.mousePressed(startSound); + osc = new p5.Oscillator(); + osc.amp(0); + fft = new p5.FFT(); + } + + function draw(){ + background(220); + + let freq = map(mouseX, 0, windowWidth, 20, 10000); + freq = constrain(freq, 1, 20000); + osc.freq(freq); + + let spectrum = fft.analyze(); + noStroke(); + fill(255, 0, 255); + for (let i = 0; i< spectrum.length; i++){ + let x = map(i, 0, spectrum.length, 0, width); + let h = -height + map(spectrum[i], 0, 255, height, 0); + rect(x, height, width / spectrum.length, h ); + } + + stroke(255); + if (!osc.started) { + text('tap here and drag to change frequency', 10, 20, width - 20); + } else { + text(round(freq)+'Hz', 10, 20); + } + } + + function startSound() { + osc.start(); + osc.amp(0.5, 0.2); + } + + function mouseReleased() { + osc.amp(0, 0.2); + } +
+ +return: + description: |- + spectrum Array of energy (amplitude/volume) + values across the frequency spectrum. + Lowest energy (silence) = 0, highest + possible is 255. + type: Array +chainable: false +--- + + +# analyze diff --git a/src/content/reference/en/p5.FFT/getCentroid.mdx b/src/content/reference/en/p5.FFT/getCentroid.mdx new file mode 100644 index 0000000000..14dad1d752 --- /dev/null +++ b/src/content/reference/en/p5.FFT/getCentroid.mdx @@ -0,0 +1,77 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getCentroid +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the + + spectral centroid of the input signal. + NOTE: analyze() must be called prior to getCentroid(). Analyze() + tells the FFT to analyze frequency data, and getCentroid() uses + the results determine the spectral centroid.

+line: 3739 +itemtype: method +class: p5.FFT +example: + - |- + +
+ function setup(){ + cnv = createCanvas(100,100); + cnv.mousePressed(userStartAudio); + sound = new p5.AudioIn(); + sound.start(); + fft = new p5.FFT(); + sound.connect(fft); + } + + function draw() { + if (getAudioContext().state !== 'running') { + background(220); + text('tap here and enable mic to begin', 10, 20, width - 20); + return; + } + let centroidplot = 0.0; + let spectralCentroid = 0; + + background(0); + stroke(0,255,0); + let spectrum = fft.analyze(); + fill(0,255,0); // spectrum is green + + //draw the spectrum + for (let i = 0; i < spectrum.length; i++){ + let x = map(log(i), 0, log(spectrum.length), 0, width); + let h = map(spectrum[i], 0, 255, 0, height); + let rectangle_width = (log(i+1)-log(i))*(width/log(spectrum.length)); + rect(x, height, rectangle_width, -h ) + } + let nyquist = 22050; + + // get the centroid + spectralCentroid = fft.getCentroid(); + + // the mean_freq_index calculation is for the display. + let mean_freq_index = spectralCentroid/(nyquist/spectrum.length); + + centroidplot = map(log(mean_freq_index), 0, log(spectrum.length), 0, width); + + stroke(255,0,0); // the line showing where the centroid is will be red + + rect(centroidplot, 0, width / spectrum.length, height) + noStroke(); + fill(255,255,255); // text is white + text('centroid: ', 10, 20); + text(round(spectralCentroid)+' Hz', 10, 40); + } +
+return: + description: Spectral Centroid Frequency of the spectral centroid in Hz. + type: Number +chainable: false +--- + + +# getCentroid diff --git a/src/content/reference/en/p5.FFT/getEnergy.mdx b/src/content/reference/en/p5.FFT/getEnergy.mdx new file mode 100644 index 0000000000..8026d5cce1 --- /dev/null +++ b/src/content/reference/en/p5.FFT/getEnergy.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getEnergy +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the amount of energy (volume) at a specific + + frequency, or the average amount of energy between two + frequencies. Accepts Number(s) corresponding + to frequency (in Hz), or a "string" corresponding to predefined + frequency ranges ("bass", "lowMid", "mid", "highMid", "treble"). + Returns a range between 0 (no energy/volume at that frequency) and + 255 (maximum energy). + NOTE: analyze() must be called prior to getEnergy(). analyze() + tells the FFT to analyze frequency data, and getEnergy() uses + the results to determine the value at a specific frequency or + range of frequencies.

+line: 3650 +params: + - name: frequency1 + description: | +

Will return a value representing + energy at this frequency. Alternately, + the strings "bass", "lowMid" "mid", + "highMid", and "treble" will return + predefined frequency ranges.

+ type: Number|String + - name: frequency2 + description: | +

If a second frequency is given, + will return average amount of + energy that exists between the + two frequencies.

+ type: Number + optional: true +itemtype: method +class: p5.FFT +return: + description: |- + Energy Energy (volume/amplitude) from + 0 and 255. + type: Number +chainable: false +--- + + +# getEnergy diff --git a/src/content/reference/en/p5.FFT/getOctaveBands.mdx b/src/content/reference/en/p5.FFT/getOctaveBands.mdx new file mode 100644 index 0000000000..bd49b59668 --- /dev/null +++ b/src/content/reference/en/p5.FFT/getOctaveBands.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getOctaveBands +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Calculates and Returns the 1/N + + Octave + Bands + + N defaults to 3 and minimum central frequency to 15.625Hz. + + (1/3 Octave Bands ~= 31 Frequency Bands) + + Setting fCtr0 to a central value of a higher octave will ignore the lower + bands + + and produce less frequency groups.

+line: 3925 +params: + - name: 'N' + description: | +

Specifies the 1/N type of generated octave bands

+ type: Number + - name: fCtr0 + description: | +

Minimum central frequency for the lowest band

+ type: Number +itemtype: method +class: p5.FFT +return: + description: octaveBands Array of octave band objects with their bounds + type: Array +chainable: false +--- + + +# getOctaveBands diff --git a/src/content/reference/en/p5.FFT/linAverages.mdx b/src/content/reference/en/p5.FFT/linAverages.mdx new file mode 100644 index 0000000000..9cc40dbcd4 --- /dev/null +++ b/src/content/reference/en/p5.FFT/linAverages.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: linAverages +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns an array of average amplitude values for a given number + of frequency bands split equally. N defaults to 16. + NOTE: analyze() must be called prior to linAverages(). Analyze() + tells the FFT to analyze frequency data, and linAverages() uses + the results to group them into a smaller set of averages.

+line: 3854 +params: + - name: 'N' + description: | +

Number of returned frequency groups

+ type: Number +itemtype: method +class: p5.FFT +return: + description: linearAverages Array of average amplitude values for each group + type: Array +chainable: false +--- + + +# linAverages diff --git a/src/content/reference/en/p5.FFT/logAverages.mdx b/src/content/reference/en/p5.FFT/logAverages.mdx new file mode 100644 index 0000000000..ab777081c2 --- /dev/null +++ b/src/content/reference/en/p5.FFT/logAverages.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: logAverages +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns an array of average amplitude values of the spectrum, for a given + set of + Octave Bands + NOTE: analyze() must be called prior to logAverages(). Analyze() + tells the FFT to analyze frequency data, and logAverages() uses + the results to group them into a smaller set of averages.

+line: 3889 +params: + - name: octaveBands + description: | +

Array of Octave Bands objects for grouping

+ type: Array +itemtype: method +class: p5.FFT +return: + description: logAverages Array of average amplitude values for each group + type: Array +chainable: false +--- + + +# logAverages diff --git a/src/content/reference/en/p5.FFT/setInput.mdx b/src/content/reference/en/p5.FFT/setInput.mdx new file mode 100644 index 0000000000..bc4ef5a0ed --- /dev/null +++ b/src/content/reference/en/p5.FFT/setInput.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setInput +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the input source for the FFT analysis. If no source is + provided, FFT will analyze all sound in the sketch.

+line: 3476 +params: + - name: source + description: | +

p5.sound object (or web audio API source node)

+ type: Object + optional: true +itemtype: method +class: p5.FFT +chainable: false +--- + + +# setInput diff --git a/src/content/reference/en/p5.FFT/smooth.mdx b/src/content/reference/en/p5.FFT/smooth.mdx new file mode 100644 index 0000000000..5c0771727d --- /dev/null +++ b/src/content/reference/en/p5.FFT/smooth.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: smooth +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Smooth FFT analysis by averaging with the last analysis frame.

+line: 3826 +params: + - name: smoothing + description: | +

0.0 < smoothing < 1.0. + Defaults to 0.8.

+ type: Number +itemtype: method +class: p5.FFT +chainable: false +--- + + +# smooth diff --git a/src/content/reference/en/p5.FFT/waveform.mdx b/src/content/reference/en/p5.FFT/waveform.mdx new file mode 100644 index 0000000000..267962002a --- /dev/null +++ b/src/content/reference/en/p5.FFT/waveform.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: waveform +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns an array of amplitude values (between -1.0 and +1.0) that represent + a snapshot of amplitude readings in a single buffer. Length will be + equal to bins (defaults to 1024). Can be used to draw the waveform + of a sound.

+line: 3501 +params: + - name: bins + description: | +

Must be a power of two between + 16 and 1024. Defaults to 1024.

+ type: Number + optional: true + - name: precision + description: | +

If any value is provided, will return results + in a Float32 Array which is more precise + than a regular array.

+ type: String + optional: true +itemtype: method +class: p5.FFT +return: + description: |- + Array Array of amplitude values (-1 to 1) + over time. Array length = bins. + type: Array +chainable: false +--- + + +# waveform diff --git a/src/content/reference/en/p5.File/data.mdx b/src/content/reference/en/p5.File/data.mdx new file mode 100644 index 0000000000..dcfe178ce6 --- /dev/null +++ b/src/content/reference/en/p5.File/data.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: data +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

A string containing either the file's image data, text contents, or + a parsed object in the case of JSON and + p5.XML objects.

+line: 5173 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displayData() when + // the file loads. + let input = createFileInput(displayData); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its data is written in black.'); + } + + // Display the p5.File's data + // once it loads. + function displayData(file) { + background(200); + + // Display the p5.File's data, + // which looks like a random + // string of characters. + text(file.data, 10, 10, 80, 80); + } + +
+chainable: false +--- + + +# data diff --git a/src/content/reference/en/p5.File/file.mdx b/src/content/reference/en/p5.File/file.mdx new file mode 100644 index 0000000000..821b3ca6b1 --- /dev/null +++ b/src/content/reference/en/p5.File/file.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: file +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Underlying + + File + + object. All File properties and methods are accessible.

+line: 4986 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displayInfo() when + // the file loads. + let input = createFileInput(displayInfo); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its info is written in black.'); + } + + // Use the p5.File once + // it loads. + function displayInfo(file) { + background(200); + + // Display the p5.File's name. + text(file.name, 10, 10, 80, 40); + // Display the p5.File's type and subtype. + text(`${file.type}/${file.subtype}`, 10, 70); + // Display the p5.File's size in bytes. + text(file.size, 10, 90); + } + +
+chainable: false +--- + + +# file diff --git a/src/content/reference/en/p5.File/name.mdx b/src/content/reference/en/p5.File/name.mdx new file mode 100644 index 0000000000..2d244fff88 --- /dev/null +++ b/src/content/reference/en/p5.File/name.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: name +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

The file name as a string.

+line: 5104 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displayName() when + // the file loads. + let input = createFileInput(displayName); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its name is written in black.'); + } + + // Display the p5.File's name + // once it loads. + function displayName(file) { + background(200); + + // Display the p5.File's name. + text(`This is file's name is: ${file.name}`, 10, 10, 80, 80); + } + +
+chainable: false +--- + + +# name diff --git a/src/content/reference/en/p5.File/size.mdx b/src/content/reference/en/p5.File/size.mdx new file mode 100644 index 0000000000..592a44a36b --- /dev/null +++ b/src/content/reference/en/p5.File/size.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: size +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

The number of bytes in the file.

+line: 5138 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displaySize() when + // the file loads. + let input = createFileInput(displaySize); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its size in bytes is written in black.'); + } + + // Display the p5.File's size + // in bytes once it loads. + function displaySize(file) { + background(200); + + // Display the p5.File's size. + text(`This is file has ${file.size} bytes.`, 10, 10, 80, 80); + } + +
+chainable: false +--- + + +# size diff --git a/src/content/reference/en/p5.File/subtype.mdx b/src/content/reference/en/p5.File/subtype.mdx new file mode 100644 index 0000000000..6e9578f705 --- /dev/null +++ b/src/content/reference/en/p5.File/subtype.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: subtype +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

The file subtype as a string. For example, a file with an + 'image' + + MIME type + + may have a subtype such as png or jpeg.

+line: 5068 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displaySubtype() when + // the file loads. + let input = createFileInput(displaySubtype); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its subtype is written in black.'); + } + + // Display the p5.File's type + // once it loads. + function displaySubtype(file) { + background(200); + + // Display the p5.File's subtype. + text(`This is file's subtype is: ${file.subtype}`, 10, 10, 80, 80); + } + +
+chainable: false +--- + + +# subtype diff --git a/src/content/reference/en/p5.File/type.mdx b/src/content/reference/en/p5.File/type.mdx new file mode 100644 index 0000000000..1e779657df --- /dev/null +++ b/src/content/reference/en/p5.File/type.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: type +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

The file + + MIME type + + as a string. For example, 'image', 'text', and so + on.

+line: 5032 +itemtype: property +class: p5.File +example: + - |- + +
+ + // Use the file input to load a + // file and display its info. + + function setup() { + background(200); + + // Create a file input and place it beneath + // the canvas. Call displayType() when + // the file loads. + let input = createFileInput(displayType); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user loads a file, its type is written in black.'); + } + + // Display the p5.File's type + // once it loads. + function displayType(file) { + background(200); + + // Display the p5.File's type. + text(`This is file's type is: ${file.type}`, 10, 10, 80, 80); + } + +
+chainable: false +--- + + +# type diff --git a/src/content/reference/en/p5.Filter/biquadFilter.mdx b/src/content/reference/en/p5.Filter/biquadFilter.mdx new file mode 100644 index 0000000000..6e3adbbd65 --- /dev/null +++ b/src/content/reference/en/p5.Filter/biquadFilter.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: biquadFilter +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The p5.Filter is built with a + + Web Audio BiquadFilter Node.

+line: 6719 +itemtype: property +class: p5.Filter +chainable: false +--- + + +# biquadFilter diff --git a/src/content/reference/en/p5.Filter/freq.mdx b/src/content/reference/en/p5.Filter/freq.mdx new file mode 100644 index 0000000000..9b43c60fe2 --- /dev/null +++ b/src/content/reference/en/p5.Filter/freq.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: freq +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the filter frequency, in Hz, from 10 to 22050 (the range of + human hearing, although in reality most people hear in a narrower + range).

+line: 6781 +params: + - name: freq + description: | +

Filter Frequency

+ type: Number + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Filter +return: + description: value Returns the current frequency value + type: Number +chainable: false +--- + + +# freq diff --git a/src/content/reference/en/p5.Filter/gain.mdx b/src/content/reference/en/p5.Filter/gain.mdx new file mode 100644 index 0000000000..e0333b9c9f --- /dev/null +++ b/src/content/reference/en/p5.Filter/gain.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: gain +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Controls the gain attribute of a Biquad Filter. + This is distinctly different from .amp() which is inherited from p5.Effect + .amp() controls the volume via the output gain node + p5.Filter.gain() controls the gain parameter of a Biquad Filter node.

+line: 6838 +params: + - name: gain + description: '' + type: Number +itemtype: method +class: p5.Filter +return: + description: Returns the current or updated gain value + type: Number +chainable: false +--- + + +# gain diff --git a/src/content/reference/en/p5.Filter/process.mdx b/src/content/reference/en/p5.Filter/process.mdx new file mode 100644 index 0000000000..6848aa5507 --- /dev/null +++ b/src/content/reference/en/p5.Filter/process.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Filter an audio signal according to a set + of filter parameters.

+line: 6742 +params: + - name: Signal + description: | +

An object that outputs audio

+ type: Object + - name: freq + description: | +

Frequency in Hz, from 10 to 22050

+ type: Number + optional: true + - name: res + description: | +

Resonance/Width of the filter frequency + from 0.001 to 1000

+ type: Number + optional: true +itemtype: method +class: p5.Filter +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Filter/res.mdx b/src/content/reference/en/p5.Filter/res.mdx new file mode 100644 index 0000000000..9d47be3e53 --- /dev/null +++ b/src/content/reference/en/p5.Filter/res.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: res +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Controls either width of a bandpass frequency, + or the resonance of a low/highpass cutoff frequency.

+line: 6811 +params: + - name: res + description: | +

Resonance/Width of filter freq + from 0.001 to 1000

+ type: Number + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Filter +return: + description: value Returns the current res value + type: Number +chainable: false +--- + + +# res diff --git a/src/content/reference/en/p5.Filter/set.mdx b/src/content/reference/en/p5.Filter/set.mdx new file mode 100644 index 0000000000..1b147451ba --- /dev/null +++ b/src/content/reference/en/p5.Filter/set.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the frequency and the resonance of the filter.

+line: 6760 +params: + - name: freq + description: | +

Frequency in Hz, from 10 to 22050

+ type: Number + optional: true + - name: res + description: | +

Resonance (Q) from 0.001 to 1000

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Filter +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Filter/setType.mdx b/src/content/reference/en/p5.Filter/setType.mdx new file mode 100644 index 0000000000..fbf45f9f29 --- /dev/null +++ b/src/content/reference/en/p5.Filter/setType.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setType +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the type of a p5.Filter. Possible types include: + "lowpass" (default), "highpass", "bandpass", + "lowshelf", "highshelf", "peaking", "notch", + "allpass".

+line: 6884 +params: + - name: t + description: '' + type: String +itemtype: method +class: p5.Filter +chainable: false +--- + + +# setType diff --git a/src/content/reference/en/p5.Filter/toggle.mdx b/src/content/reference/en/p5.Filter/toggle.mdx new file mode 100644 index 0000000000..d6c019415b --- /dev/null +++ b/src/content/reference/en/p5.Filter/toggle.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toggle +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Toggle function. Switches between the specified type and allpass

+line: 6864 +itemtype: method +class: p5.Filter +return: + description: '[Toggle value]' + type: Boolean +chainable: false +--- + + +# toggle diff --git a/src/content/reference/en/p5.Font/font.mdx b/src/content/reference/en/p5.Font/font.mdx new file mode 100644 index 0000000000..076bce240a --- /dev/null +++ b/src/content/reference/en/p5.Font/font.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: font +module: Typography +submodule: Loading & Displaying +file: src/typography/p5.Font.js +description: | +

Underlying + opentype.js + font object.

+line: 45 +itemtype: property +class: p5.Font +chainable: false +--- + + +# font diff --git a/src/content/reference/en/p5.Font/textBounds.mdx b/src/content/reference/en/p5.Font/textBounds.mdx new file mode 100644 index 0000000000..dd409c8f9c --- /dev/null +++ b/src/content/reference/en/p5.Font/textBounds.mdx @@ -0,0 +1,132 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textBounds +module: Typography +submodule: Loading & Displaying +file: src/typography/p5.Font.js +description: > +

Returns the bounding box for a string of text written using this + + p5.Font.

+ +

The first parameter, str, is a string of text. The second and + third + + parameters, x and y, are the text's position. By + default, they set the + + coordinates of the bounding box's bottom-left corner. See + + textAlign() for more ways to align text.

+ +

The fourth parameter, fontSize, is optional. It sets the font + size used to + + determine the bounding box. By default, font.textBounds() will + use the + + current textSize().

+line: 55 +params: + - name: str + description: | +

string of text.

+ type: String + - name: x + description: | +

x-coordinate of the text.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the text.

+ type: Number + - name: fontSize + description: | +

font size. Defaults to the current + textSize().

+ type: Number + optional: true +itemtype: method +class: p5.Font +example: + - |- + +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + + let bbox = font.textBounds('p5*js', 35, 53); + rect(bbox.x, bbox.y, bbox.w, bbox.h); + + textFont(font); + text('p5*js', 35, 53); + + describe('The text "p5*js" written in black inside a white rectangle.'); + } + +
+ +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + + textFont(font); + textSize(15); + textAlign(CENTER, CENTER); + + let bbox = font.textBounds('p5*js', 50, 50); + rect(bbox.x, bbox.y, bbox.w, bbox.h); + + text('p5*js', 50, 50); + + describe('The text "p5*js" written in black inside a white rectangle.'); + } + +
+ +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + + let bbox = font.textBounds('p5*js', 31, 53, 15); + rect(bbox.x, bbox.y, bbox.w, bbox.h); + + textFont(font); + textSize(15); + text('p5*js', 31, 53); + + describe('The text "p5*js" written in black inside a white rectangle.'); + } + +
+return: + description: |- + object describing the bounding box with + properties x, y, w, and h. + type: Object +chainable: false +--- + + +# textBounds diff --git a/src/content/reference/en/p5.Font/textToPoints.mdx b/src/content/reference/en/p5.Font/textToPoints.mdx new file mode 100644 index 0000000000..0849a09e96 --- /dev/null +++ b/src/content/reference/en/p5.Font/textToPoints.mdx @@ -0,0 +1,104 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textToPoints +module: Typography +submodule: Loading & Displaying +file: src/typography/p5.Font.js +description: > +

Returns an array of points outlining a string of text written using this + + p5.Font.

+ +

The first parameter, str, is a string of text. The second and + third + + parameters, x and y, are the text's position. By + default, they set the + + coordinates of the bounding box's bottom-left corner. See + + textAlign() for more ways to align text.

+ +

The fourth parameter, fontSize, is optional. It sets the + text's font + + size. By default, font.textToPoints() will use the current + + textSize().

+ +

The fifth parameter, options, is also optional. + font.textToPoints() + + expects an object with the following properties:

+ +

sampleFactor is the ratio of the text's path length to the + number of + + samples. It defaults to 0.1. Higher values produce more points along the + + path and are more precise.

+ +

simplifyThreshold removes collinear points if it's set to a + number other + + than 0. The value represents the threshold angle to use when determining + + whether two edges are collinear.

+line: 249 +params: + - name: str + description: | +

string of text.

+ type: String + - name: x + description: | +

x-coordinate of the text.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the text.

+ type: Number + - name: fontSize + description: | +

font size. Defaults to the current + textSize().

+ type: Number + optional: true + - name: options + description: | +

object with sampleFactor and simplifyThreshold + properties.

+ type: Object + optional: true +itemtype: method +class: p5.Font +example: + - |- + +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + let points = font.textToPoints('p5*js', 6, 60, 35, { sampleFactor: 0.5 }); + points.forEach(p => { + point(p.x, p.y); + }); + + describe('A set of black dots outlining the text "p5*js" on a gray background.'); + } + +
+return: + description: 'array of point objects, each with x, y, and alpha (path angle) properties.' + type: Array +chainable: false +--- + + +# textToPoints diff --git a/src/content/reference/en/p5.Framebuffer/autoSized.mdx b/src/content/reference/en/p5.Framebuffer/autoSized.mdx new file mode 100644 index 0000000000..1eff54c4c3 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/autoSized.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: autoSized +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Gets or sets whether or not this framebuffer will automatically resize + along with the canvas it's attached to in order to match its size.

+

Call this method with no arguments to see if it is currently auto-sized, + or pass in a boolean to set this property.

+line: 257 +params: + - name: autoSized + description: | +

Whether or not the framebuffer should resize + along with the canvas it's attached to

+ type: Boolean + optional: true +itemtype: method +class: p5.Framebuffer +chainable: false +--- + + +# autoSized diff --git a/src/content/reference/en/p5.Framebuffer/begin.mdx b/src/content/reference/en/p5.Framebuffer/begin.mdx new file mode 100644 index 0000000000..552ac9d1c4 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/begin.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: begin +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Begin drawing to this framebuffer. Subsequent drawing functions to the + canvas the framebuffer is attached to will not be immediately visible, and + will instead be drawn to the framebuffer's texture. Call + end() when finished to make draw + functions go right to the canvas again and to be able to read the + contents of the framebuffer's texture.

+line: 790 +itemtype: method +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + function setup() { + createCanvas(100, 100, WEBGL); + framebuffer = createFramebuffer(); + noStroke(); + } + + function draw() { + // Draw to the framebuffer + framebuffer.begin(); + background(255); + translate(0, 10*sin(frameCount * 0.01), 0); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + fill(255, 0, 0); + box(50); + framebuffer.end(); + + background(100); + // Draw the framebuffer to the main canvas + image(framebuffer, -50, -50, 25, 25); + image(framebuffer, 0, 0, 35, 35); + } + +
+alt: |- + A video of a floating and rotating red cube is pasted twice on the + canvas: once in the top left, and again, larger, in the bottom right. +chainable: false +--- + + +# begin diff --git a/src/content/reference/en/p5.Framebuffer/color.mdx b/src/content/reference/en/p5.Framebuffer/color.mdx new file mode 100644 index 0000000000..08a42f1a9e --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/color.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: color +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

A texture with the color information of the framebuffer. Pass this (or the + framebuffer itself) to texture() to draw it to + the canvas, or pass it to a shader with + setUniform() to read its data.

+

Since Framebuffers are controlled by WebGL, their y coordinates are stored + flipped compared to images and videos. When texturing with a framebuffer + texture, you may want to flip vertically, e.g. with + plane(framebuffer.width, -framebuffer.height).

+line: 1279 +itemtype: property +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + function setup() { + createCanvas(100, 100, WEBGL); + framebuffer = createFramebuffer(); + noStroke(); + } + + function draw() { + // Draw to the framebuffer + framebuffer.begin(); + background(255); + normalMaterial(); + sphere(20); + framebuffer.end(); + + // Draw the framebuffer to the main canvas + image(framebuffer.color, -width/2, -height/2); + } + +
+alt: 'A red, green, and blue sphere in the middle of the canvas' +chainable: false +--- + + +# color diff --git a/src/content/reference/en/p5.Framebuffer/createCamera.mdx b/src/content/reference/en/p5.Framebuffer/createCamera.mdx new file mode 100644 index 0000000000..0913251df7 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/createCamera.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createCamera +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Creates and returns a new + p5.FramebufferCamera to be used + while drawing to this framebuffer. The camera will be set as the + currently active camera.

+line: 698 +itemtype: method +class: p5.Framebuffer +return: + description: A new camera + type: p5.Camera +chainable: false +--- + + +# createCamera diff --git a/src/content/reference/en/p5.Framebuffer/depth.mdx b/src/content/reference/en/p5.Framebuffer/depth.mdx new file mode 100644 index 0000000000..bacc213c0e --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/depth.mdx @@ -0,0 +1,96 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: depth +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: > +

A texture with the depth information of the framebuffer. If the framebuffer + + was created with { depth: false } in its settings, then this + property will + + be undefined. Pass this to texture() to draw it to + + the canvas, or pass it to a shader with + + setUniform() to read its data.

+ +

Since Framebuffers are controlled by WebGL, their y coordinates are stored + + flipped compared to images and videos. When texturing with a framebuffer + + texture, you may want to flip vertically, e.g. with + + plane(framebuffer.width, -framebuffer.height).

+line: 1321 +itemtype: property +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + let depthShader; + + const vert = ` + precision highp float; + attribute vec3 aPosition; + attribute vec2 aTexCoord; + uniform mat4 uModelViewMatrix; + uniform mat4 uProjectionMatrix; + varying vec2 vTexCoord; + void main() { + vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0); + gl_Position = uProjectionMatrix * viewModelPosition; + vTexCoord = aTexCoord; + } + `; + + const frag = ` + precision highp float; + varying vec2 vTexCoord; + uniform sampler2D depth; + void main() { + float depthVal = texture2D(depth, vTexCoord).r; + gl_FragColor = mix( + vec4(1., 1., 0., 1.), // yellow + vec4(0., 0., 1., 1.), // blue + pow(depthVal, 6.) + ); + } + `; + + function setup() { + createCanvas(100, 100, WEBGL); + framebuffer = createFramebuffer(); + depthShader = createShader(vert, frag); + noStroke(); + } + + function draw() { + // Draw to the framebuffer + framebuffer.begin(); + background(255); + rotateX(frameCount * 0.01); + box(20, 20, 100); + framebuffer.end(); + + push(); + shader(depthShader); + depthShader.setUniform('depth', framebuffer.depth); + plane(framebuffer.width, framebuffer.height); + pop(); + } + +
+alt: |- + A video of a rectangular prism rotating, with parts closest to the camera + appearing yellow and colors getting progressively more blue the farther + from the camera they go +chainable: false +--- + + +# depth diff --git a/src/content/reference/en/p5.Framebuffer/draw.mdx b/src/content/reference/en/p5.Framebuffer/draw.mdx new file mode 100644 index 0000000000..8a226d5ec9 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/draw.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: draw +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: > +

Run a function while drawing to the framebuffer rather than to its canvas. + + This is equivalent to calling framebuffer.begin(), running the + function, + + and then calling framebuffer.end(), but ensures that one never + + accidentally forgets begin or end.

+line: 947 +params: + - name: callback + description: | +

A function to run that draws to the canvas. The + function will immediately be run, but it will draw to the framebuffer + instead of the canvas.

+ type: Function +itemtype: method +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + function setup() { + createCanvas(100, 100, WEBGL); + framebuffer = createFramebuffer(); + noStroke(); + } + + function draw() { + // Draw to the framebuffer + framebuffer.draw(function() { + background(255); + translate(0, 10*sin(frameCount * 0.01), 0); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + fill(255, 0, 0); + box(50); + }); + + background(100); + // Draw the framebuffer to the main canvas + image(framebuffer, -50, -50, 25, 25); + image(framebuffer, 0, 0, 35, 35); + } + +
+alt: |- + A video of a floating and rotating red cube is pasted twice on the + canvas: once in the top left, and again, larger, in the bottom right. +chainable: false +--- + + +# draw diff --git a/src/content/reference/en/p5.Framebuffer/end.mdx b/src/content/reference/en/p5.Framebuffer/end.mdx new file mode 100644 index 0000000000..1bd798e871 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/end.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: end +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

After having previously called + begin(), this method stops drawing + functions from going to the framebuffer's texture, allowing them to go + right to the canvas again. After this, one can read from the framebuffer's + texture.

+line: 918 +itemtype: method +class: p5.Framebuffer +chainable: false +--- + + +# end diff --git a/src/content/reference/en/p5.Framebuffer/get.mdx b/src/content/reference/en/p5.Framebuffer/get.mdx new file mode 100644 index 0000000000..8b446f4e0f --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/get.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: > +

Get a region of pixels from the canvas in the form of a + + p5.Image, or a single pixel as an array of + + numbers.

+ +

Returns an array of [R,G,B,A] values for any pixel or grabs a section of + + an image. If the Framebuffer has been set up to not store alpha values, then + + only [R,G,B] will be returned. If no parameters are specified, the entire + + image is returned. + + Use the x and y parameters to get the value of one pixel. Get a section of + + the display window by specifying additional w and h parameters. When + + getting an image, the x and y parameters define the coordinates for the + + upper-left corner of the image, regardless of the current imageMode().

+line: 1026 +itemtype: method +class: p5.Framebuffer +return: + description: the rectangle p5.Image + type: p5.Image +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5.Framebuffer/pixelDensity.mdx b/src/content/reference/en/p5.Framebuffer/pixelDensity.mdx new file mode 100644 index 0000000000..fe091a95b2 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/pixelDensity.mdx @@ -0,0 +1,27 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixelDensity +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Gets or sets the pixel scaling for high pixel density displays. By + default, the density will match that of the canvas the framebuffer was + created on, which will match the display density.

+

Call this method with no arguments to get the current density, or pass + in a number to set the density.

+line: 235 +params: + - name: density + description: | +

A scaling factor for the number of pixels per + side of the framebuffer

+ type: Number + optional: true +itemtype: method +class: p5.Framebuffer +chainable: false +--- + + +# pixelDensity diff --git a/src/content/reference/en/p5.Framebuffer/pixels.mdx b/src/content/reference/en/p5.Framebuffer/pixels.mdx new file mode 100644 index 0000000000..3f54b8bb1c --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/pixels.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixels +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: > +

A Uint8ClampedArray + + containing the values for all the pixels in the Framebuffer.

+ +

Like the main canvas pixels property, call + + loadPixels() before reading + + it, and call updatePixels() + + afterwards to update its data.

+ +

Note that updating pixels via this property will be slower than + + drawing to the framebuffer directly. + + Consider using a shader instead of looping over pixels.

+line: 93 +itemtype: property +class: p5.Framebuffer +chainable: false +--- + + +# pixels diff --git a/src/content/reference/en/p5.Framebuffer/remove.mdx b/src/content/reference/en/p5.Framebuffer/remove.mdx new file mode 100644 index 0000000000..7a8910016e --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/remove.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: remove +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Removes the framebuffer and frees its resources.

+line: 729 +itemtype: method +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + const useFramebuffer = (frameCount % 120) > 60; + if (useFramebuffer && !framebuffer) { + // Create a new framebuffer for us to use + framebuffer = createFramebuffer(); + } else if (!useFramebuffer && framebuffer) { + // Free the old framebuffer's resources + framebuffer.remove(); + framebuffer = undefined; + } + + background(255); + if (useFramebuffer) { + // Draw to the framebuffer + framebuffer.begin(); + background(255); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + fill(255, 0, 0); + box(30); + framebuffer.end(); + + image(framebuffer, -width/2, -height/2); + } + } + +
+alt: A rotating red cube blinks on and off every second. +chainable: false +--- + + +# remove diff --git a/src/content/reference/en/p5.Framebuffer/resize.mdx b/src/content/reference/en/p5.Framebuffer/resize.mdx new file mode 100644 index 0000000000..1a645ce039 --- /dev/null +++ b/src/content/reference/en/p5.Framebuffer/resize.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resize +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

Resizes the framebuffer to the given width and height.

+line: 184 +params: + - name: width + description: '' + type: Number + - name: height + description: '' + type: Number +itemtype: method +class: p5.Framebuffer +example: + - |- + +
+ + let framebuffer; + function setup() { + createCanvas(100, 100, WEBGL); + framebuffer = createFramebuffer(); + noStroke(); + } + + function mouseMoved() { + framebuffer.resize( + max(20, mouseX), + max(20, mouseY) + ); + } + + function draw() { + // Draw to the framebuffer + framebuffer.begin(); + background(255); + normalMaterial(); + sphere(20); + framebuffer.end(); + + background(100); + // Draw the framebuffer to the main canvas + image(framebuffer, -width/2, -height/2); + } + +
+alt: |- + A red, green, and blue sphere is drawn in the middle of a white rectangle + which starts in the top left of the canvas and whose bottom right is at + the user's mouse +chainable: false +--- + + +# resize diff --git a/src/content/reference/en/p5.Gain/amp.mdx b/src/content/reference/en/p5.Gain/amp.mdx new file mode 100644 index 0000000000..56ed94ade9 --- /dev/null +++ b/src/content/reference/en/p5.Gain/amp.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the output level of the gain node.

+line: 11098 +params: + - name: volume + description: | +

amplitude between 0 and 1.0

+ type: Number + - name: rampTime + description: | +

create a fade that lasts rampTime

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Gain +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.Gain/connect.mdx b/src/content/reference/en/p5.Gain/connect.mdx new file mode 100644 index 0000000000..c3e884975f --- /dev/null +++ b/src/content/reference/en/p5.Gain/connect.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Send output to a p5.sound or web audio object

+line: 11070 +params: + - name: unit + description: '' + type: Object +itemtype: method +class: p5.Gain +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.Gain/disconnect.mdx b/src/content/reference/en/p5.Gain/disconnect.mdx new file mode 100644 index 0000000000..4edfefe847 --- /dev/null +++ b/src/content/reference/en/p5.Gain/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all output.

+line: 11084 +itemtype: method +class: p5.Gain +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Gain/setInput.mdx b/src/content/reference/en/p5.Gain/setInput.mdx new file mode 100644 index 0000000000..4f8bbf9d80 --- /dev/null +++ b/src/content/reference/en/p5.Gain/setInput.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setInput +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect a source to the gain node.

+line: 11055 +params: + - name: src + description: | +

p5.sound / Web Audio object with a sound + output.

+ type: Object +itemtype: method +class: p5.Gain +chainable: false +--- + + +# setInput diff --git a/src/content/reference/en/p5.Geometry/averageNormals.mdx b/src/content/reference/en/p5.Geometry/averageNormals.mdx new file mode 100644 index 0000000000..fa7566141c --- /dev/null +++ b/src/content/reference/en/p5.Geometry/averageNormals.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: averageNormals +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

Averages the vertex normals. Used in curved + surfaces

+line: 535 +itemtype: method +class: p5.Geometry +chainable: true +--- + + +# averageNormals diff --git a/src/content/reference/en/p5.Geometry/averagePoleNormals.mdx b/src/content/reference/en/p5.Geometry/averagePoleNormals.mdx new file mode 100644 index 0000000000..44f82c0c71 --- /dev/null +++ b/src/content/reference/en/p5.Geometry/averagePoleNormals.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: averagePoleNormals +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

Averages pole normals. Used in spherical primitives

+line: 556 +itemtype: method +class: p5.Geometry +chainable: true +--- + + +# averagePoleNormals diff --git a/src/content/reference/en/p5.Geometry/clearColors.mdx b/src/content/reference/en/p5.Geometry/clearColors.mdx new file mode 100644 index 0000000000..c361a21d17 --- /dev/null +++ b/src/content/reference/en/p5.Geometry/clearColors.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearColors +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: > +

Removes the internal colors of p5.Geometry. + + Using clearColors(), you can use fill() to supply + new colors before drawing each shape. + + If clearColors() is not used, the shapes will use their internal + colors by ignoring fill().

+line: 123 +itemtype: method +class: p5.Geometry +example: + - |- + +
+ + let shape01; + let shape02; + let points = []; + + function setup() { + createCanvas(100, 100, WEBGL); + points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), + new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0)); + buildShape01(); + buildShape02(); + } + function draw() { + background(0); + fill('pink'); // shape01 retains its internal blue color, so it won't turn pink. + model(shape01); + fill('yellow'); // Now, shape02 is yellow. + model(shape02); + } + + function buildShape01() { + beginGeometry(); + fill('blue'); // shape01's color is blue because its internal colors remain. + beginShape(); + for (let vec of points) vertex(vec.x * 100, vec.y * 100, vec.z * 100); + endShape(CLOSE); + shape01 = endGeometry(); + } + + function buildShape02() { + beginGeometry(); + fill('red'); // shape02.clearColors() removes its internal colors. Now, shape02 is red. + beginShape(); + for (let vec of points) vertex(vec.x * 200, vec.y * 200, vec.z * 200); + endShape(CLOSE); + shape02 = endGeometry(); + shape02.clearColors(); // Resets shape02's colors. + } + +
+chainable: false +--- + + +# clearColors diff --git a/src/content/reference/en/p5.Geometry/computeFaces.mdx b/src/content/reference/en/p5.Geometry/computeFaces.mdx new file mode 100644 index 0000000000..cb8ace6ba0 --- /dev/null +++ b/src/content/reference/en/p5.Geometry/computeFaces.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: computeFaces +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

computes faces for geometry objects based on the vertices.

+line: 321 +itemtype: method +class: p5.Geometry +chainable: true +--- + + +# computeFaces diff --git a/src/content/reference/en/p5.Geometry/computeNormals.mdx b/src/content/reference/en/p5.Geometry/computeNormals.mdx new file mode 100644 index 0000000000..d685302a2d --- /dev/null +++ b/src/content/reference/en/p5.Geometry/computeNormals.mdx @@ -0,0 +1,127 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: computeNormals +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: > +

This function calculates normals for each face, where each vertex's normal + is the average of the normals of all faces it's connected to. + + i.e computes smooth normals per vertex as an average of each face.

+ +

When using FLAT shading, vertices are disconnected/duplicated + i.e each face has its own copy of vertices. + + When using SMOOTH shading, vertices are connected/deduplicated + i.e each face has its vertices shared with other faces.

+ +

Options can include:

+ + +line: 364 +params: + - name: shadingType + description: > +

shading type (FLAT for flat shading or SMOOTH + for smooth shading) for buildGeometry() outputs. Defaults to + FLAT.

+ type: String + optional: true + - name: options + description: | +

An optional object with configuration.

+ type: Object + optional: true +itemtype: method +class: p5.Geometry +example: + - |- + +
+ + let helix; + + function setup() { + createCanvas(100, 100, WEBGL); + + helix = buildGeometry(() => { + beginShape(); + + for (let i = 0; i < TWO_PI * 3; i += 0.6) { + let radius = 20; + let x = cos(i) * radius; + let y = sin(i) * radius; + let z = map(i, 0, TWO_PI * 3, -30, 30); + vertex(x, y, z); + } + endShape(); + }); + helix.computeNormals(); + } + function draw() { + background(255); + stroke(0); + fill(150, 200, 250); + lights(); + rotateX(PI*0.2); + orbitControl(); + model(helix); + } + +
+ - |- + +
+ + let star; + + function setup() { + createCanvas(100, 100, WEBGL); + + star = buildGeometry(() => { + beginShape(); + for (let i = 0; i < TWO_PI; i += PI / 5) { + let outerRadius = 60; + let innerRadius = 30; + let xOuter = cos(i) * outerRadius; + let yOuter = sin(i) * outerRadius; + let zOuter = random(-20, 20); + vertex(xOuter, yOuter, zOuter); + + let nextI = i + PI / 5 / 2; + let xInner = cos(nextI) * innerRadius; + let yInner = sin(nextI) * innerRadius; + let zInner = random(-20, 20); + vertex(xInner, yInner, zInner); + } + endShape(CLOSE); + }); + star.computeNormals(SMOOTH); + } + function draw() { + background(255); + stroke(0); + fill(150, 200, 250); + lights(); + rotateX(PI*0.2); + orbitControl(); + model(star); + } + +
+alt: >- + A star-like geometry, here the computeNormals(SMOOTH) is applied for a smooth + shading effect. + + This helps to avoid the faceted appearance that can occur with flat shading. +chainable: true +--- + + +# computeNormals diff --git a/src/content/reference/en/p5.Geometry/flipU.mdx b/src/content/reference/en/p5.Geometry/flipU.mdx new file mode 100644 index 0000000000..a296706c7d --- /dev/null +++ b/src/content/reference/en/p5.Geometry/flipU.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: flipU +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

Flips the U texture coordinates of the model.

+line: 177 +itemtype: method +class: p5.Geometry +example: + - |- + +
+ + let img; + let model1; + let model2; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(150, 150, WEBGL); + background(200); + + model1 = createShape(50, 50); + model2 = createShape(50, 50); + model2.flipU(); + } + + function draw() { + background(0); + + // original + push(); + translate(-40, 0, 0); + texture(img); + noStroke(); + plane(50); + model(model1); + pop(); + + // flipped + push(); + translate(40, 0, 0); + texture(img); + noStroke(); + plane(50); + model(model2); + pop(); + } + + function createShape(w, h) { + return buildGeometry(() => { + textureMode(NORMAL); + beginShape(); + vertex(-w / 2, -h / 2, 0, 0); + vertex(w / 2, -h / 2, 1, 0); + vertex(w / 2, h / 2, 1, 1); + vertex(-w / 2, h / 2, 0, 1); + endShape(CLOSE); + }); + } + +
+return: + description: '' + type: p5.Geometry +chainable: false +--- + + +# flipU diff --git a/src/content/reference/en/p5.Geometry/flipV.mdx b/src/content/reference/en/p5.Geometry/flipV.mdx new file mode 100644 index 0000000000..e1c6c5aa49 --- /dev/null +++ b/src/content/reference/en/p5.Geometry/flipV.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: flipV +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

Flips the V texture coordinates of the model.

+line: 249 +itemtype: method +class: p5.Geometry +example: + - |- + +
+ + let img; + let model1; + let model2; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(150, 150, WEBGL); + background(200); + + model1 = createShape(50, 50); + model2 = createShape(50, 50); + model2.flipV(); + } + + function draw() { + background(0); + + // original + push(); + translate(-40, 0, 0); + texture(img); + noStroke(); + plane(50); + model(model1); + pop(); + + // flipped + push(); + translate(40, 0, 0); + texture(img); + noStroke(); + plane(50); + model(model2); + pop(); + } + + function createShape(w, h) { + return buildGeometry(() => { + textureMode(NORMAL); + beginShape(); + vertex(-w / 2, -h / 2, 0, 0); + vertex(w / 2, -h / 2, 1, 0); + vertex(w / 2, h / 2, 1, 1); + vertex(-w / 2, h / 2, 0, 1); + endShape(CLOSE); + }); + } + +
+return: + description: '' + type: p5.Geometry +chainable: false +--- + + +# flipV diff --git a/src/content/reference/en/p5.Geometry/normalize.mdx b/src/content/reference/en/p5.Geometry/normalize.mdx new file mode 100644 index 0000000000..b503e87695 --- /dev/null +++ b/src/content/reference/en/p5.Geometry/normalize.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: normalize +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

Modifies all vertices to be centered within the range -100 to 100.

+line: 866 +itemtype: method +class: p5.Geometry +chainable: true +--- + + +# normalize diff --git a/src/content/reference/en/p5.Graphics/createFramebuffer.mdx b/src/content/reference/en/p5.Graphics/createFramebuffer.mdx new file mode 100644 index 0000000000..9d058b6701 --- /dev/null +++ b/src/content/reference/en/p5.Graphics/createFramebuffer.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createFramebuffer +module: Rendering +submodule: Rendering +file: src/core/p5.Graphics.js +description: > +

Creates and returns a new p5.Framebuffer + + inside a p5.Graphics WebGL context.

+ +

This takes the same parameters as the global + + createFramebuffer function.

+line: 199 +itemtype: method +class: p5.Graphics +return: + description: '' + type: p5.Framebuffer +chainable: false +--- + + +# createFramebuffer diff --git a/src/content/reference/en/p5.Graphics/remove.mdx b/src/content/reference/en/p5.Graphics/remove.mdx new file mode 100644 index 0000000000..860a6a784a --- /dev/null +++ b/src/content/reference/en/p5.Graphics/remove.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: remove +module: Rendering +submodule: Rendering +file: src/core/p5.Graphics.js +description: | +

Removes a Graphics object from the page and frees any resources + associated with it.

+line: 131 +itemtype: method +class: p5.Graphics +example: + - |- + +
+ let bg; + function setup() { + bg = createCanvas(100, 100); + bg.background(0); + image(bg, 0, 0); + bg.remove(); + } +
+ +
+ let bg; + function setup() { + pixelDensity(1); + createCanvas(100, 100); + stroke(255); + fill(0); + + // create and draw the background image + bg = createGraphics(100, 100); + bg.background(200); + bg.ellipse(50, 50, 80, 80); + } + function draw() { + let t = millis() / 1000; + // draw the background + if (bg) { + image(bg, frameCount % 100, 0); + image(bg, frameCount % 100 - 100, 0); + } + // draw the foreground + let p = p5.Vector.fromAngle(t, 35).add(50, 50); + ellipse(p.x, p.y, 30); + } + function mouseClicked() { + // remove the background + if (bg) { + bg.remove(); + bg = null; + } + } +
+alt: |- + no image + a multi-colored circle moving back and forth over a scrolling background. +chainable: false +--- + + +# remove diff --git a/src/content/reference/en/p5.Graphics/reset.mdx b/src/content/reference/en/p5.Graphics/reset.mdx new file mode 100644 index 0000000000..90f5311068 --- /dev/null +++ b/src/content/reference/en/p5.Graphics/reset.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reset +module: Rendering +submodule: Rendering +file: src/core/p5.Graphics.js +description: > +

Resets certain values such as those modified by functions in the Transform + category + + and in the Lights category that are not automatically reset + + with graphics buffer objects. Calling this in draw() + will copy the behavior + + of the standard canvas.

+line: 79 +itemtype: method +class: p5.Graphics +example: + - |- + + +
+ let pg; + function setup() { + createCanvas(100, 100); + background(0); + pg = createGraphics(50, 100); + pg.fill(0); + frameRate(5); + } + + function draw() { + image(pg, width / 2, 0); + pg.background(255); + // p5.Graphics object behave a bit differently in some cases + // The normal canvas on the left resets the translate + // with every loop through draw() + // the graphics object on the right doesn't automatically reset + // so translate() is additive and it moves down the screen + rect(0, 0, width / 2, 5); + pg.rect(0, 0, width / 2, 5); + translate(0, 5, 0); + pg.translate(0, 5, 0); + } + function mouseClicked() { + // if you click you will see that + // reset() resets the translate back to the initial state + // of the Graphics object + pg.reset(); + } +
+alt: >- + A white line on a black background stays still on the top-left half. + + A black line animates from top to bottom on a white background on the right + half. + + When clicked, the black line starts back over at the top. +chainable: false +--- + + +# reset diff --git a/src/content/reference/en/p5.Image/blend.mdx b/src/content/reference/en/p5.Image/blend.mdx new file mode 100644 index 0000000000..aeeec7c0a2 --- /dev/null +++ b/src/content/reference/en/p5.Image/blend.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: blend +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Copies a region of pixels from another + + p5.Image object into this one. The + blendMode + + parameter blends the images' colors to create different effects.

+line: 1107 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let mountains; + let bricks; + + function preload() { + mountains = loadImage('assets/rockies.jpg'); + bricks = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD); + image(mountains, 0, 0); + image(bricks, 0, 0); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.'); + } + +
+ +
+ + let mountains; + let bricks; + + function preload() { + mountains = loadImage('assets/rockies.jpg'); + bricks = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); + image(mountains, 0, 0); + image(bricks, 0, 0); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.'); + } + +
+ +
+ + let mountains; + let bricks; + + function preload() { + mountains = loadImage('assets/rockies.jpg'); + bricks = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); + image(mountains, 0, 0); + image(bricks, 0, 0); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.'); + } + +
+chainable: false +--- + + +# blend diff --git a/src/content/reference/en/p5.Image/copy.mdx b/src/content/reference/en/p5.Image/copy.mdx new file mode 100644 index 0000000000..f0bc8f5a33 --- /dev/null +++ b/src/content/reference/en/p5.Image/copy.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: copy +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Copies pixels from a source p5.Image + to this one. Calling img.copy() will scale pixels from the source + region if it isn't the same size as the destination region.

+line: 770 +itemtype: method +class: p5.Image +example: + - |2- + +
+ + let img; + function preload() { + img = loadImage('assets/rockies.jpg'); + } + function setup() { + img.copy(7, 22, 10, 10, 35, 25, 50, 50); + image(img, 0, 0); + // Outline copied region. + stroke(255); + noFill(); + square(7, 22, 10); + describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.'); + } + +
+
+ + let mountains; + let bricks; + function preload() { + mountains = loadImage('assets/rockies.jpg'); + bricks = loadImage('assets/bricks.jpg'); + } + function setup() { + let x = bricks.width / 2; + let y = bricks.height / 2; + mountains.copy(bricks, 0, 0, x, y, 0, 0, x, y); + image(mountains, 0, 0); + describe('An image of a brick wall drawn at the top-left of an image of a mountain landscape.'); + } + +
+chainable: false +--- + + +# copy diff --git a/src/content/reference/en/p5.Image/delay.mdx b/src/content/reference/en/p5.Image/delay.mdx new file mode 100644 index 0000000000..561f4050f4 --- /dev/null +++ b/src/content/reference/en/p5.Image/delay.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: delay +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Changes the delay between frames in an animated GIF.

+ +

The second parameter, index, is optional. If provided, only + the frame + + at index will have its delay modified. All other frames will keep + + their default delay.

+line: 1521 +params: + - name: d + description: | +

delay in milliseconds between switching frames.

+ type: Number + - name: index + description: | +

index of the frame that will have its delay modified.

+ type: Number + optional: true +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gifFast; + let gifSlow; + + function preload() { + gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + } + + function setup() { + gifFast.resize(50, 50); + gifSlow.resize(50, 50); + gifFast.delay(10); + gifSlow.delay(100); + } + + function draw() { + image(gifFast, 0, 0); + image(gifSlow, 50, 0); + + describe('Two animated eyes looking around. The eye on the left moves faster than the eye on the right.'); + } + +
+ +
+ + let gif; + + function preload() { + gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + } + + function setup() { + gif.delay(3000, 67); + } + + function draw() { + image(gif, 0, 0); + + describe('An animated eye looking around. It pauses for three seconds while it looks down.'); + } + +
+chainable: false +--- + + +# delay diff --git a/src/content/reference/en/p5.Image/filter.mdx b/src/content/reference/en/p5.Image/filter.mdx new file mode 100644 index 0000000000..9f012a28cf --- /dev/null +++ b/src/content/reference/en/p5.Image/filter.mdx @@ -0,0 +1,189 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: filter +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Applies an image filter to the p5.Image object. + The preset options are:

+

INVERT + Inverts the colors in the image. No parameter is used.

+

GRAY + Converts the image to grayscale. No parameter is used.

+

THRESHOLD + Converts the image to black and white. Pixels with a grayscale value + above a given threshold are converted to white. The rest are converted to + black. The threshold must be between 0.0 (black) and 1.0 (white). If no + value is specified, 0.5 is used.

+

OPAQUE + Sets the alpha channel to be entirely opaque. No parameter is used.

+

POSTERIZE + Limits the number of colors in the image. Each color channel is limited to + the number of colors specified. Values between 2 and 255 are valid, but + results are most noticeable with lower values. The default value is 4.

+

BLUR + Blurs the image. The level of blurring is specified by a blur radius. Larger + values increase the blur. The default value is 4. A gaussian blur is used + in P2D mode. A box blur is used in WEBGL mode.

+

ERODE + Reduces the light areas. No parameter is used.

+

DILATE + Increases the light areas. No parameter is used.

+line: 926 +params: + - name: filterType + description: | +

either THRESHOLD, GRAY, OPAQUE, INVERT, + POSTERIZE, ERODE, DILATE or BLUR.

+ type: Constant + - name: filterParam + description: | +

parameter unique to each filter.

+ type: Number + optional: true +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(INVERT); + image(img, 0, 0); + + describe('A blue brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(GRAY); + image(img, 0, 0); + + describe('A brick wall drawn in grayscale.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(THRESHOLD); + image(img, 0, 0); + + describe('A brick wall drawn in black and white.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(OPAQUE); + image(img, 0, 0); + + describe('A red brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(POSTERIZE, 3); + image(img, 0, 0); + + describe('An image of a red brick wall drawn with a limited color palette.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(BLUR, 3); + image(img, 0, 0); + + describe('A blurry image of a red brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(DILATE); + image(img, 0, 0); + + describe('A red brick wall with bright lines between each brick.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + img.filter(ERODE); + image(img, 0, 0); + + describe('A red brick wall with faint lines between each brick.'); + } + +
+chainable: false +--- + + +# filter diff --git a/src/content/reference/en/p5.Image/get.mdx b/src/content/reference/en/p5.Image/get.mdx new file mode 100644 index 0000000000..ce38f67301 --- /dev/null +++ b/src/content/reference/en/p5.Image/get.mdx @@ -0,0 +1,111 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Gets a pixel or a region of pixels from a + + p5.Image object.

+ +

img.get() is easy to use but it's not as fast as + + img.pixels. Use + + img.pixels to read many pixel values.

+ +

The version of img.get() with no parameters returns the entire + image.

+ +

The version of img.get() with two parameters interprets them + as + + coordinates. It returns an array with the [R, G, B, A] values of + the + + pixel at the given point.

+ +

The version of img.get() with four parameters interprets them + as + + coordinates and dimensions. It returns a subsection of the canvas as a + + p5.Image object. The first two parameters are + + the coordinates for the upper-left corner of the subsection. The last two + + parameters are the width and height of the subsection.

+ +

Use img.get() to work directly with + + p5.Image objects.

+line: 430 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let img2 = get(); + image(img2, width / 2, 0); + + describe('Two identical mountain landscapes shown side-by-side.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let c = img.get(50, 90); + fill(c); + noStroke(); + square(25, 25, 50); + + describe('A mountain landscape with an olive green square in its center.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let img2 = img.get(0, 0, img.width / 2, img.height / 2); + image(img2, width / 2, height / 2); + + describe('A mountain landscape drawn on top of another mountain landscape.'); + } + +
+return: + description: subsection as a p5.Image object. + type: p5.Image +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5.Image/getCurrentFrame.mdx b/src/content/reference/en/p5.Image/getCurrentFrame.mdx new file mode 100644 index 0000000000..4523bf2f98 --- /dev/null +++ b/src/content/reference/en/p5.Image/getCurrentFrame.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getCurrentFrame +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Gets the index of the current frame in an animated GIF.

+line: 1334 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + + function preload() { + gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + } + + function draw() { + let index = gif.getCurrentFrame(); + image(gif, 0, 0); + text(index, 10, 90); + + describe('A cartoon eye repeatedly looks around, then outwards. A number displayed in the bottom-left corner increases from 0 to 124, then repeats.'); + } + +
+return: + description: index of the GIF's current frame. + type: Number +chainable: false +--- + + +# getCurrentFrame diff --git a/src/content/reference/en/p5.Image/height.mdx b/src/content/reference/en/p5.Image/height.mdx new file mode 100644 index 0000000000..efd313b939 --- /dev/null +++ b/src/content/reference/en/p5.Image/height.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: height +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Image height.

+line: 117 +itemtype: property +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let x = img.width / 2; + let y = img.height / 2; + let d = 20; + circle(x, y, d); + + describe('An image of a mountain landscape with a white circle drawn in the middle.'); + } + +
+chainable: false +--- + + +# height diff --git a/src/content/reference/en/p5.Image/loadPixels.mdx b/src/content/reference/en/p5.Image/loadPixels.mdx new file mode 100644 index 0000000000..0e0f5591ac --- /dev/null +++ b/src/content/reference/en/p5.Image/loadPixels.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadPixels +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Loads the current value of each pixel in the + + p5.Image object into the img.pixels + array. + + This method must be called before reading or modifying pixel values.

+line: 308 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img = createImage(66, 66); + img.loadPixels(); + for (let x = 0; x < img.width; x += 1) { + for (let y = 0; y < img.height; y += 1) { + img.set(x, y, 0); + } + } + img.updatePixels(); + image(img, 17, 17); + + describe('A black square drawn in the middle of a gray square.'); + +
+ +
+ + let img = createImage(66, 66); + img.loadPixels(); + let numPixels = 4 * img.width * img.height; + for (let i = 0; i < numPixels; i += 4) { + // Red. + img.pixels[i] = 0; + // Green. + img.pixels[i + 1] = 0; + // Blue. + img.pixels[i + 2] = 0; + // Alpha. + img.pixels[i + 3] = 255; + } + img.updatePixels(); + image(img, 17, 17); + + describe('A black square drawn in the middle of a gray square.'); + +
+chainable: false +--- + + +# loadPixels diff --git a/src/content/reference/en/p5.Image/mask.mdx b/src/content/reference/en/p5.Image/mask.mdx new file mode 100644 index 0000000000..ed62bfa554 --- /dev/null +++ b/src/content/reference/en/p5.Image/mask.mdx @@ -0,0 +1,45 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mask +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Masks part of an image from displaying by loading another + image and using its alpha channel as an alpha channel for + this image. Masks are cumulative, once applied to an image + object, they cannot be removed.

+line: 845 +params: + - name: srcImage + description: | +

source image.

+ type: p5.Image +itemtype: method +class: p5.Image +example: + - |- + +
+ + let photo; + let maskImage; + + function preload() { + photo = loadImage('assets/rockies.jpg'); + maskImage = loadImage('assets/mask2.png'); + } + + function setup() { + photo.mask(maskImage); + image(photo, 0, 0); + + describe('An image of a mountain landscape. The right side of the image has a faded patch of white.'); + } + +
+chainable: false +--- + + +# mask diff --git a/src/content/reference/en/p5.Image/numFrames.mdx b/src/content/reference/en/p5.Image/numFrames.mdx new file mode 100644 index 0000000000..1d123b5106 --- /dev/null +++ b/src/content/reference/en/p5.Image/numFrames.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: numFrames +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Returns the number of frames in an animated GIF.

+line: 1413 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + + function preload() { + gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + } + + function draw() { + image(gif, 0, 0); + let total = gif.numFrames(); + let index = gif.getCurrentFrame(); + text(`${index} / ${total}`, 30, 90); + + describe('A cartoon eye looks around. The text "n / 125" is shown at the bottom of the canvas.'); + } + +
+return: + description: number of frames in the GIF. + type: Number +chainable: false +--- + + +# numFrames diff --git a/src/content/reference/en/p5.Image/pause.mdx b/src/content/reference/en/p5.Image/pause.mdx new file mode 100644 index 0000000000..760e832e28 --- /dev/null +++ b/src/content/reference/en/p5.Image/pause.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Pauses an animated GIF. The GIF can be resumed by calling + img.play().

+line: 1483 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + + function preload() { + gif = loadImage('assets/nancy-liang-wind-loop-forever.gif'); + } + + function draw() { + background(255); + image(gif, 0, 0); + + describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.'); + } + + function mousePressed() { + gif.pause(); + } + + function mouseReleased() { + gif.play(); + } + +
+chainable: false +--- + + +# pause diff --git a/src/content/reference/en/p5.Image/pixelDensity.mdx b/src/content/reference/en/p5.Image/pixelDensity.mdx new file mode 100644 index 0000000000..5decc3c4fe --- /dev/null +++ b/src/content/reference/en/p5.Image/pixelDensity.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixelDensity +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Gets or sets the pixel density for high pixel density displays. By default, + the density will be set to 1.

+

Call this method with no arguments to get the default density, or pass + in a number to set the density. If a non-positive number is provided, + it defaults to 1.

+line: 227 +params: + - name: density + description: | +

A scaling factor for the number of pixels per + side

+ type: Number + optional: true +itemtype: method +class: p5.Image +return: + description: >- + The current density if called without arguments, or the instance for + chaining if setting density. + type: Number +chainable: false +--- + + +# pixelDensity diff --git a/src/content/reference/en/p5.Image/pixels.mdx b/src/content/reference/en/p5.Image/pixels.mdx new file mode 100644 index 0000000000..3e9d630651 --- /dev/null +++ b/src/content/reference/en/p5.Image/pixels.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixels +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

An array containing the color of each pixel in the + + p5.Image object. Colors are stored as numbers + + representing red, green, blue, and alpha (RGBA) values. + img.pixels is a + + one-dimensional array for performance reasons.

+ +

Each pixel occupies four elements in the pixels array, one for each + + RGBA value. For example, the pixel at coordinates (0, 0) stores its + + RGBA values at img.pixels[0], img.pixels[1], + img.pixels[2], + + and img.pixels[3], respectively. The next pixel at coordinates + (1, 0) + + stores its RGBA values at img.pixels[4], + img.pixels[5], + + img.pixels[6], and img.pixels[7]. And so on. The + img.pixels array + + for a 100×100 p5.Image object has + + 100 × 100 × 4 = 40,000 elements.

+ +

Accessing the RGBA values for a pixel in the + + p5.Image object requires a little math as + + shown below. The img.loadPixels() + + method must be called before accessing the img.pixels array. The + + img.updatePixels() method must be + + called after any changes are made.

+line: 155 +itemtype: property +class: p5.Image +example: + - |- + +
+ + let img = createImage(66, 66); + img.loadPixels(); + let numPixels = 4 * img.width * img.height; + for (let i = 0; i < numPixels; i += 4) { + // Red. + img.pixels[i] = 0; + // Green. + img.pixels[i + 1] = 0; + // Blue. + img.pixels[i + 2] = 0; + // Alpha. + img.pixels[i + 3] = 255; + } + img.updatePixels(); + image(img, 17, 17); + + describe('A black square drawn in the middle of a gray square.'); + +
+ +
+ + let img = createImage(66, 66); + img.loadPixels(); + let numPixels = 4 * img.width * img.height; + for (let i = 0; i < numPixels; i += 4) { + // Red. + img.pixels[i] = 255; + // Green. + img.pixels[i + 1] = 0; + // Blue. + img.pixels[i + 2] = 0; + // Alpha. + img.pixels[i + 3] = 255; + } + img.updatePixels(); + image(img, 17, 17); + + describe('A red square drawn in the middle of a gray square.'); + +
+chainable: false +--- + + +# pixels diff --git a/src/content/reference/en/p5.Image/play.mdx b/src/content/reference/en/p5.Image/play.mdx new file mode 100644 index 0000000000..ce4f11ba4d --- /dev/null +++ b/src/content/reference/en/p5.Image/play.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Plays an animated GIF that was paused with + img.pause().

+line: 1445 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + + function preload() { + gif = loadImage('assets/nancy-liang-wind-loop-forever.gif'); + } + + function draw() { + background(255); + image(gif, 0, 0); + + describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.'); + } + + function mousePressed() { + gif.pause(); + } + + function mouseReleased() { + gif.play(); + } + +
+chainable: false +--- + + +# play diff --git a/src/content/reference/en/p5.Image/reset.mdx b/src/content/reference/en/p5.Image/reset.mdx new file mode 100644 index 0000000000..07aacfebc9 --- /dev/null +++ b/src/content/reference/en/p5.Image/reset.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reset +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Restarts an animated GIF at its first frame.

+line: 1295 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + + function preload() { + gif = loadImage('assets/arnott-wallace-wink-loop-once.gif'); + } + + function draw() { + background(255); + image(gif, 0, 0); + + describe('A cartoon face winks once and then freezes. Clicking resets the face and makes it wink again.'); + } + + function mousePressed() { + gif.reset(); + } + +
+chainable: false +--- + + +# reset diff --git a/src/content/reference/en/p5.Image/resize.mdx b/src/content/reference/en/p5.Image/resize.mdx new file mode 100644 index 0000000000..9ebababfc2 --- /dev/null +++ b/src/content/reference/en/p5.Image/resize.mdx @@ -0,0 +1,92 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resize +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Resizes the p5.Image object to a given + width + + and height. The image's original aspect ratio can be kept by + passing 0 + + for either width or height. For example, calling + img.resize(50, 0) + + on an image that was 500 × 300 pixels will resize it to + + 50 × 30 pixels.

+line: 626 +params: + - name: width + description: | +

resized image width.

+ type: Number + - name: height + description: | +

resized image height.

+ type: Number +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + img.resize(50, 100); + image(img, 0, 0); + + describe('Two images of a mountain landscape. One copy of the image is squeezed horizontally.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + img.resize(0, 30); + image(img, 0, 0); + + describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + img.resize(60, 0); + image(img, 0, 0); + + describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.'); + } + +
+chainable: false +--- + + +# resize diff --git a/src/content/reference/en/p5.Image/save.mdx b/src/content/reference/en/p5.Image/save.mdx new file mode 100644 index 0000000000..b1e2d54173 --- /dev/null +++ b/src/content/reference/en/p5.Image/save.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: save +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Saves the p5.Image object to a file. + + The browser will either save the file immediately or prompt the user + + with a dialogue window.

+ +

By default, calling img.save() will save the image as + untitled.png.

+ +

Calling img.save() with one argument, as in + img.save('photo.png'), + + will set the image's filename and type together.

+ +

Calling img.save() with two arguments, as in + + image.save('photo', 'png'), will set the image's filename and + type + + separately.

+ +

The image will only be downloaded as an animated GIF if the + + p5.Image object was loaded from a GIF file. + + See saveGif() to create new GIFs.

+line: 1238 +params: + - name: filename + description: | +

filename. Defaults to 'untitled'.

+ type: String + - name: extension + description: | +

file extension, either 'png' or 'jpg'. + Defaults to 'png'.

+ type: String + optional: true +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function draw() { + image(img, 0, 0); + + describe('An image of a mountain landscape.'); + } + + function keyPressed() { + if (key === 's') { + img.save(); + } else if (key === 'j') { + img.save('rockies.jpg'); + } else if (key === 'p') { + img.save('rockies', 'png'); + } + } + +
+chainable: false +--- + + +# save diff --git a/src/content/reference/en/p5.Image/set.mdx b/src/content/reference/en/p5.Image/set.mdx new file mode 100644 index 0000000000..9c2dc4842e --- /dev/null +++ b/src/content/reference/en/p5.Image/set.mdx @@ -0,0 +1,161 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Sets the color of one or more pixels within a + + p5.Image object.

+ +

img.set() is easy to use but it's not as fast as + + img.pixels. Use + + img.pixels to set many pixel values.

+ +

img.set() interprets the first two parameters as x- and + y-coordinates. It + + interprets the last parameter as a grayscale value, a [R, G, B, + A] pixel + + array, a p5.Color object, or another + + p5.Image object.

+ +

img.updatePixels() must be called + + after using img.set() for changes to appear.

+line: 535 +params: + - name: x + description: | +

x-coordinate of the pixel.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the pixel.

+ type: Number + - name: a + description: | +

grayscale value | pixel array | + p5.Color object | + p5.Image to copy.

+ type: 'Number|Number[]|Object' +itemtype: method +class: p5.Image +example: + - >- + +
+ + + + let img = createImage(100, 100); + + img.set(30, 20, 0); + + img.set(85, 20, 0); + + img.set(85, 75, 0); + + img.set(30, 75, 0); + + img.updatePixels(); + + image(img, 0, 0); + + + describe('Four black dots arranged in a square drawn on a gray + background.'); + + + +
+ + +
+ + + + let img = createImage(100, 100); + + let black = color(0); + + img.set(30, 20, black); + + img.set(85, 20, black); + + img.set(85, 75, black); + + img.set(30, 75, black); + + img.updatePixels(); + + image(img, 0, 0); + + + describe('Four black dots arranged in a square drawn on a gray + background.'); + + + +
+ + +
+ + + + let img = createImage(66, 66); + + for (let x = 0; x < img.width; x += 1) { + for (let y = 0; y < img.height; y += 1) { + let c = map(x, 0, img.width, 0, 255); + img.set(x, y, c); + } + } + + img.updatePixels(); + + image(img, 17, 17); + + + describe('A square with a horiztonal color gradient from black to white + drawn on a gray background.'); + + + +
+ + +
+ + + + let img; + + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + + function setup() { + let img2 = createImage(100, 100); + img2.set(0, 0, img); + image(img2, 0, 0); + + describe('An image of a mountain landscape.'); + } + + + +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Image/setFrame.mdx b/src/content/reference/en/p5.Image/setFrame.mdx new file mode 100644 index 0000000000..b4e10951a3 --- /dev/null +++ b/src/content/reference/en/p5.Image/setFrame.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setFrame +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Sets the current frame in an animated GIF.

+line: 1365 +params: + - name: index + description: | +

index of the frame to display.

+ type: Number +itemtype: method +class: p5.Image +example: + - |- + +
+ + let gif; + let frameSlider; + + function preload() { + gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif'); + } + + function setup() { + let maxFrame = gif.numFrames() - 1; + frameSlider = createSlider(0, maxFrame); + frameSlider.position(10, 80); + frameSlider.size(80); + } + + function draw() { + let index = frameSlider.value(); + gif.setFrame(index); + image(gif, 0, 0); + + describe('A cartoon eye looks around when a slider is moved.'); + } + +
+chainable: false +--- + + +# setFrame diff --git a/src/content/reference/en/p5.Image/updatePixels.mdx b/src/content/reference/en/p5.Image/updatePixels.mdx new file mode 100644 index 0000000000..57f41c4628 --- /dev/null +++ b/src/content/reference/en/p5.Image/updatePixels.mdx @@ -0,0 +1,82 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: updatePixels +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

Updates the canvas with the RGBA values in the + + img.pixels array.

+ +

img.updatePixels() only needs to be called after changing + values in + + the img.pixels array. Such changes can be + + made directly after calling + + img.loadPixels() or by calling + + img.set().

+ +

The optional parameters x, y, width, + and height define a + + subsection of the p5.Image object to update. + + Doing so can improve performance in some cases.

+ +

If the p5.Image object was loaded from a GIF, + + then calling img.updatePixels() will update the pixels in current + + frame.

+line: 358 +itemtype: method +class: p5.Image +example: + - |- + +
+ + let img = createImage(66, 66); + img.loadPixels(); + for (let x = 0; x < img.width; x += 1) { + for (let y = 0; y < img.height; y += 1) { + img.set(x, y, 0); + } + } + img.updatePixels(); + image(img, 17, 17); + + describe('A black square drawn in the middle of a gray square.'); + +
+ +
+ + let img = createImage(66, 66); + img.loadPixels(); + let numPixels = 4 * img.width * img.height; + for (let i = 0; i < numPixels; i += 4) { + // Red. + img.pixels[i] = 0; + // Green. + img.pixels[i + 1] = 0; + // Blue. + img.pixels[i + 2] = 0; + // Alpha. + img.pixels[i + 3] = 255; + } + img.updatePixels(); + image(img, 17, 17); + + describe('A black square drawn in the middle of a gray square.'); + +
+chainable: false +--- + + +# updatePixels diff --git a/src/content/reference/en/p5.Image/width.mdx b/src/content/reference/en/p5.Image/width.mdx new file mode 100644 index 0000000000..12dd7ffe5e --- /dev/null +++ b/src/content/reference/en/p5.Image/width.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: width +module: Image +submodule: Image +file: src/image/p5.Image.js +description: | +

Image width.

+line: 89 +itemtype: property +class: p5.Image +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let x = img.width / 2; + let y = img.height / 2; + let d = 20; + circle(x, y, d); + + describe('An image of a mountain landscape with a white circle drawn in the middle.'); + } + +
+chainable: false +--- + + +# width diff --git a/src/content/reference/en/p5.MediaElement/addCue.mdx b/src/content/reference/en/p5.MediaElement/addCue.mdx new file mode 100644 index 0000000000..574572e28a --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/addCue.mdx @@ -0,0 +1,84 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addCue +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Schedules a function to call when the audio/video reaches a specific time + + during its playback.

+ +

The first parameter, time, is the time, in seconds, when the + function + + should run. This value is passed to callback as its first + argument.

+ +

The second parameter, callback, is the function to call at the + specified + + cue time.

+ +

The third parameter, value, is optional and can be any type of + value. + + value is passed to callback.

+ +

Calling media.addCue() returns an ID as a string. This is + useful for + + removing the cue later.

+line: 4696 +params: + - name: time + description: | +

cue time to run the callback function.

+ type: Number + - name: callback + description: | +

function to call at the cue time.

+ type: Function + - name: value + description: | +

object to pass as the argument to + callback.

+ type: Object + optional: true +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + function setup() { + // Create a p5.MediaElement using createAudio(). + let beat = createAudio('assets/beat.mp3'); + // Play the beat in a loop. + beat.loop(); + + // Schedule a few events. + beat.addCue(0, changeBackground, 'red'); + beat.addCue(2, changeBackground, 'deeppink'); + beat.addCue(4, changeBackground, 'orchid'); + beat.addCue(6, changeBackground, 'lavender'); + + describe('A red square with a beat playing in the background. Its color changes every 2 seconds while the audio plays.'); + } + + function changeBackground(c) { + background(c); + } + +
+return: + description: |- + id ID of this cue, + useful for `media.removeCue(id)`. + type: Number +chainable: false +--- + + +# addCue diff --git a/src/content/reference/en/p5.MediaElement/autoplay.mdx b/src/content/reference/en/p5.MediaElement/autoplay.mdx new file mode 100644 index 0000000000..6025923003 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/autoplay.mdx @@ -0,0 +1,72 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: autoplay +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Sets the audio/video to play once it's loaded.

+ +

The parameter, shouldAutoplay, is optional. Calling + + media.autoplay() without an argument causes the media to play + + automatically. If true is passed, as in + media.autoplay(true), the + + media will automatically play. If false is passed, as in + + media.autoPlay(false), it won't play automatically.

+line: 4055 +params: + - name: shouldAutoplay + description: | +

whether the element should autoplay.

+ type: Boolean + optional: true +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + function setup() { + noCanvas(); + + // Load a video and play it automatically. + let video = createVideo('assets/fingers.mov', () => { + video.autoplay(); + video.size(100, 100); + }); + + describe('A video of fingers walking on a treadmill.'); + } + +
+ +
+ + function setup() { + noCanvas(); + + // Load a video, but don't play it automatically. + let video = createVideo('assets/fingers.mov', () => { + video.autoplay(false); + video.size(100, 100); + }); + + // Play the video when the user clicks on it. + video.mousePressed(() => { + video.play(); + }); + + describe('An image of fingers on a treadmill. They start walking when the user double-clicks on them.'); + } + +
+chainable: true +--- + + +# autoplay diff --git a/src/content/reference/en/p5.MediaElement/clearCues.mdx b/src/content/reference/en/p5.MediaElement/clearCues.mdx new file mode 100644 index 0000000000..4c30f026b5 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/clearCues.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearCues +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Removes all functions scheduled with media.addCue().

+line: 4820 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let isChanging = true; + + function setup() { + background(200); + + // Create a p5.MediaElement using createAudio(). + let beat = createAudio('assets/beat.mp3'); + // Play the beat in a loop. + beat.loop(); + + // Schedule a few events. + beat.addCue(0, changeBackground, 'red'); + beat.addCue(2, changeBackground, 'deeppink'); + beat.addCue(4, changeBackground, 'orchid'); + beat.addCue(6, changeBackground, 'lavender'); + + describe('The text "Double-click to stop changing." written on a square. The color changes every 2 seconds while the audio plays. The color stops changing when the user double-clicks the square.'); + } + + function draw() { + if (isChanging === true) { + text('Double-click to stop changing.', 10, 10, 80, 80); + } else { + text('No more changes.', 10, 10, 80, 80); + } + } + + function changeBackground(c) { + background(c); + } + + // Remove cued functions and stop + // changing colors when the user + // double-clicks. + function doubleClicked() { + if (isChanging === true) { + beat.clearCues(); + isChanging = false; + } + } + +
+chainable: false +--- + + +# clearCues diff --git a/src/content/reference/en/p5.MediaElement/connect.mdx b/src/content/reference/en/p5.MediaElement/connect.mdx new file mode 100644 index 0000000000..225e798455 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/connect.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Send the audio output of this element to a specified audioNode or + p5.sound object. If no element is provided, connects to p5's main + output. That connection is established when this method is first called. + All connections are removed by the .disconnect() method.

+

This method is meant to be used with the p5.sound.js addon library.

+line: 4547 +params: + - name: audioNode + description: | +

AudioNode from the Web Audio API, + or an object from the p5.sound library

+ type: AudioNode|Object +itemtype: method +class: p5.MediaElement +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.MediaElement/disconnect.mdx b/src/content/reference/en/p5.MediaElement/disconnect.mdx new file mode 100644 index 0000000000..a8ff8fa476 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/disconnect.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Disconnect all Web Audio routing, including to main output. + This is useful if you want to re-route the output through + audio effects, for example.

+line: 4596 +itemtype: method +class: p5.MediaElement +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.MediaElement/duration.mdx b/src/content/reference/en/p5.MediaElement/duration.mdx new file mode 100644 index 0000000000..36971fb1ca --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/duration.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: duration +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Returns the audio/video's duration in seconds.

+line: 4339 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let dragon; + + function setup() { + background(200); + + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + // Show the default media controls. + dragon.showControls(); + + describe('The text "S seconds left" on a gray square with media controls beneath it. The number "S" decreases as the song plays.'); + } + + function draw() { + background(200); + + // Calculate the time remaining. + let s = dragon.duration() - dragon.time(); + // Round s to 1 decimal place + // for display. + s = round(s, 1); + + // Display the time remaining. + textAlign(CENTER); + text(`${s} seconds left`, 50, 50); + } + +
+return: + description: duration (in seconds). + type: Number +chainable: false +--- + + +# duration diff --git a/src/content/reference/en/p5.MediaElement/hideControls.mdx b/src/content/reference/en/p5.MediaElement/hideControls.mdx new file mode 100644 index 0000000000..04e53e4690 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/hideControls.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hideControls +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Hide the default + + HTMLMediaElement + + controls.

+line: 4645 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let dragon; + let isHidden = false; + + function setup() { + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + // Show the default media controls. + dragon.showControls(); + + describe('The text "Double-click to hide controls" written in the middle of a gray square. A song plays in the background. Audio controls are displayed beneath the canvas. The controls appear/disappear when the user double-clicks the square.'); + } + + function draw() { + background(200); + + // Display a different message when + // controls are hidden or shown. + textAlign(CENTER); + if (isHidden === true) { + text('Double-click to show controls', 10, 20, 80, 80); + } else { + text('Double-click to hide controls', 10, 20, 80, 80); + } + } + + // Show/hide controls based on a double-click. + function doubleClicked() { + if (isHidden === true) { + dragon.showControls(); + isHidden = false; + } else { + dragon.hideControls(); + isHidden = true; + } + } + +
+chainable: false +--- + + +# hideControls diff --git a/src/content/reference/en/p5.MediaElement/loop.mdx b/src/content/reference/en/p5.MediaElement/loop.mdx new file mode 100644 index 0000000000..d2e520c406 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/loop.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loop +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Play the audio/video repeatedly in a loop.

+line: 3922 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + let isLooping = false; + + function setup() { + background(200); + + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "Click to loop" written in black on a gray background. A beat plays repeatedly in a loop when the user clicks. The beat stops when the user clicks again.'); + } + + function draw() { + background(200); + + // Display different instructions + // based on playback. + textAlign(CENTER); + if (isLooping === true) { + text('Click to stop', 50, 50); + } else { + text('Click to loop', 50, 50); + } + } + + // Adjust playback when the user + // presses the mouse. + function mousePressed() { + if (isLooping === true) { + // If the beat is looping, + // stop it. + beat.stop(); + isLooping = false; + } else { + // If the beat is stopped, + // loop it. + beat.loop(); + isLooping = true; + } + } + +
+chainable: true +--- + + +# loop diff --git a/src/content/reference/en/p5.MediaElement/noLoop.mdx b/src/content/reference/en/p5.MediaElement/noLoop.mdx new file mode 100644 index 0000000000..5d062cff3a --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/noLoop.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noLoop +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Stops the audio/video from playing in a loop. It will stop when it + reaches the end.

+line: 3978 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + let isPlaying = false; + + function setup() { + background(200); + + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "Click to play" written in black on a gray background. A beat plays when the user clicks. The beat stops when the user clicks again.'); + } + + function draw() { + background(200); + + // Display different instructions + // based on playback. + textAlign(CENTER); + if (isPlaying === true) { + text('Click to stop', 50, 50); + } else { + text('Click to play', 50, 50); + } + } + + // Adjust playback when the user + // presses the mouse. + function mousePressed() { + if (isPlaying === true) { + // If the beat is playing, + // stop it. + beat.stop(); + isPlaying = false; + } else { + // If the beat is stopped, + // play it. + beat.play(); + isPlaying = true; + } + } + +
+chainable: true +--- + + +# noLoop diff --git a/src/content/reference/en/p5.MediaElement/onended.mdx b/src/content/reference/en/p5.MediaElement/onended.mdx new file mode 100644 index 0000000000..ff82b35ba7 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/onended.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: onended +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Calls a function when the audio/video reaches the end of its playback + + The function won't be called if the media is looping.

+ +

The p5.MediaElement is passed as an argument to the callback + function.

+line: 4482 +params: + - name: callback + description: | +

function to call when playback ends. + The p5.MediaElement is passed as + the argument.

+ type: Function +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + let isPlaying = false; + let isDone = false; + + function setup() { + + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + // Set isDone to false when + // the beat finishes. + beat.onended(() => { + isDone = true; + }); + + describe('The text "Click to play" written in black on a gray square. A beat plays when the user clicks. The text "Done!" appears when the beat finishes playing.'); + } + + function draw() { + background(200); + + // Display different messages + // based on playback. + textAlign(CENTER); + if (isDone === true) { + text('Done!', 50, 50); + } else if (isPlaying === false) { + text('Click to play', 50, 50); + } else { + text('Playing...', 50, 50); + } + } + + // Play the beat when the + // user presses the mouse. + function mousePressed() { + if (isPlaying === false) { + isPlaying = true; + beat.play(); + } + } + +
+chainable: true +--- + + +# onended diff --git a/src/content/reference/en/p5.MediaElement/pause.mdx b/src/content/reference/en/p5.MediaElement/pause.mdx new file mode 100644 index 0000000000..8506ba1ea7 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/pause.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Pauses a media element. Calling media.play() will resume + playing + + audio/video from the moment it paused.

+line: 3867 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + let isPaused = true; + + function setup() { + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "Click to play" written in black on a gray background. The beat plays or pauses when the user clicks the square.'); + } + + function draw() { + background(200); + + // Display different instructions + // based on playback. + textAlign(CENTER); + if (isPaused === true) { + text('Click to play', 50, 50); + } else { + text('Click to pause', 50, 50); + } + } + + // Adjust playback when the user + // presses the mouse. + function mousePressed() { + if (isPaused === true) { + // If the beat is paused, + // play it. + beat.play(); + isPaused = false; + } else { + // If the beat is playing, + // pause it. + beat.pause(); + isPaused = true; + } + } + +
+chainable: true +--- + + +# pause diff --git a/src/content/reference/en/p5.MediaElement/play.mdx b/src/content/reference/en/p5.MediaElement/play.mdx new file mode 100644 index 0000000000..3afb01c615 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/play.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Play audio or video from a media element.

+line: 3753 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + + function setup() { + background(200); + + textAlign(CENTER); + text('Click to play', 50, 50); + + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "Click to play" written in black on a gray background. A beat plays when the user clicks the square.'); + } + + // Play the beat when the user + // presses the mouse. + function mousePressed() { + beat.play(); + } + +
+chainable: true +--- + + +# play diff --git a/src/content/reference/en/p5.MediaElement/removeCue.mdx b/src/content/reference/en/p5.MediaElement/removeCue.mdx new file mode 100644 index 0000000000..3167b3732c --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/removeCue.mdx @@ -0,0 +1,68 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeCue +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Remove a callback based on its ID.

+line: 4756 +params: + - name: id + description: | +

ID of the cue, created by media.addCue().

+ type: Number +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let lavenderID; + let isRemoved = false; + + function setup() { + // Create a p5.MediaElement using createAudio(). + let beat = createAudio('assets/beat.mp3'); + // Play the beat in a loop. + beat.loop(); + + // Schedule a few events. + beat.addCue(0, changeBackground, 'red'); + beat.addCue(2, changeBackground, 'deeppink'); + beat.addCue(4, changeBackground, 'orchid'); + + // Record the ID of the "lavender" callback. + lavenderID = beat.addCue(6, changeBackground, 'lavender'); + + describe('The text "Double-click to remove lavender." written on a red square. The color changes every 2 seconds while the audio plays. The lavender option is removed when the user double-clicks the square.'); + } + + function draw() { + if (isRemoved === false) { + text('Double-click to remove lavender.', 10, 10, 80, 80); + } else { + text('No more lavender.', 10, 10, 80, 80); + } + } + + function changeBackground(c) { + background(c); + } + + // Remove the lavender color-change cue + // when the user double-clicks. + function doubleClicked() { + if (isRemoved === false) { + beat.removeCue(lavenderID); + isRemoved = true; + } + } + +
+chainable: false +--- + + +# removeCue diff --git a/src/content/reference/en/p5.MediaElement/showControls.mdx b/src/content/reference/en/p5.MediaElement/showControls.mdx new file mode 100644 index 0000000000..8ef1147694 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/showControls.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: showControls +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Show the default + + HTMLMediaElement + + controls. These vary between web browser.

+line: 4613 +itemtype: method +class: p5.MediaElement +example: + - "\n
\n\nfunction setup() {\n background('cornflowerblue');\n\n textAlign(CENTER);\n textSize(50);\n text('\U0001F409', 50, 50);\n\n // Create a p5.MediaElement using createAudio().\n let dragon = createAudio('assets/lucky_dragons.mp3');\n // Show the default media controls.\n dragon.showControls();\n\n describe('A dragon emoji, \U0001F409, drawn in the center of a blue square. A song plays in the background. Audio controls are displayed beneath the canvas.');\n}\n\n
" +chainable: false +--- + + +# showControls diff --git a/src/content/reference/en/p5.MediaElement/speed.mdx b/src/content/reference/en/p5.MediaElement/speed.mdx new file mode 100644 index 0000000000..b1ef348091 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/speed.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: speed +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Manages the audio/video playback speed. Calling media.speed() + returns + + the current speed as a number.

+ +

The parameter, val, is optional. It's a number that sets the + playback + + speed. 1 plays the media at normal speed, 0.5 plays it at half speed, 2 + + plays it at double speed, and so on. -1 plays the media at normal speed + + in reverse.

+ +

Note: Not all browsers support backward playback. Even if they do, + + playback might not be smooth.

+line: 4188 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let dragon; + + function setup() { + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + + // Show the default media controls. + dragon.showControls(); + + describe('The text "Speed: S" on a gray square with media controls beneath it. The number "S" oscillates between 0 and 1 as the music plays.'); + } + + function draw() { + background(200); + + // Produce a number between 0 and 2. + let n = sin(frameCount * 0.01) + 1; + // Use n to set the playback speed. + dragon.speed(n); + + // Get the current speed + // and display it. + let s = dragon.speed(); + // Round s to 1 decimal place + // for display. + s = round(s, 1); + textAlign(CENTER); + text(`Speed: ${s}`, 50, 50); + } + +return: + description: current playback speed. + type: Number +chainable: false +--- + + +# speed diff --git a/src/content/reference/en/p5.MediaElement/src.mdx b/src/content/reference/en/p5.MediaElement/src.mdx new file mode 100644 index 0000000000..5f6d20eff2 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/src.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: src +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Path to the media element's source as a string.

+line: 3699 +itemtype: property +class: p5.MediaElement +example: + - |- + +
+ + let beat; + + function setup() { + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "https://p5js.org/reference/assets/beat.mp3" written in black on a gray background.'); + } + + function draw() { + background(200); + + textWrap(CHAR); + text(beat.src, 10, 10, 80, 80); + } + +
+return: + description: src + type: String +chainable: false +--- + + +# src diff --git a/src/content/reference/en/p5.MediaElement/stop.mdx b/src/content/reference/en/p5.MediaElement/stop.mdx new file mode 100644 index 0000000000..fbe62fc556 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/stop.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Stops a media element and sets its current time to zero. Calling + + media.play() will restart playing audio/video from the + beginning.

+line: 3813 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let beat; + let isStopped = true; + + function setup() { + // Create a p5.MediaElement using createAudio(). + beat = createAudio('assets/beat.mp3'); + + describe('The text "Click to start" written in black on a gray background. The beat starts or stops when the user presses the mouse.'); + } + + function draw() { + background(200); + + textAlign(CENTER); + if (isStopped === true) { + text('Click to start', 50, 50); + } else { + text('Click to stop', 50, 50); + } + } + + // Adjust playback when the user + // presses the mouse. + function mousePressed() { + if (isStopped === true) { + // If the beat is stopped, + // play it. + beat.play(); + isStopped = false; + } else { + // If the beat is playing, + // stop it. + beat.stop(); + isStopped = true; + } + } + +
+chainable: true +--- + + +# stop diff --git a/src/content/reference/en/p5.MediaElement/time.mdx b/src/content/reference/en/p5.MediaElement/time.mdx new file mode 100644 index 0000000000..3e6e71ebb9 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/time.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: time +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Manages the media element's playback time. Calling + media.time() + + returns the number of seconds the audio/video has played. Time resets to + + 0 when the looping media restarts.

+ +

The parameter, time, is optional. It's a number that specifies + the + + time, in seconds, to jump to when playback begins.

+line: 4255 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let dragon; + + function setup() { + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + // Show the default media controls. + dragon.showControls(); + + describe('The text "S seconds" on a gray square with media controls beneath it. The number "S" increases as the song plays.'); + } + + function draw() { + background(200); + + // Display the current time. + let s = dragon.time(); + // Round s to 1 decimal place + // for display. + s = round(s, 1); + textAlign(CENTER); + text(`${s} seconds`, 50, 50); + } + +
+ +
+ + let dragon; + + function setup() { + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + // Show the default media controls. + dragon.showControls(); + + // Jump to 2 seconds + // to start. + dragon.time(2); + + describe('The text "S seconds" on a gray square with media controls beneath it. The number "S" increases as the song plays.'); + } + + function draw() { + background(200); + + // Display the current time. + let s = dragon.time(); + // Round s to 1 decimal place + // for display. + s = round(s, 1); + textAlign(CENTER); + text(`${s} seconds`, 50, 50); + } + +
+return: + description: current time (in seconds). + type: Number +chainable: false +--- + + +# time diff --git a/src/content/reference/en/p5.MediaElement/volume.mdx b/src/content/reference/en/p5.MediaElement/volume.mdx new file mode 100644 index 0000000000..ba00a016b6 --- /dev/null +++ b/src/content/reference/en/p5.MediaElement/volume.mdx @@ -0,0 +1,67 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: volume +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Manages the audio/video volume.

+ +

Calling media.volume() without an argument returns the current + volume + + as a number in the range 0 (off) to 1 (maximum).

+ +

The parameter, val, is optional. It's a number that sets the + volume + + from 0 (off) to 1 (maximum). For example, calling + media.volume(0.5) + + sets the volume to half of its maximum.

+line: 4128 +itemtype: method +class: p5.MediaElement +example: + - |- + +
+ + let dragon; + + function setup() { + // Create a p5.MediaElement using createAudio(). + dragon = createAudio('assets/lucky_dragons.mp3'); + // Show the default media controls. + dragon.showControls(); + + describe('The text "Volume: V" on a gray square with media controls beneath it. The number "V" oscillates between 0 and 1 as the music plays.'); + } + + function draw() { + background(200); + + // Produce a number between 0 and 1. + let n = 0.5 * sin(frameCount * 0.01) + 0.5; + // Use n to set the volume. + dragon.volume(n); + + // Get the current volume + // and display it. + let v = dragon.volume(); + // Round v to 1 decimal place + // for display. + v = round(v, 1); + textAlign(CENTER); + text(`Volume: ${v}`, 50, 50); + } + +
+return: + description: current volume. + type: Number +chainable: false +--- + + +# volume diff --git a/src/content/reference/en/p5.MonoSynth/amp.mdx b/src/content/reference/en/p5.MonoSynth/amp.mdx new file mode 100644 index 0000000000..200c4866f4 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/amp.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

MonoSynth amp

+line: 11544 +params: + - name: vol + description: | +

desired volume

+ type: Number + - name: rampTime + description: | +

Time to reach new volume

+ type: Number + optional: true +itemtype: method +class: p5.MonoSynth +return: + description: new volume value + type: Number +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.MonoSynth/attack.mdx b/src/content/reference/en/p5.MonoSynth/attack.mdx new file mode 100644 index 0000000000..9b4a2b6709 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/attack.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: attack +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getters and Setters

+line: 11322 +itemtype: property +class: p5.MonoSynth +chainable: false +--- + + +# attack diff --git a/src/content/reference/en/p5.MonoSynth/connect.mdx b/src/content/reference/en/p5.MonoSynth/connect.mdx new file mode 100644 index 0000000000..a9da457f60 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/connect.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect to a p5.sound / Web Audio object.

+line: 11564 +params: + - name: unit + description: | +

A p5.sound or Web Audio object

+ type: Object +itemtype: method +class: p5.MonoSynth +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.MonoSynth/decay.mdx b/src/content/reference/en/p5.MonoSynth/decay.mdx new file mode 100644 index 0000000000..d11689a7aa --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/decay.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: decay +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 11328 +itemtype: property +class: p5.MonoSynth +chainable: false +--- + + +# decay diff --git a/src/content/reference/en/p5.MonoSynth/disconnect.mdx b/src/content/reference/en/p5.MonoSynth/disconnect.mdx new file mode 100644 index 0000000000..40d51e3d8f --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all outputs

+line: 11578 +itemtype: method +class: p5.MonoSynth +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.MonoSynth/dispose.mdx b/src/content/reference/en/p5.MonoSynth/dispose.mdx new file mode 100644 index 0000000000..5d408b6216 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/dispose.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dispose +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get rid of the MonoSynth and free up its resources / memory.

+line: 11592 +itemtype: method +class: p5.MonoSynth +chainable: false +--- + + +# dispose diff --git a/src/content/reference/en/p5.MonoSynth/play.mdx b/src/content/reference/en/p5.MonoSynth/play.mdx new file mode 100644 index 0000000000..9101923c68 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/play.mdx @@ -0,0 +1,72 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Play tells the MonoSynth to start playing a note. This method schedules + the calling of .triggerAttack and .triggerRelease.

+line: 11379 +params: + - name: note + description: | +

the note you want to play, specified as a + frequency in Hertz (Number) or as a midi + value in Note/Octave format ("C4", "Eb3"...etc") + See + Tone. Defaults to 440 hz.

+ type: String | Number + - name: velocity + description: | +

velocity of the note to play (ranging from 0 to 1)

+ type: Number + optional: true + - name: secondsFromNow + description: | +

time from now (in seconds) at which to play

+ type: Number + optional: true + - name: sustainTime + description: > +

time to sustain before releasing the envelope. Defaults to 0.15 + seconds.

+ type: Number + optional: true +itemtype: method +class: p5.MonoSynth +example: + - | + +
+ let monoSynth; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playSynth); + background(220); + textAlign(CENTER); + text('tap to play', width/2, height/2); + + monoSynth = new p5.MonoSynth(); + } + + function playSynth() { + userStartAudio(); + + let note = random(['Fb4', 'G4']); + // note velocity (volume, from 0 to 1) + let velocity = random(); + // time from now (in seconds) + let time = 0; + // note duration (in seconds) + let dur = 1/6; + + monoSynth.play(note, velocity, time, dur); + } +
+chainable: false +--- + + +# play diff --git a/src/content/reference/en/p5.MonoSynth/release.mdx b/src/content/reference/en/p5.MonoSynth/release.mdx new file mode 100644 index 0000000000..2da7f11aff --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/release.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: release +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 11338 +itemtype: property +class: p5.MonoSynth +chainable: false +--- + + +# release diff --git a/src/content/reference/en/p5.MonoSynth/setADSR.mdx b/src/content/reference/en/p5.MonoSynth/setADSR.mdx new file mode 100644 index 0000000000..0c3607641e --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/setADSR.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setADSR +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Set values like a traditional + + + + ADSR envelope + + .

+line: 11516 +params: + - name: attackTime + description: | +

Time (in seconds before envelope + reaches Attack Level

+ type: Number + - name: decayTime + description: | +

Time (in seconds) before envelope + reaches Decay/Sustain Level

+ type: Number + optional: true + - name: susRatio + description: | +

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1, + where 1.0 = attackLevel, 0.0 = releaseLevel. + The susRatio determines the decayLevel and the level at which the + sustain portion of the envelope will sustain. + For example, if attackLevel is 0.4, releaseLevel is 0, + and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is + increased to 1.0 (using setRange), + then decayLevel would increase proportionally, to become 0.5.

+ type: Number + optional: true + - name: releaseTime + description: | +

Time in seconds from now (defaults to 0)

+ type: Number + optional: true +itemtype: method +class: p5.MonoSynth +chainable: false +--- + + +# setADSR diff --git a/src/content/reference/en/p5.MonoSynth/sustain.mdx b/src/content/reference/en/p5.MonoSynth/sustain.mdx new file mode 100644 index 0000000000..bd8dc0c609 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/sustain.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sustain +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: '' +line: 11333 +itemtype: property +class: p5.MonoSynth +chainable: false +--- + + +# sustain diff --git a/src/content/reference/en/p5.MonoSynth/triggerAttack.mdx b/src/content/reference/en/p5.MonoSynth/triggerAttack.mdx new file mode 100644 index 0000000000..f29e9c6f58 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/triggerAttack.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: triggerAttack +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the Attack, and Decay portion of the Envelope. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go.

+line: 11431 +params: + - name: note + description: | +

the note you want to play, specified as a + frequency in Hertz (Number) or as a midi + value in Note/Octave format ("C4", "Eb3"...etc") + See + Tone. Defaults to 440 hz

+ type: String | Number + - name: velocity + description: | +

velocity of the note to play (ranging from 0 to 1)

+ type: Number + optional: true + - name: secondsFromNow + description: | +

time from now (in seconds) at which to play

+ type: Number + optional: true +itemtype: method +class: p5.MonoSynth +example: + - |- + +
+ let monoSynth; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(triggerAttack); + background(220); + text('tap here for attack, let go to release', 5, 20, width - 20); + monoSynth = new p5.MonoSynth(); + } + + function triggerAttack() { + userStartAudio(); + + monoSynth.triggerAttack("E3"); + } + + function mouseReleased() { + monoSynth.triggerRelease(); + } +
+chainable: false +--- + + +# triggerAttack diff --git a/src/content/reference/en/p5.MonoSynth/triggerRelease.mdx b/src/content/reference/en/p5.MonoSynth/triggerRelease.mdx new file mode 100644 index 0000000000..b9079a0f88 --- /dev/null +++ b/src/content/reference/en/p5.MonoSynth/triggerRelease.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: triggerRelease +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the release of the Envelope. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+line: 11478 +params: + - name: secondsFromNow + description: | +

time to trigger the release

+ type: Number +itemtype: method +class: p5.MonoSynth +example: + - |- + +
+ let monoSynth; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(triggerAttack); + background(220); + text('tap here for attack, let go to release', 5, 20, width - 20); + monoSynth = new p5.MonoSynth(); + } + + function triggerAttack() { + userStartAudio(); + + monoSynth.triggerAttack("E3"); + } + + function mouseReleased() { + monoSynth.triggerRelease(); + } +
+chainable: false +--- + + +# triggerRelease diff --git a/src/content/reference/en/p5.Noise/setType.mdx b/src/content/reference/en/p5.Noise/setType.mdx new file mode 100644 index 0000000000..efeaafb858 --- /dev/null +++ b/src/content/reference/en/p5.Noise/setType.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setType +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set type of noise to 'white', 'pink' or 'brown'. + White is the default.

+line: 5657 +params: + - name: type + description: | +

'white', 'pink' or 'brown'

+ type: String + optional: true +itemtype: method +class: p5.Noise +chainable: false +--- + + +# setType diff --git a/src/content/reference/en/p5.NumberDict/add.mdx b/src/content/reference/en/p5.NumberDict/add.mdx new file mode 100644 index 0000000000..cb98eb6a71 --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/add.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: add +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Add the given number to the value currently stored at the given key. + The sum then replaces the value previously stored in the Dictionary.

+line: 439 +params: + - name: Key + description: | +

for the value you wish to add to

+ type: Number + - name: Number + description: | +

to add to the value

+ type: Number +itemtype: method +class: p5.NumberDict +example: + - | + +
+ + function setup() { + let myDictionary = createNumberDict(2, 5); + myDictionary.add(2, 2); + print(myDictionary.get(2)); // logs 7 to console. + } +
+chainable: false +--- + + +# add diff --git a/src/content/reference/en/p5.NumberDict/div.mdx b/src/content/reference/en/p5.NumberDict/div.mdx new file mode 100644 index 0000000000..8c7034bb7e --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/div.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: div +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Divide the given number with the value currently stored at the given key. + The quotient then replaces the value previously stored in the Dictionary.

+line: 516 +params: + - name: Key + description: | +

for value you wish to divide

+ type: Number + - name: Amount + description: | +

to divide the value by

+ type: Number +itemtype: method +class: p5.NumberDict +example: + - | + +
+ + function setup() { + let myDictionary = createNumberDict(2, 8); + myDictionary.div(2, 2); + print(myDictionary.get(2)); // logs 4 to console. + } +
+chainable: false +--- + + +# div diff --git a/src/content/reference/en/p5.NumberDict/maxKey.mdx b/src/content/reference/en/p5.NumberDict/maxKey.mdx new file mode 100644 index 0000000000..bea693630b --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/maxKey.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: maxKey +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Return the highest key currently used in the Dictionary.

+line: 649 +itemtype: method +class: p5.NumberDict +example: + - |- + +
+ + function setup() { + let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); + let highestKey = myDictionary.maxKey(); // value is 4 + print(highestKey); + } +
+return: + description: '' + type: Number +chainable: false +--- + + +# maxKey diff --git a/src/content/reference/en/p5.NumberDict/maxValue.mdx b/src/content/reference/en/p5.NumberDict/maxValue.mdx new file mode 100644 index 0000000000..baf058d414 --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/maxValue.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: maxValue +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Return the highest number currently stored in the Dictionary.

+line: 587 +itemtype: method +class: p5.NumberDict +example: + - |- + +
+ + function setup() { + let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); + let highestValue = myDictionary.maxValue(); // value is 3 + print(highestValue); + } +
+return: + description: '' + type: Number +chainable: false +--- + + +# maxValue diff --git a/src/content/reference/en/p5.NumberDict/minKey.mdx b/src/content/reference/en/p5.NumberDict/minKey.mdx new file mode 100644 index 0000000000..3f1af56337 --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/minKey.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: minKey +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Return the lowest key currently used in the Dictionary.

+line: 629 +itemtype: method +class: p5.NumberDict +example: + - |- + +
+ + function setup() { + let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); + let lowestKey = myDictionary.minKey(); // value is 1.2 + print(lowestKey); + } +
+return: + description: '' + type: Number +chainable: false +--- + + +# minKey diff --git a/src/content/reference/en/p5.NumberDict/minValue.mdx b/src/content/reference/en/p5.NumberDict/minValue.mdx new file mode 100644 index 0000000000..1a58c28c1d --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/minValue.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: minValue +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Return the lowest number currently stored in the Dictionary.

+line: 567 +itemtype: method +class: p5.NumberDict +example: + - |- + +
+ + function setup() { + let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); + let lowestValue = myDictionary.minValue(); // value is -10 + print(lowestValue); + } +
+return: + description: '' + type: Number +chainable: false +--- + + +# minValue diff --git a/src/content/reference/en/p5.NumberDict/mult.mdx b/src/content/reference/en/p5.NumberDict/mult.mdx new file mode 100644 index 0000000000..4e9809b8c5 --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/mult.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mult +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Multiply the given number with the value currently stored at the given key. + The product then replaces the value previously stored in the Dictionary.

+line: 489 +params: + - name: Key + description: | +

for value you wish to multiply

+ type: Number + - name: Amount + description: | +

to multiply the value by

+ type: Number +itemtype: method +class: p5.NumberDict +example: + - | + +
+ + function setup() { + let myDictionary = createNumberDict(2, 4); + myDictionary.mult(2, 2); + print(myDictionary.get(2)); // logs 8 to console. + } +
+chainable: false +--- + + +# mult diff --git a/src/content/reference/en/p5.NumberDict/sub.mdx b/src/content/reference/en/p5.NumberDict/sub.mdx new file mode 100644 index 0000000000..1704eee1e9 --- /dev/null +++ b/src/content/reference/en/p5.NumberDict/sub.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sub +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: > +

Subtract the given number from the value currently stored at the given key. + + The difference then replaces the value previously stored in the + Dictionary.

+line: 466 +params: + - name: Key + description: | +

for the value you wish to subtract from

+ type: Number + - name: Number + description: | +

to subtract from the value

+ type: Number +itemtype: method +class: p5.NumberDict +example: + - | + +
+ + function setup() { + let myDictionary = createNumberDict(2, 5); + myDictionary.sub(2, 2); + print(myDictionary.get(2)); // logs 3 to console. + } +
+chainable: false +--- + + +# sub diff --git a/src/content/reference/en/p5.Oscillator/add.mdx b/src/content/reference/en/p5.Oscillator/add.mdx new file mode 100644 index 0000000000..f4ed12bc9f --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/add.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: add +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Add a value to the p5.Oscillator's output amplitude, + and return the oscillator. Calling this method again + will override the initial add() with a new value.

+line: 4522 +params: + - name: number + description: | +

Constant number to add

+ type: Number +itemtype: method +class: p5.Oscillator +return: + description: |- + Oscillator Returns this oscillator + with scaled output + type: p5.Oscillator +chainable: false +--- + + +# add diff --git a/src/content/reference/en/p5.Oscillator/amp.mdx b/src/content/reference/en/p5.Oscillator/amp.mdx new file mode 100644 index 0000000000..e5558eeb50 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/amp.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the amplitude between 0 and 1.0. Or, pass in an object + such as an oscillator to modulate amplitude with an audio signal.

+line: 4238 +params: + - name: vol + description: | +

between 0 and 1.0 + or a modulating signal/oscillator

+ type: Number|Object + - name: rampTime + description: | +

create a fade that lasts rampTime

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Oscillator +return: + description: |- + gain If no value is provided, + returns the Web Audio API + AudioParam that controls + this oscillator's + gain/amplitude/volume) + type: AudioParam +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.Oscillator/connect.mdx b/src/content/reference/en/p5.Oscillator/connect.mdx new file mode 100644 index 0000000000..e2901b4941 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/connect.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect to a p5.sound / Web Audio object.

+line: 4399 +params: + - name: unit + description: | +

A p5.sound or Web Audio object

+ type: Object +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.Oscillator/disconnect.mdx b/src/content/reference/en/p5.Oscillator/disconnect.mdx new file mode 100644 index 0000000000..d2f7402ad4 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all outputs

+line: 4420 +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Oscillator/freq.mdx b/src/content/reference/en/p5.Oscillator/freq.mdx new file mode 100644 index 0000000000..2774b66500 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/freq.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: freq +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set frequency of an oscillator to a value. Or, pass in an object + such as an oscillator to modulate the frequency with an audio signal.

+line: 4285 +params: + - name: Frequency + description: | +

Frequency in Hz + or modulating signal/oscillator

+ type: Number|Object + - name: rampTime + description: | +

Ramp time (in seconds)

+ type: Number + optional: true + - name: timeFromNow + description: | +

Schedule this event to happen + at x seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Oscillator +example: + - |- + +
+ let osc; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playOscillator); + osc = new p5.Oscillator(300); + background(220); + text('tap to play', 20, 20); + } + + function playOscillator() { + osc.start(); + osc.amp(0.5); + // start at 700Hz + osc.freq(700); + // ramp to 60Hz over 0.7 seconds + osc.freq(60, 0.7); + osc.amp(0, 0.1, 0.7); + } +
+return: + description: |- + Frequency If no value is provided, + returns the Web Audio API + AudioParam that controls + this oscillator's frequency + type: AudioParam +chainable: false +--- + + +# freq diff --git a/src/content/reference/en/p5.Oscillator/getAmp.mdx b/src/content/reference/en/p5.Oscillator/getAmp.mdx new file mode 100644 index 0000000000..f8a0a3bac0 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/getAmp.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getAmp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the value of output gain

+line: 4271 +itemtype: method +class: p5.Oscillator +return: + description: Amplitude value between 0.0 and 1.0 + type: Number +chainable: false +--- + + +# getAmp diff --git a/src/content/reference/en/p5.Oscillator/getFreq.mdx b/src/content/reference/en/p5.Oscillator/getFreq.mdx new file mode 100644 index 0000000000..cf60ee4f6e --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/getFreq.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getFreq +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the value of frequency of oscillator

+line: 4360 +itemtype: method +class: p5.Oscillator +return: + description: Frequency of oscillator in Hertz + type: Number +chainable: false +--- + + +# getFreq diff --git a/src/content/reference/en/p5.Oscillator/getPan.mdx b/src/content/reference/en/p5.Oscillator/getPan.mdx new file mode 100644 index 0000000000..98ff9cf976 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/getPan.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getPan +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Returns the current value of panPosition , between Left (-1) and Right + (1)

+line: 4460 +itemtype: method +class: p5.Oscillator +return: + description: 'panPosition of oscillator , between Left (-1) and Right (1)' + type: Number +chainable: false +--- + + +# getPan diff --git a/src/content/reference/en/p5.Oscillator/getType.mdx b/src/content/reference/en/p5.Oscillator/getType.mdx new file mode 100644 index 0000000000..7b88a7cd54 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/getType.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getType +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Returns current type of oscillator eg. 'sine', 'triangle', 'sawtooth' or + 'square'.

+line: 4386 +itemtype: method +class: p5.Oscillator +return: + description: 'type of oscillator eg . ''sine'', ''triangle'', ''sawtooth'' or ''square''.' + type: String +chainable: false +--- + + +# getType diff --git a/src/content/reference/en/p5.Oscillator/mult.mdx b/src/content/reference/en/p5.Oscillator/mult.mdx new file mode 100644 index 0000000000..6f6b5ad28d --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/mult.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mult +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Multiply the p5.Oscillator's output amplitude + by a fixed value (i.e. turn it up!). Calling this method + again will override the initial mult() with a new value.

+line: 4543 +params: + - name: number + description: | +

Constant number to multiply

+ type: Number +itemtype: method +class: p5.Oscillator +return: + description: |- + Oscillator Returns this oscillator + with multiplied output + type: p5.Oscillator +chainable: false +--- + + +# mult diff --git a/src/content/reference/en/p5.Oscillator/pan.mdx b/src/content/reference/en/p5.Oscillator/pan.mdx new file mode 100644 index 0000000000..60d86f61f3 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/pan.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pan +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Pan between Left (-1) and Right (1)

+line: 4444 +params: + - name: panning + description: | +

Number between -1 and 1

+ type: Number + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# pan diff --git a/src/content/reference/en/p5.Oscillator/phase.mdx b/src/content/reference/en/p5.Oscillator/phase.mdx new file mode 100644 index 0000000000..eaa589eb53 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/phase.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: phase +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the phase of an oscillator between 0.0 and 1.0. + In this implementation, phase is a delay time + based on the oscillator's current frequency.

+line: 4494 +params: + - name: phase + description: | +

float between 0.0 and 1.0

+ type: Number +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# phase diff --git a/src/content/reference/en/p5.Oscillator/scale.mdx b/src/content/reference/en/p5.Oscillator/scale.mdx new file mode 100644 index 0000000000..91f846d18a --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/scale.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: scale +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Scale this oscillator's amplitude values to a given + range, and return the oscillator. Calling this method + again will override the initial scale() with new values.

+line: 4563 +params: + - name: inMin + description: | +

input range minumum

+ type: Number + - name: inMax + description: | +

input range maximum

+ type: Number + - name: outMin + description: | +

input range minumum

+ type: Number + - name: outMax + description: | +

input range maximum

+ type: Number +itemtype: method +class: p5.Oscillator +return: + description: |- + Oscillator Returns this oscillator + with scaled output + type: p5.Oscillator +chainable: false +--- + + +# scale diff --git a/src/content/reference/en/p5.Oscillator/setType.mdx b/src/content/reference/en/p5.Oscillator/setType.mdx new file mode 100644 index 0000000000..f0044bef79 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/setType.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setType +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set type to 'sine', 'triangle', 'sawtooth' or 'square'.

+line: 4373 +params: + - name: type + description: | +

'sine', 'triangle', 'sawtooth' or 'square'.

+ type: String +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# setType diff --git a/src/content/reference/en/p5.Oscillator/start.mdx b/src/content/reference/en/p5.Oscillator/start.mdx new file mode 100644 index 0000000000..d4bdb6238e --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/start.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: start +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start an oscillator.

+

Starting an oscillator on a user gesture will enable audio in browsers + that have a strict autoplay policy, including Chrome and most mobile + devices. See also: userStartAudio().

+line: 4168 +params: + - name: time + description: | +

startTime in seconds from now.

+ type: Number + optional: true + - name: frequency + description: | +

frequency in Hz.

+ type: Number + optional: true +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# start diff --git a/src/content/reference/en/p5.Oscillator/stop.mdx b/src/content/reference/en/p5.Oscillator/stop.mdx new file mode 100644 index 0000000000..2858217111 --- /dev/null +++ b/src/content/reference/en/p5.Oscillator/stop.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop an oscillator. Accepts an optional parameter + to determine how long (in seconds from now) until the + oscillator stops.

+line: 4218 +params: + - name: secondsFromNow + description: | +

Time, in seconds from now.

+ type: Number +itemtype: method +class: p5.Oscillator +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.Panner3D/maxDist.mdx b/src/content/reference/en/p5.Panner3D/maxDist.mdx new file mode 100644 index 0000000000..193593360f --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/maxDist.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: maxDist +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Maxium distance between the source and the listener

+line: 7852 +params: + - name: maxDistance + description: '' + type: Number +itemtype: method +class: p5.Panner3D +return: + description: updated value + type: Number +chainable: false +--- + + +# maxDist diff --git a/src/content/reference/en/p5.Panner3D/orient.mdx b/src/content/reference/en/p5.Panner3D/orient.mdx new file mode 100644 index 0000000000..37846ac0cd --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/orient.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: orient +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the X,Y,Z position of the Panner

+line: 7753 +params: + - name: xVal + description: '' + type: Number + - name: yVal + description: '' + type: Number + - name: zVal + description: '' + type: Number + - name: time + description: '' + type: Number +itemtype: method +class: p5.Panner3D +return: + description: 'Updated x, y, z values as an array' + type: Array +chainable: false +--- + + +# orient diff --git a/src/content/reference/en/p5.Panner3D/orientX.mdx b/src/content/reference/en/p5.Panner3D/orientX.mdx new file mode 100644 index 0000000000..70ef06cdcf --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/orientX.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: orientX +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for orient coordinates

+line: 7772 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# orientX diff --git a/src/content/reference/en/p5.Panner3D/orientY.mdx b/src/content/reference/en/p5.Panner3D/orientY.mdx new file mode 100644 index 0000000000..9796f574d7 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/orientY.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: orientY +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for orient coordinates

+line: 7779 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# orientY diff --git a/src/content/reference/en/p5.Panner3D/orientZ.mdx b/src/content/reference/en/p5.Panner3D/orientZ.mdx new file mode 100644 index 0000000000..0771949203 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/orientZ.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: orientZ +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for orient coordinates

+line: 7786 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# orientZ diff --git a/src/content/reference/en/p5.Panner3D/panner.mdx b/src/content/reference/en/p5.Panner3D/panner.mdx new file mode 100644 index 0000000000..d3754886a7 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/panner.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: panner +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

+ Web Audio Spatial Panner Node

+

Properties include
+ Panning Model + : "equal power" or "HRTF"
+ DistanceModel + : "linear", "inverse", or "exponential"

+line: 7629 +itemtype: property +class: p5.Panner3D +chainable: false +--- + + +# panner diff --git a/src/content/reference/en/p5.Panner3D/positionX.mdx b/src/content/reference/en/p5.Panner3D/positionX.mdx new file mode 100644 index 0000000000..b7bd91ed43 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/positionX.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: positionX +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for position coordinates

+line: 7687 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# positionX diff --git a/src/content/reference/en/p5.Panner3D/positionY.mdx b/src/content/reference/en/p5.Panner3D/positionY.mdx new file mode 100644 index 0000000000..f9b18bee58 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/positionY.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: positionY +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for position coordinates

+line: 7694 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# positionY diff --git a/src/content/reference/en/p5.Panner3D/positionZ.mdx b/src/content/reference/en/p5.Panner3D/positionZ.mdx new file mode 100644 index 0000000000..4b63c07570 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/positionZ.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: positionZ +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Getter and setter methods for position coordinates

+line: 7701 +itemtype: method +class: p5.Panner3D +return: + description: updated coordinate value + type: Number +chainable: false +--- + + +# positionZ diff --git a/src/content/reference/en/p5.Panner3D/process.mdx b/src/content/reference/en/p5.Panner3D/process.mdx new file mode 100644 index 0000000000..6ab9dee282 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/process.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect an audio sorce

+line: 7654 +params: + - name: src + description: | +

Input source

+ type: Object +itemtype: method +class: p5.Panner3D +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Panner3D/rollof.mdx b/src/content/reference/en/p5.Panner3D/rollof.mdx new file mode 100644 index 0000000000..eb421e8b38 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/rollof.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rollof +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

How quickly the volume is reduced as the source moves away from the + listener

+line: 7869 +params: + - name: rolloffFactor + description: '' + type: Number +itemtype: method +class: p5.Panner3D +return: + description: updated value + type: Number +chainable: false +--- + + +# rollof diff --git a/src/content/reference/en/p5.Panner3D/set.mdx b/src/content/reference/en/p5.Panner3D/set.mdx new file mode 100644 index 0000000000..fc6c9df604 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/set.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the X,Y,Z position of the Panner

+line: 7668 +params: + - name: xVal + description: '' + type: Number + - name: yVal + description: '' + type: Number + - name: zVal + description: '' + type: Number + - name: time + description: '' + type: Number +itemtype: method +class: p5.Panner3D +return: + description: 'Updated x, y, z values as an array' + type: Array +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Panner3D/setFalloff.mdx b/src/content/reference/en/p5.Panner3D/setFalloff.mdx new file mode 100644 index 0000000000..c76642cfe8 --- /dev/null +++ b/src/content/reference/en/p5.Panner3D/setFalloff.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setFalloff +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the rolloff factor and max distance

+line: 7838 +params: + - name: maxDistance + description: '' + type: Number + optional: true + - name: rolloffFactor + description: '' + type: Number + optional: true +itemtype: method +class: p5.Panner3D +chainable: false +--- + + +# setFalloff diff --git a/src/content/reference/en/p5.Part/addPhrase.mdx b/src/content/reference/en/p5.Part/addPhrase.mdx new file mode 100644 index 0000000000..c16f5c05f7 --- /dev/null +++ b/src/content/reference/en/p5.Part/addPhrase.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addPhrase +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Add a p5.Phrase to this Part.

+line: 9379 +params: + - name: phrase + description: | +

reference to a p5.Phrase

+ type: p5.Phrase +itemtype: method +class: p5.Part +chainable: false +--- + + +# addPhrase diff --git a/src/content/reference/en/p5.Part/getBPM.mdx b/src/content/reference/en/p5.Part/getBPM.mdx new file mode 100644 index 0000000000..1db25025e4 --- /dev/null +++ b/src/content/reference/en/p5.Part/getBPM.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getBPM +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the tempo, in Beats Per Minute, of this part.

+line: 9278 +itemtype: method +class: p5.Part +return: + description: '' + type: Number +chainable: false +--- + + +# getBPM diff --git a/src/content/reference/en/p5.Part/getPhrase.mdx b/src/content/reference/en/p5.Part/getPhrase.mdx new file mode 100644 index 0000000000..1fd8f2c3c9 --- /dev/null +++ b/src/content/reference/en/p5.Part/getPhrase.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getPhrase +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get a phrase from this part, based on the name it was + given when it was created. Now you can modify its array.

+line: 9424 +params: + - name: phraseName + description: '' + type: String +itemtype: method +class: p5.Part +chainable: false +--- + + +# getPhrase diff --git a/src/content/reference/en/p5.Part/loop.mdx b/src/content/reference/en/p5.Part/loop.mdx new file mode 100644 index 0000000000..08abd42cd7 --- /dev/null +++ b/src/content/reference/en/p5.Part/loop.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Loop playback of this part. It will begin + looping through all of its phrases at a speed + determined by setBPM.

+line: 9311 +params: + - name: time + description: | +

seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Part +chainable: false +--- + + +# loop diff --git a/src/content/reference/en/p5.Part/noLoop.mdx b/src/content/reference/en/p5.Part/noLoop.mdx new file mode 100644 index 0000000000..58cb22cea1 --- /dev/null +++ b/src/content/reference/en/p5.Part/noLoop.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noLoop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Tell the part to stop looping.

+line: 9333 +itemtype: method +class: p5.Part +chainable: false +--- + + +# noLoop diff --git a/src/content/reference/en/p5.Part/onStep.mdx b/src/content/reference/en/p5.Part/onStep.mdx new file mode 100644 index 0000000000..ce7472638b --- /dev/null +++ b/src/content/reference/en/p5.Part/onStep.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: onStep +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Set the function that will be called at every step. This will clear the + previous function.

+line: 9473 +params: + - name: callback + description: | +

The name of the callback + you want to fire + on every beat/tatum.

+ type: Function +itemtype: method +class: p5.Part +chainable: false +--- + + +# onStep diff --git a/src/content/reference/en/p5.Part/pause.mdx b/src/content/reference/en/p5.Part/pause.mdx new file mode 100644 index 0000000000..802f0755f8 --- /dev/null +++ b/src/content/reference/en/p5.Part/pause.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Pause the part. Playback will resume + from the current step.

+line: 9363 +params: + - name: time + description: | +

seconds from now

+ type: Number +itemtype: method +class: p5.Part +chainable: false +--- + + +# pause diff --git a/src/content/reference/en/p5.Part/removePhrase.mdx b/src/content/reference/en/p5.Part/removePhrase.mdx new file mode 100644 index 0000000000..905fb1eaf2 --- /dev/null +++ b/src/content/reference/en/p5.Part/removePhrase.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removePhrase +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Remove a phrase from this part, based on the name it was + given when it was created.

+line: 9406 +params: + - name: phraseName + description: '' + type: String +itemtype: method +class: p5.Part +chainable: false +--- + + +# removePhrase diff --git a/src/content/reference/en/p5.Part/replaceSequence.mdx b/src/content/reference/en/p5.Part/replaceSequence.mdx new file mode 100644 index 0000000000..72b5191358 --- /dev/null +++ b/src/content/reference/en/p5.Part/replaceSequence.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: replaceSequence +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Find all sequences with the specified name, and replace their patterns with + the specified array.

+line: 9442 +params: + - name: phraseName + description: '' + type: String + - name: sequence + description: | +

Array of values to pass into the callback + at each step of the phrase.

+ type: Array +itemtype: method +class: p5.Part +chainable: false +--- + + +# replaceSequence diff --git a/src/content/reference/en/p5.Part/setBPM.mdx b/src/content/reference/en/p5.Part/setBPM.mdx new file mode 100644 index 0000000000..c5faa89df5 --- /dev/null +++ b/src/content/reference/en/p5.Part/setBPM.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setBPM +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the tempo of this part, in Beats Per Minute.

+line: 9263 +params: + - name: BPM + description: | +

Beats Per Minute

+ type: Number + - name: rampTime + description: | +

Seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Part +chainable: false +--- + + +# setBPM diff --git a/src/content/reference/en/p5.Part/start.mdx b/src/content/reference/en/p5.Part/start.mdx new file mode 100644 index 0000000000..616f3c1622 --- /dev/null +++ b/src/content/reference/en/p5.Part/start.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: start +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start playback of this part. It will play + through all of its phrases at a speed + determined by setBPM.

+line: 9291 +params: + - name: time + description: | +

seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Part +chainable: false +--- + + +# start diff --git a/src/content/reference/en/p5.Part/stop.mdx b/src/content/reference/en/p5.Part/stop.mdx new file mode 100644 index 0000000000..a988eab55f --- /dev/null +++ b/src/content/reference/en/p5.Part/stop.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Stop the part and cue it to step 0. Playback will resume from the begining + of the Part when it is played again.

+line: 9349 +params: + - name: time + description: | +

seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Part +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.PeakDetect/isDetected.mdx b/src/content/reference/en/p5.PeakDetect/isDetected.mdx new file mode 100644 index 0000000000..21f18f3f15 --- /dev/null +++ b/src/content/reference/en/p5.PeakDetect/isDetected.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isDetected +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

isDetected is set to true when a peak is detected.

+line: 10419 +itemtype: attribute +class: p5.PeakDetect +chainable: false +--- + + +# isDetected diff --git a/src/content/reference/en/p5.PeakDetect/onPeak.mdx b/src/content/reference/en/p5.PeakDetect/onPeak.mdx new file mode 100644 index 0000000000..f16a7c08ec --- /dev/null +++ b/src/content/reference/en/p5.PeakDetect/onPeak.mdx @@ -0,0 +1,84 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: onPeak +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

onPeak accepts two arguments: a function to call when + a peak is detected. The value of the peak, + between 0.0 and 1.0, is passed to the callback.

+line: 10470 +params: + - name: callback + description: | +

Name of a function that will + be called when a peak is + detected.

+ type: Function + - name: val + description: | +

Optional value to pass + into the function when + a peak is detected.

+ type: Object + optional: true +itemtype: method +class: p5.PeakDetect +example: + - |- + +
+ var cnv, soundFile, fft, peakDetect; + var ellipseWidth = 0; + + function preload() { + soundFile = loadSound('assets/beat.mp3'); + } + + function setup() { + cnv = createCanvas(100,100); + textAlign(CENTER); + + fft = new p5.FFT(); + peakDetect = new p5.PeakDetect(); + + setupSound(); + + // when a beat is detected, call triggerBeat() + peakDetect.onPeak(triggerBeat); + } + + function draw() { + background(0); + fill(255); + text('click to play', width/2, height/2); + + fft.analyze(); + peakDetect.update(fft); + + ellipseWidth *= 0.95; + ellipse(width/2, height/2, ellipseWidth, ellipseWidth); + } + + // this function is called by peakDetect.onPeak + function triggerBeat() { + ellipseWidth = 50; + } + + // mouseclick starts/stops sound + function setupSound() { + cnv.mouseClicked( function() { + if (soundFile.isPlaying() ) { + soundFile.stop(); + } else { + soundFile.play(); + } + }); + } +
+chainable: false +--- + + +# onPeak diff --git a/src/content/reference/en/p5.PeakDetect/update.mdx b/src/content/reference/en/p5.PeakDetect/update.mdx new file mode 100644 index 0000000000..0d9912a002 --- /dev/null +++ b/src/content/reference/en/p5.PeakDetect/update.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: update +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

The update method is run in the draw loop.

+

Accepts an FFT object. You must call .analyze() + on the FFT object prior to updating the peakDetect + because it relies on a completed FFT analysis.

+line: 10432 +params: + - name: fftObject + description: | +

A p5.FFT object

+ type: p5.FFT +itemtype: method +class: p5.PeakDetect +chainable: false +--- + + +# update diff --git a/src/content/reference/en/p5.Phrase/sequence.mdx b/src/content/reference/en/p5.Phrase/sequence.mdx new file mode 100644 index 0000000000..6d32605a08 --- /dev/null +++ b/src/content/reference/en/p5.Phrase/sequence.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sequence +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Array of values to pass into the callback + at each step of the phrase. Depending on the callback + function's requirements, these values may be numbers, + strings, or an object with multiple parameters. + Zero (0) indicates a rest.

+line: 9173 +itemtype: property +class: p5.Phrase +chainable: false +--- + + +# sequence diff --git a/src/content/reference/en/p5.PolySynth/AudioVoice.mdx b/src/content/reference/en/p5.PolySynth/AudioVoice.mdx new file mode 100644 index 0000000000..640b67d0e6 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/AudioVoice.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: AudioVoice +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Monosynth that generates the sound for each note that is triggered. The + p5.PolySynth defaults to using the p5.MonoSynth as its voice.

+line: 11761 +itemtype: property +class: p5.PolySynth +chainable: false +--- + + +# AudioVoice diff --git a/src/content/reference/en/p5.PolySynth/connect.mdx b/src/content/reference/en/p5.PolySynth/connect.mdx new file mode 100644 index 0000000000..ee13491044 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/connect.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect to a p5.sound / Web Audio object.

+line: 12105 +params: + - name: unit + description: | +

A p5.sound or Web Audio object

+ type: Object +itemtype: method +class: p5.PolySynth +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.PolySynth/disconnect.mdx b/src/content/reference/en/p5.PolySynth/disconnect.mdx new file mode 100644 index 0000000000..2c0d369adf --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all outputs

+line: 12119 +itemtype: method +class: p5.PolySynth +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.PolySynth/dispose.mdx b/src/content/reference/en/p5.PolySynth/dispose.mdx new file mode 100644 index 0000000000..19bdb8ee14 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/dispose.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dispose +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Get rid of the MonoSynth and free up its resources / memory.

+line: 12133 +itemtype: method +class: p5.PolySynth +chainable: false +--- + + +# dispose diff --git a/src/content/reference/en/p5.PolySynth/noteADSR.mdx b/src/content/reference/en/p5.PolySynth/noteADSR.mdx new file mode 100644 index 0000000000..c79dc38379 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/noteADSR.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noteADSR +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

noteADSR sets the envelope for a specific note that has just been + triggered. + + Using this method modifies the envelope of whichever audiovoice is being used + + to play the desired note. The envelope should be reset before noteRelease is + called + + in order to prevent the modified envelope from being used on other notes.

+line: 11849 +params: + - name: note + description: | +

Midi note on which ADSR should be set.

+ type: Number + optional: true + - name: attackTime + description: | +

Time (in seconds before envelope + reaches Attack Level

+ type: Number + optional: true + - name: decayTime + description: | +

Time (in seconds) before envelope + reaches Decay/Sustain Level

+ type: Number + optional: true + - name: susRatio + description: | +

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1, + where 1.0 = attackLevel, 0.0 = releaseLevel. + The susRatio determines the decayLevel and the level at which the + sustain portion of the envelope will sustain. + For example, if attackLevel is 0.4, releaseLevel is 0, + and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is + increased to 1.0 (using setRange), + then decayLevel would increase proportionally, to become 0.5.

+ type: Number + optional: true + - name: releaseTime + description: | +

Time in seconds from now (defaults to 0)

+ type: Number + optional: true +itemtype: method +class: p5.PolySynth +chainable: false +--- + + +# noteADSR diff --git a/src/content/reference/en/p5.PolySynth/noteAttack.mdx b/src/content/reference/en/p5.PolySynth/noteAttack.mdx new file mode 100644 index 0000000000..d0970ed46e --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/noteAttack.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noteAttack +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the Attack, and Decay portion of a MonoSynth. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go.

+line: 11909 +params: + - name: note + description: | +

midi note on which attack should be triggered.

+ type: Number + optional: true + - name: velocity + description: | +

velocity of the note to play (ranging from 0 to 1)/

+ type: Number + optional: true + - name: secondsFromNow + description: | +

time from now (in seconds)

+ type: Number + optional: true +itemtype: method +class: p5.PolySynth +example: + - |- + +
+ let polySynth = new p5.PolySynth(); + let pitches = ['G', 'D', 'G', 'C']; + let octaves = [2, 3, 4]; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playChord); + background(220); + text('tap to play', 20, 20); + } + + function playChord() { + userStartAudio(); + + // play a chord: multiple notes at the same time + for (let i = 0; i < 4; i++) { + let note = random(pitches) + random(octaves); + polySynth.noteAttack(note, 0.1); + } + } + + function mouseReleased() { + // release all voices + polySynth.noteRelease(); + } +
+chainable: false +--- + + +# noteAttack diff --git a/src/content/reference/en/p5.PolySynth/noteRelease.mdx b/src/content/reference/en/p5.PolySynth/noteRelease.mdx new file mode 100644 index 0000000000..0cbbfbf546 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/noteRelease.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noteRelease +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Trigger the Release of an AudioVoice note. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+line: 12021 +params: + - name: note + description: | +

midi note on which attack should be triggered. + If no value is provided, all notes will be released.

+ type: Number + optional: true + - name: secondsFromNow + description: | +

time to trigger the release

+ type: Number + optional: true +itemtype: method +class: p5.PolySynth +example: + - | + +
+ let polySynth = new p5.PolySynth(); + let pitches = ['G', 'D', 'G', 'C']; + let octaves = [2, 3, 4]; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playChord); + background(220); + text('tap to play', 20, 20); + } + + function playChord() { + userStartAudio(); + + // play a chord: multiple notes at the same time + for (let i = 0; i < 4; i++) { + let note = random(pitches) + random(octaves); + polySynth.noteAttack(note, 0.1); + } + } + + function mouseReleased() { + // release all voices + polySynth.noteRelease(); + } +
+chainable: false +--- + + +# noteRelease diff --git a/src/content/reference/en/p5.PolySynth/notes.mdx b/src/content/reference/en/p5.PolySynth/notes.mdx new file mode 100644 index 0000000000..5d94769bed --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/notes.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: notes +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

An object that holds information about which notes have been played and + which notes are currently being played. New notes are added as keys + on the fly. While a note has been attacked, but not released, the value of the + key is the audiovoice which is generating that note. When notes are released, + the value of the key becomes undefined.

+line: 11742 +itemtype: property +class: p5.PolySynth +chainable: false +--- + + +# notes diff --git a/src/content/reference/en/p5.PolySynth/play.mdx b/src/content/reference/en/p5.PolySynth/play.mdx new file mode 100644 index 0000000000..6652f7843e --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/play.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Play a note by triggering noteAttack and noteRelease with sustain time

+line: 11800 +params: + - name: note + description: | +

midi note to play (ranging from 0 to 127 - 60 being a middle C)

+ type: Number + optional: true + - name: velocity + description: | +

velocity of the note to play (ranging from 0 to 1)

+ type: Number + optional: true + - name: secondsFromNow + description: | +

time from now (in seconds) at which to play

+ type: Number + optional: true + - name: sustainTime + description: | +

time to sustain before releasing the envelope

+ type: Number + optional: true +itemtype: method +class: p5.PolySynth +example: + - |- + +
+ let polySynth; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playSynth); + background(220); + text('click to play', 20, 20); + + polySynth = new p5.PolySynth(); + } + + function playSynth() { + userStartAudio(); + + // note duration (in seconds) + let dur = 1.5; + + // time from now (in seconds) + let time = 0; + + // velocity (volume, from 0 to 1) + let vel = 0.1; + + // notes can overlap with each other + polySynth.play('G2', vel, 0, dur); + polySynth.play('C3', vel, time += 1/3, dur); + polySynth.play('G3', vel, time += 1/3, dur); + } +
+chainable: false +--- + + +# play diff --git a/src/content/reference/en/p5.PolySynth/polyvalue.mdx b/src/content/reference/en/p5.PolySynth/polyvalue.mdx new file mode 100644 index 0000000000..f66dd286a8 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/polyvalue.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: polyvalue +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

A PolySynth must have at least 1 voice, defaults to 8

+line: 11755 +itemtype: property +class: p5.PolySynth +chainable: false +--- + + +# polyvalue diff --git a/src/content/reference/en/p5.PolySynth/setADSR.mdx b/src/content/reference/en/p5.PolySynth/setADSR.mdx new file mode 100644 index 0000000000..b180ab5811 --- /dev/null +++ b/src/content/reference/en/p5.PolySynth/setADSR.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setADSR +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Set the PolySynths global envelope. This method modifies the envelopes of + each + + monosynth so that all notes are played with this envelope.

+line: 11881 +params: + - name: attackTime + description: | +

Time (in seconds before envelope + reaches Attack Level

+ type: Number + optional: true + - name: decayTime + description: | +

Time (in seconds) before envelope + reaches Decay/Sustain Level

+ type: Number + optional: true + - name: susRatio + description: | +

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1, + where 1.0 = attackLevel, 0.0 = releaseLevel. + The susRatio determines the decayLevel and the level at which the + sustain portion of the envelope will sustain. + For example, if attackLevel is 0.4, releaseLevel is 0, + and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is + increased to 1.0 (using setRange), + then decayLevel would increase proportionally, to become 0.5.

+ type: Number + optional: true + - name: releaseTime + description: | +

Time in seconds from now (defaults to 0)

+ type: Number + optional: true +itemtype: method +class: p5.PolySynth +chainable: false +--- + + +# setADSR diff --git a/src/content/reference/en/p5.PrintWriter/clear.mdx b/src/content/reference/en/p5.PrintWriter/clear.mdx new file mode 100644 index 0000000000..f2f369b50e --- /dev/null +++ b/src/content/reference/en/p5.PrintWriter/clear.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clear +module: IO +submodule: Output +file: src/io/files.js +description: | +

Clears the data already written to the PrintWriter object

+line: 1298 +itemtype: method +class: p5.PrintWriter +example: + - | + +
+ // create writer object + let writer = createWriter('newFile.txt'); + writer.write(['clear me']); + // clear writer object here + writer.clear(); + // close writer + writer.close(); +
+
+ + function setup() { + button = createButton('CLEAR ME'); + button.position(21, 40); + button.mousePressed(createFile); + } + + function createFile() { + let writer = createWriter('newFile.txt'); + writer.write(['clear me']); + writer.clear(); + writer.close(); + } + +
+chainable: false +--- + + +# clear diff --git a/src/content/reference/en/p5.PrintWriter/close.mdx b/src/content/reference/en/p5.PrintWriter/close.mdx new file mode 100644 index 0000000000..bcfdf118b8 --- /dev/null +++ b/src/content/reference/en/p5.PrintWriter/close.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: close +module: IO +submodule: Output +file: src/io/files.js +description: | +

Closes the PrintWriter

+line: 1332 +itemtype: method +class: p5.PrintWriter +example: + - |- + +
+ + // create a file called 'newFile.txt' + let writer = createWriter('newFile.txt'); + // close the PrintWriter and save the file + writer.close(); + +
+
+ + // create a file called 'newFile2.txt' + let writer = createWriter('newFile2.txt'); + // write some data to the file + writer.write([100, 101, 102]); + // close the PrintWriter and save the file + writer.close(); + +
+chainable: false +--- + + +# close diff --git a/src/content/reference/en/p5.PrintWriter/print.mdx b/src/content/reference/en/p5.PrintWriter/print.mdx new file mode 100644 index 0000000000..0ef9becd9b --- /dev/null +++ b/src/content/reference/en/p5.PrintWriter/print.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: print +module: IO +submodule: Output +file: src/io/files.js +description: | +

Writes data to the PrintWriter stream, and adds a new line at the end

+line: 1257 +params: + - name: data + description: | +

all data to be printed by the PrintWriter

+ type: Array +itemtype: method +class: p5.PrintWriter +example: + - |- + +
+ + // creates a file called 'newFile.txt' + let writer = createWriter('newFile.txt'); + // creates a file containing + // My name is: + // Teddy + writer.print('My name is:'); + writer.print('Teddy'); + // close the PrintWriter and save the file + writer.close(); + +
+
+ + let writer; + + function setup() { + createCanvas(400, 400); + // create a PrintWriter + writer = createWriter('newFile.txt'); + } + + function draw() { + writer.print([mouseX, mouseY]); + } + + function mouseClicked() { + writer.close(); + } + +
+chainable: false +--- + + +# print diff --git a/src/content/reference/en/p5.PrintWriter/write.mdx b/src/content/reference/en/p5.PrintWriter/write.mdx new file mode 100644 index 0000000000..7730ea4ba1 --- /dev/null +++ b/src/content/reference/en/p5.PrintWriter/write.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: write +module: IO +submodule: Output +file: src/io/files.js +description: | +

Writes data to the PrintWriter stream

+line: 1198 +params: + - name: data + description: | +

all data to be written by the PrintWriter

+ type: Array +itemtype: method +class: p5.PrintWriter +example: + - |- + +
+ + // creates a file called 'newFile.txt' + let writer = createWriter('newFile.txt'); + // write 'Hello world!'' to the file + writer.write(['Hello world!']); + // close the PrintWriter and save the file + writer.close(); + +
+
+ + // creates a file called 'newFile2.txt' + let writer = createWriter('newFile2.txt'); + // write 'apples,bananas,123' to the file + writer.write(['apples', 'bananas', 123]); + // close the PrintWriter and save the file + writer.close(); + +
+
+ + // creates a file called 'newFile3.txt' + let writer = createWriter('newFile3.txt'); + // write 'My name is: Teddy' to the file + writer.write('My name is:'); + writer.write(' Teddy'); + // close the PrintWriter and save the file + writer.close(); + +
+
+ + function setup() { + createCanvas(100, 100); + button = createButton('SAVE FILE'); + button.position(21, 40); + button.mousePressed(createFile); + } + + function createFile() { + // creates a file called 'newFile.txt' + let writer = createWriter('newFile.txt'); + // write 'Hello world!'' to the file + writer.write(['Hello world!']); + // close the PrintWriter and save the file + writer.close(); + } + +
+chainable: false +--- + + +# write diff --git a/src/content/reference/en/p5.Pulse/width.mdx b/src/content/reference/en/p5.Pulse/width.mdx new file mode 100644 index 0000000000..22a4babb42 --- /dev/null +++ b/src/content/reference/en/p5.Pulse/width.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: width +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the width of a Pulse object (an oscillator that implements + Pulse Width Modulation).

+line: 5871 +params: + - name: width + description: | +

Width between the pulses (0 to 1.0, + defaults to 0)

+ type: Number + optional: true +itemtype: method +class: p5.Pulse +chainable: false +--- + + +# width diff --git a/src/content/reference/en/p5.Reverb/amp.mdx b/src/content/reference/en/p5.Reverb/amp.mdx new file mode 100644 index 0000000000..ec28c2581b --- /dev/null +++ b/src/content/reference/en/p5.Reverb/amp.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: amp +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the output level of the reverb effect.

+line: 8482 +params: + - name: volume + description: | +

amplitude between 0 and 1.0

+ type: Number + - name: rampTime + description: | +

create a fade that lasts rampTime

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.Reverb +chainable: false +--- + + +# amp diff --git a/src/content/reference/en/p5.Reverb/connect.mdx b/src/content/reference/en/p5.Reverb/connect.mdx new file mode 100644 index 0000000000..13119bad10 --- /dev/null +++ b/src/content/reference/en/p5.Reverb/connect.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Send output to a p5.sound or web audio object

+line: 8493 +params: + - name: unit + description: '' + type: Object +itemtype: method +class: p5.Reverb +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.Reverb/disconnect.mdx b/src/content/reference/en/p5.Reverb/disconnect.mdx new file mode 100644 index 0000000000..f4436541fa --- /dev/null +++ b/src/content/reference/en/p5.Reverb/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnect all output.

+line: 8501 +itemtype: method +class: p5.Reverb +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.Reverb/process.mdx b/src/content/reference/en/p5.Reverb/process.mdx new file mode 100644 index 0000000000..49cde55535 --- /dev/null +++ b/src/content/reference/en/p5.Reverb/process.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: process +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect a source to the reverb, and assign reverb parameters.

+line: 8409 +params: + - name: src + description: | +

p5.sound / Web Audio object with a sound + output.

+ type: Object + - name: seconds + description: | +

Duration of the reverb, in seconds. + Min: 0, Max: 10. Defaults to 3.

+ type: Number + optional: true + - name: decayRate + description: | +

Percentage of decay with each echo. + Min: 0, Max: 100. Defaults to 2.

+ type: Number + optional: true + - name: reverse + description: | +

Play the reverb backwards or forwards.

+ type: Boolean + optional: true +itemtype: method +class: p5.Reverb +chainable: false +--- + + +# process diff --git a/src/content/reference/en/p5.Reverb/set.mdx b/src/content/reference/en/p5.Reverb/set.mdx new file mode 100644 index 0000000000..5b7f20ffc5 --- /dev/null +++ b/src/content/reference/en/p5.Reverb/set.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the reverb settings. Similar to .process(), but without + assigning a new input.

+line: 8446 +params: + - name: seconds + description: | +

Duration of the reverb, in seconds. + Min: 0, Max: 10. Defaults to 3.

+ type: Number + optional: true + - name: decayRate + description: | +

Percentage of decay with each echo. + Min: 0, Max: 100. Defaults to 2.

+ type: Number + optional: true + - name: reverse + description: | +

Play the reverb backwards or forwards.

+ type: Boolean + optional: true +itemtype: method +class: p5.Reverb +chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Score/loop.mdx b/src/content/reference/en/p5.Score/loop.mdx new file mode 100644 index 0000000000..a1ce74d355 --- /dev/null +++ b/src/content/reference/en/p5.Score/loop.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Loop playback of the score.

+line: 9581 +itemtype: method +class: p5.Score +chainable: false +--- + + +# loop diff --git a/src/content/reference/en/p5.Score/noLoop.mdx b/src/content/reference/en/p5.Score/noLoop.mdx new file mode 100644 index 0000000000..1f9da92a84 --- /dev/null +++ b/src/content/reference/en/p5.Score/noLoop.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noLoop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop looping playback of the score. If it + is currently playing, this will go into effect + after the current round of playback completes.

+line: 9594 +itemtype: method +class: p5.Score +chainable: false +--- + + +# noLoop diff --git a/src/content/reference/en/p5.Score/pause.mdx b/src/content/reference/en/p5.Score/pause.mdx new file mode 100644 index 0000000000..ddba62772d --- /dev/null +++ b/src/content/reference/en/p5.Score/pause.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Pause playback of the score.

+line: 9569 +itemtype: method +class: p5.Score +chainable: false +--- + + +# pause diff --git a/src/content/reference/en/p5.Score/setBPM.mdx b/src/content/reference/en/p5.Score/setBPM.mdx new file mode 100644 index 0000000000..1c60a12299 --- /dev/null +++ b/src/content/reference/en/p5.Score/setBPM.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setBPM +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the tempo for all parts in the score

+line: 9628 +params: + - name: BPM + description: | +

Beats Per Minute

+ type: Number + - name: rampTime + description: | +

Seconds from now

+ type: Number +itemtype: method +class: p5.Score +chainable: false +--- + + +# setBPM diff --git a/src/content/reference/en/p5.Score/start.mdx b/src/content/reference/en/p5.Score/start.mdx new file mode 100644 index 0000000000..4dcba9dc6e --- /dev/null +++ b/src/content/reference/en/p5.Score/start.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: start +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start playback of the score.

+line: 9542 +itemtype: method +class: p5.Score +chainable: false +--- + + +# start diff --git a/src/content/reference/en/p5.Score/stop.mdx b/src/content/reference/en/p5.Score/stop.mdx new file mode 100644 index 0000000000..2df491c1ce --- /dev/null +++ b/src/content/reference/en/p5.Score/stop.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop playback of the score.

+line: 9555 +itemtype: method +class: p5.Score +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.Shader/copyToContext.mdx b/src/content/reference/en/p5.Shader/copyToContext.mdx new file mode 100644 index 0000000000..f0ed381a8c --- /dev/null +++ b/src/content/reference/en/p5.Shader/copyToContext.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: copyToContext +module: 3D +submodule: Material +file: src/webgl/p5.Shader.js +description: | +

Shaders belong to the main canvas or a p5.Graphics. Once they are compiled, + they can only be used in the context they were compiled on.

+

Use this method to make a new copy of a shader that gets compiled on a + different context.

+line: 106 +params: + - name: context + description: | +

The graphic or instance to copy this shader to. + Pass window if you need to copy to the main canvas.

+ type: p5|p5.Graphics +itemtype: method +class: p5.Shader +example: + - |- + +
+ + let graphic = createGraphics(200, 200, WEBGL); + let graphicShader = graphic.createShader(vert, frag); + graphic.shader(graphicShader); // Use graphicShader on the graphic + + let mainShader = graphicShader.copyToContext(window); + shader(mainShader); // Use `mainShader` on the main canvas + +
+return: + description: A new shader on the target context. + type: p5.Shader +chainable: false +--- + + +# copyToContext diff --git a/src/content/reference/en/p5.Shader/setUniform.mdx b/src/content/reference/en/p5.Shader/setUniform.mdx new file mode 100644 index 0000000000..56f85f5090 --- /dev/null +++ b/src/content/reference/en/p5.Shader/setUniform.mdx @@ -0,0 +1,133 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setUniform +module: 3D +submodule: Material +file: src/webgl/p5.Shader.js +description: > +

Used to set the uniforms of a + + p5.Shader object.

+ +

Uniforms are used as a way to provide shader programs + + (which run on the GPU) with values from a sketch + + (which runs on the CPU).

+ +

Here are some examples of uniforms you can make:

+ + +line: 367 +params: + - name: uniformName + description: | +

the name of the uniform. + Must correspond to the name used in the vertex and fragment shaders

+ type: String + - name: data + description: | +

The value to assign to the uniform. This can be + a boolean (true/false), a number, an array of numbers, or + an image (p5.Image, p5.Graphics, p5.MediaElement, p5.Texture)

+ type: 'Boolean|Number|Number[]|p5.Image|p5.Graphics|p5.MediaElement|p5.Texture' +itemtype: method +class: p5.Shader +example: + - |- + +
+ + // Click within the image to toggle the value of uniforms + // Note: for an alternative approach to the same example, + // involving toggling between shaders please refer to: + // https://p5js.org/reference/#/p5/shader + + let grad; + let showRedGreen = false; + + function preload() { + // note that we are using two instances + // of the same vertex and fragment shaders + grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + shader(grad); + noStroke(); + + describe( + 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.' + ); + } + + function draw() { + // update the offset values for each scenario, + // moving the "grad" shader in either vertical or + // horizontal direction each with differing colors + + if (showRedGreen === true) { + grad.setUniform('colorCenter', [1, 0, 0]); + grad.setUniform('colorBackground', [0, 1, 0]); + grad.setUniform('offset', [sin(millis() / 2000), 1]); + } else { + grad.setUniform('colorCenter', [1, 0.5, 0]); + grad.setUniform('colorBackground', [0.226, 0, 0.615]); + grad.setUniform('offset', [0, sin(millis() / 2000) + 1]); + } + quad(-1, -1, 1, -1, 1, 1, -1, 1); + } + + function mouseClicked() { + showRedGreen = !showRedGreen; + } + +
+alt: >- + canvas toggles between a circular gradient of orange and blue vertically. and + a circular gradient of red and green moving horizontally when mouse is + clicked/pressed. +chainable: true +--- + + +# setUniform diff --git a/src/content/reference/en/p5.SoundFile/addCue.mdx b/src/content/reference/en/p5.SoundFile/addCue.mdx new file mode 100644 index 0000000000..5b9cda6d35 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/addCue.mdx @@ -0,0 +1,82 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addCue +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Schedule events to trigger every time a MediaElement + (audio/video) reaches a playback cue point.

+

Accepts a callback function, a time (in seconds) at which to trigger + the callback, and an optional parameter for the callback.

+

Time will be passed as the first parameter to the callback function, + and param will be the second parameter.

+line: 2719 +params: + - name: time + description: | +

Time in seconds, relative to this media + element's playback. For example, to trigger + an event every time playback reaches two + seconds, pass in the number 2. This will be + passed as the first parameter to + the callback function.

+ type: Number + - name: callback + description: | +

Name of a function that will be + called at the given time. The callback will + receive time and (optionally) param as its + two parameters.

+ type: Function + - name: value + description: | +

An object to be passed as the + second parameter to the + callback function.

+ type: Object + optional: true +itemtype: method +class: p5.SoundFile +example: + - |- + +
+ let mySound; + function preload() { + mySound = loadSound('assets/Damscray_DancingTiger.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap to play', 10, 20); + + // schedule calls to changeText + mySound.addCue(0, changeText, "hello" ); + mySound.addCue(0.5, changeText, "hello," ); + mySound.addCue(1, changeText, "hello, p5!"); + mySound.addCue(1.5, changeText, "hello, p5!!"); + mySound.addCue(2, changeText, "hello, p5!!!!!"); + } + + function changeText(val) { + background(220); + text(val, 10, 20); + } + + function canvasPressed() { + mySound.play(); + } +
+return: + description: |- + id ID of this cue, + useful for removeCue(id) + type: Number +chainable: false +--- + + +# addCue diff --git a/src/content/reference/en/p5.SoundFile/channels.mdx b/src/content/reference/en/p5.SoundFile/channels.mdx new file mode 100644 index 0000000000..af05b0dc74 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/channels.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: channels +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the number of channels in a sound file. + For example, Mono = 1, Stereo = 2.

+line: 2340 +itemtype: method +class: p5.SoundFile +return: + description: '[channels]' + type: Number +chainable: false +--- + + +# channels diff --git a/src/content/reference/en/p5.SoundFile/clearCues.mdx b/src/content/reference/en/p5.SoundFile/clearCues.mdx new file mode 100644 index 0000000000..173016acec --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/clearCues.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearCues +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Remove all of the callbacks that had originally been scheduled + via the addCue method.

+line: 2817 +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# clearCues diff --git a/src/content/reference/en/p5.SoundFile/connect.mdx b/src/content/reference/en/p5.SoundFile/connect.mdx new file mode 100644 index 0000000000..5538f16b3f --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/connect.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: connect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connects the output of a p5sound object to input of another + p5.sound object. For example, you may connect a p5.SoundFile to an + FFT or an Effect. If no parameter is given, it will connect to + the main output. Most p5sound objects connect to the master + output when they are created.

+line: 2565 +params: + - name: object + description: | +

Audio object that accepts an input

+ type: Object + optional: true +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# connect diff --git a/src/content/reference/en/p5.SoundFile/currentTime.mdx b/src/content/reference/en/p5.SoundFile/currentTime.mdx new file mode 100644 index 0000000000..93d9f45983 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/currentTime.mdx @@ -0,0 +1,24 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: currentTime +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Return the current position of the p5.SoundFile playhead, in seconds. + + Time is relative to the normal buffer direction, so if + reverseBuffer + + has been called, currentTime will count backwards.

+line: 2293 +itemtype: method +class: p5.SoundFile +return: + description: currentTime of the soundFile in seconds. + type: Number +chainable: false +--- + + +# currentTime diff --git a/src/content/reference/en/p5.SoundFile/disconnect.mdx b/src/content/reference/en/p5.SoundFile/disconnect.mdx new file mode 100644 index 0000000000..f2f08061ed --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/disconnect.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disconnect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Disconnects the output of this p5sound object.

+line: 2590 +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# disconnect diff --git a/src/content/reference/en/p5.SoundFile/duration.mdx b/src/content/reference/en/p5.SoundFile/duration.mdx new file mode 100644 index 0000000000..3b74440f3b --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/duration.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: duration +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the duration of a sound file in seconds.

+line: 2276 +itemtype: method +class: p5.SoundFile +return: + description: The duration of the soundFile in seconds. + type: Number +chainable: false +--- + + +# duration diff --git a/src/content/reference/en/p5.SoundFile/frames.mdx b/src/content/reference/en/p5.SoundFile/frames.mdx new file mode 100644 index 0000000000..5f3bd9fc89 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/frames.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: frames +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the number of samples in a sound file. + Equal to sampleRate * duration.

+line: 2367 +itemtype: method +class: p5.SoundFile +return: + description: '[sampleCount]' + type: Number +chainable: false +--- + + +# frames diff --git a/src/content/reference/en/p5.SoundFile/getBlob.mdx b/src/content/reference/en/p5.SoundFile/getBlob.mdx new file mode 100644 index 0000000000..9617c1a955 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/getBlob.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getBlob +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

This method is useful for sending a SoundFile to a server. It returns the + .wav-encoded audio data as a "Blob". + A Blob is a file-like data object that can be uploaded to a server + with an http request. We'll + use the httpDo options object to send a POST request with some + specific options: we encode the request as multipart/form-data, + and attach the blob as one of the form values using FormData.

+line: 2882 +itemtype: method +class: p5.SoundFile +example: + - |2- + +
+ function preload() { + mySound = loadSound('assets/doorbell.mp3'); + } + + function setup() { + noCanvas(); + let soundBlob = mySound.getBlob(); + + // Now we can send the blob to a server... + let serverUrl = 'https://jsonplaceholder.typicode.com/posts'; + let httpRequestOptions = { + method: 'POST', + body: new FormData().append('soundBlob', soundBlob), + headers: new Headers({ + 'Content-Type': 'multipart/form-data' + }) + }; + httpDo(serverUrl, httpRequestOptions); + + // We can also create an `ObjectURL` pointing to the Blob + let blobUrl = URL.createObjectURL(soundBlob); + + // The `
+return: + description: A file-like data object + type: Blob +chainable: false +--- + + +# getBlob diff --git a/src/content/reference/en/p5.SoundFile/getPan.mdx b/src/content/reference/en/p5.SoundFile/getPan.mdx new file mode 100644 index 0000000000..14bda2f61e --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/getPan.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getPan +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the current stereo pan position (-1.0 to 1.0)

+line: 2131 +itemtype: method +class: p5.SoundFile +return: + description: |- + Returns the stereo pan setting of the Oscillator + as a number between -1.0 (left) and 1.0 (right). + 0.0 is center and default. + type: Number +chainable: false +--- + + +# getPan diff --git a/src/content/reference/en/p5.SoundFile/getPeaks.mdx b/src/content/reference/en/p5.SoundFile/getPeaks.mdx new file mode 100644 index 0000000000..627933c6b7 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/getPeaks.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getPeaks +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns an array of amplitude peaks in a p5.SoundFile that can be + used to draw a static waveform. Scans through the p5.SoundFile's + audio buffer to find the greatest amplitudes. Accepts one + parameter, 'length', which determines size of the array. + Larger arrays result in more precise waveform visualizations.

+

Inspired by Wavesurfer.js.

+line: 2381 +params: + - name: length + description: | +

length is the size of the returned array. + Larger length results in more precision. + Defaults to 5*width of the browser window.

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +return: + description: Array of peaks. + type: Float32Array +chainable: false +--- + + +# getPeaks diff --git a/src/content/reference/en/p5.SoundFile/isLoaded.mdx b/src/content/reference/en/p5.SoundFile/isLoaded.mdx new file mode 100644 index 0000000000..8d6d21f26d --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/isLoaded.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isLoaded +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns true if the sound file finished loading successfully.

+line: 1662 +itemtype: method +class: p5.SoundFile +return: + description: '' + type: Boolean +chainable: false +--- + + +# isLoaded diff --git a/src/content/reference/en/p5.SoundFile/isLooping.mdx b/src/content/reference/en/p5.SoundFile/isLooping.mdx new file mode 100644 index 0000000000..18f2714e25 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/isLooping.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isLooping +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Returns 'true' if a p5.SoundFile is currently looping and playing, 'false' + if not.

+line: 1976 +itemtype: method +class: p5.SoundFile +return: + description: '' + type: Boolean +chainable: false +--- + + +# isLooping diff --git a/src/content/reference/en/p5.SoundFile/isPaused.mdx b/src/content/reference/en/p5.SoundFile/isPaused.mdx new file mode 100644 index 0000000000..96ef7a3143 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/isPaused.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isPaused +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns true if a p5.SoundFile is paused, false if not (i.e. + playing or stopped).

+line: 2011 +itemtype: method +class: p5.SoundFile +return: + description: '' + type: Boolean +chainable: false +--- + + +# isPaused diff --git a/src/content/reference/en/p5.SoundFile/isPlaying.mdx b/src/content/reference/en/p5.SoundFile/isPlaying.mdx new file mode 100644 index 0000000000..f273927a14 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/isPlaying.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isPlaying +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns true if a p5.SoundFile is playing, false if not (i.e. + paused or stopped).

+line: 1997 +itemtype: method +class: p5.SoundFile +return: + description: '' + type: Boolean +chainable: false +--- + + +# isPlaying diff --git a/src/content/reference/en/p5.SoundFile/jump.mdx b/src/content/reference/en/p5.SoundFile/jump.mdx new file mode 100644 index 0000000000..10b7d7e6e5 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/jump.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: jump +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Move the playhead of a soundfile that is currently playing to a + + new position and a new duration, in seconds. + + If none are given, will reset the file to play entire duration + + from start to finish. To set the position of a soundfile that is + + not currently playing, use the play or loop + methods.

+line: 2308 +params: + - name: cueTime + description: | +

cueTime of the soundFile in seconds.

+ type: Number + - name: duration + description: | +

duration in seconds.

+ type: Number +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# jump diff --git a/src/content/reference/en/p5.SoundFile/loop.mdx b/src/content/reference/en/p5.SoundFile/loop.mdx new file mode 100644 index 0000000000..307564235f --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/loop.mdx @@ -0,0 +1,71 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Loop the p5.SoundFile. Accepts optional parameters to set the + playback rate, playback volume, loopStart, loopEnd.

+line: 1905 +params: + - name: startTime + description: | +

(optional) schedule event to occur + seconds from now

+ type: Number + optional: true + - name: rate + description: | +

(optional) playback rate

+ type: Number + optional: true + - name: amp + description: | +

(optional) playback volume

+ type: Number + optional: true + - name: cueLoopStart + description: | +

(optional) startTime in seconds

+ type: Number + optional: true + - name: duration + description: | +

(optional) loop duration in seconds

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +example: + - |2- + +
+ let soundFile; + let loopStart = 0.5; + let loopDuration = 0.2; + function preload() { + soundFormats('ogg', 'mp3'); + soundFile = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3'); + } + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap to play, release to pause', 10, 20, width - 20); + } + function canvasPressed() { + soundFile.loop(); + background(0, 200, 50); + } + function mouseReleased() { + soundFile.pause(); + background(220); + } + +
+chainable: false +--- + + +# loop diff --git a/src/content/reference/en/p5.SoundFile/onended.mdx b/src/content/reference/en/p5.SoundFile/onended.mdx new file mode 100644 index 0000000000..1839c65d73 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/onended.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: onended +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Schedule an event to be called when the soundfile + reaches the end of a buffer. If the soundfile is + playing through once, this will be called when it + ends. If it is looping, it will be called when + stop is called.

+line: 2497 +params: + - name: callback + description: | +

function to call when the + soundfile has ended.

+ type: Function +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# onended diff --git a/src/content/reference/en/p5.SoundFile/pan.mdx b/src/content/reference/en/p5.SoundFile/pan.mdx new file mode 100644 index 0000000000..b8a81a4d72 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/pan.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pan +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the stereo panning of a p5.sound object to + a floating point number between -1.0 (left) and 1.0 (right). + Default is 0.0 (center).

+line: 2087 +params: + - name: panValue + description: | +

Set the stereo panner

+ type: Number + optional: true + - name: timeFromNow + description: | +

schedule this event to happen + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +example: + - |- + +
+ let ballX = 0; + let soundFile; + + function preload() { + soundFormats('ogg', 'mp3'); + soundFile = loadSound('assets/beatbox.mp3'); + } + + function draw() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + ballX = constrain(mouseX, 0, width); + ellipse(ballX, height/2, 20, 20); + } + + function canvasPressed(){ + // map the ball's x location to a panning degree + // between -1.0 (left) and 1.0 (right) + let panning = map(ballX, 0., width,-1.0, 1.0); + soundFile.pan(panning); + soundFile.play(); + } +
+chainable: false +--- + + +# pan diff --git a/src/content/reference/en/p5.SoundFile/pause.mdx b/src/content/reference/en/p5.SoundFile/pause.mdx new file mode 100644 index 0000000000..c0fb2e0542 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/pause.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Pauses a file that is currently playing. If the file is not + playing, then nothing will happen.

+

After pausing, .play() will resume from the paused + position. + If p5.SoundFile had been set to loop before it was paused, + it will continue to loop after it is unpaused with .play().

+line: 1847 +params: + - name: startTime + description: | +

(optional) schedule event to occur + seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +example: + - |- + +
+ let soundFile; + function preload() { + soundFormats('ogg', 'mp3'); + soundFile = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3'); + } + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap to play, release to pause', 10, 20, width - 20); + } + function canvasPressed() { + soundFile.loop(); + background(0, 200, 50); + } + function mouseReleased() { + soundFile.pause(); + background(220); + } + +
+chainable: false +--- + + +# pause diff --git a/src/content/reference/en/p5.SoundFile/play.mdx b/src/content/reference/en/p5.SoundFile/play.mdx new file mode 100644 index 0000000000..d41cee1f1e --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/play.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: play +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Play the p5.SoundFile

+line: 1679 +params: + - name: startTime + description: | +

(optional) schedule playback to start (in seconds from now).

+ type: Number + optional: true + - name: rate + description: | +

(optional) playback rate

+ type: Number + optional: true + - name: amp + description: | +

(optional) amplitude (volume) + of playback

+ type: Number + optional: true + - name: cueStart + description: | +

(optional) cue start time in seconds

+ type: Number + optional: true + - name: duration + description: | +

(optional) duration of playback in seconds

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# play diff --git a/src/content/reference/en/p5.SoundFile/playMode.mdx b/src/content/reference/en/p5.SoundFile/playMode.mdx new file mode 100644 index 0000000000..9068a4ee12 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/playMode.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: playMode +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

p5.SoundFile has two play modes: restart and + sustain. Play Mode determines what happens to a + p5.SoundFile if it is triggered while in the middle of playback. + In sustain mode, playback will continue simultaneous to the + new playback. In restart mode, play() will stop playback + and start over. With untilDone, a sound will play only if it's + not already playing. Sustain is the default mode.

+line: 1787 +params: + - name: str + description: | +

'restart' or 'sustain' or 'untilDone'

+ type: String +itemtype: method +class: p5.SoundFile +example: + - |- + +
+ let mySound; + function preload(){ + mySound = loadSound('assets/Damscray_DancingTiger.mp3'); + } + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + noFill(); + rect(0, height/2, width - 1, height/2 - 1); + rect(0, 0, width - 1, height/2); + textAlign(CENTER, CENTER); + fill(20); + text('restart', width/2, 1 * height/4); + text('sustain', width/2, 3 * height/4); + } + function canvasPressed() { + if (mouseX < height/2) { + mySound.playMode('restart'); + } else { + mySound.playMode('sustain'); + } + mySound.play(); + } + +
+chainable: false +--- + + +# playMode diff --git a/src/content/reference/en/p5.SoundFile/rate.mdx b/src/content/reference/en/p5.SoundFile/rate.mdx new file mode 100644 index 0000000000..64952d3396 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/rate.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rate +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the playback rate of a sound file. Will change the speed and the pitch. + Values less than zero will reverse the audio buffer.

+line: 2146 +params: + - name: playbackRate + description: | +

Set the playback rate. 1.0 is normal, + .5 is half-speed, 2.0 is twice as fast. + Values less than zero play backwards.

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +example: + - | + +
+ let mySound; + + function preload() { + mySound = loadSound('assets/Damscray_DancingTiger.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + } + function canvasPressed() { + mySound.loop(); + } + function mouseReleased() { + mySound.pause(); + } + function draw() { + background(220); + + // Set the rate to a range between 0.1 and 4 + // Changing the rate also alters the pitch + let playbackRate = map(mouseY, 0.1, height, 2, 0); + playbackRate = constrain(playbackRate, 0.01, 4); + mySound.rate(playbackRate); + + line(0, mouseY, width, mouseY); + text('rate: ' + round(playbackRate * 100) + '%', 10, 20); + } + + +
+chainable: false +--- + + +# rate diff --git a/src/content/reference/en/p5.SoundFile/removeCue.mdx b/src/content/reference/en/p5.SoundFile/removeCue.mdx new file mode 100644 index 0000000000..f1758692cc --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/removeCue.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeCue +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Remove a callback based on its ID. The ID is returned by the + addCue method.

+line: 2790 +params: + - name: id + description: | +

ID of the cue, as returned by addCue

+ type: Number +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# removeCue diff --git a/src/content/reference/en/p5.SoundFile/reverseBuffer.mdx b/src/content/reference/en/p5.SoundFile/reverseBuffer.mdx new file mode 100644 index 0000000000..ee8582b93e --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/reverseBuffer.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reverseBuffer +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Reverses the p5.SoundFile's buffer source. + Playback must be handled separately (see example).

+line: 2443 +itemtype: method +class: p5.SoundFile +example: + - |- + +
+ let drum; + function preload() { + drum = loadSound('assets/drum.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap to play', 20, 20); + } + + function canvasPressed() { + drum.stop(); + drum.reverseBuffer(); + drum.play(); + } + +
+chainable: false +--- + + +# reverseBuffer diff --git a/src/content/reference/en/p5.SoundFile/sampleRate.mdx b/src/content/reference/en/p5.SoundFile/sampleRate.mdx new file mode 100644 index 0000000000..a8b2eb69d8 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/sampleRate.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sampleRate +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Return the sample rate of the sound file.

+line: 2354 +itemtype: method +class: p5.SoundFile +return: + description: '[sampleRate]' + type: Number +chainable: false +--- + + +# sampleRate diff --git a/src/content/reference/en/p5.SoundFile/save.mdx b/src/content/reference/en/p5.SoundFile/save.mdx new file mode 100644 index 0000000000..e328dae08f --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/save.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: save +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Save a p5.SoundFile as a .wav file. The browser will prompt the user + to download the file to their device. To upload a file to a server, see + getBlob

+line: 2850 +params: + - name: fileName + description: | +

name of the resulting .wav file.

+ type: String + optional: true +itemtype: method +class: p5.SoundFile +example: + - |2- + +
+ let mySound; + function preload() { + mySound = loadSound('assets/doorbell.mp3'); + } + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap to download', 10, 20); + } + + function canvasPressed() { + mySound.save('my cool filename'); + } +
+chainable: false +--- + + +# save diff --git a/src/content/reference/en/p5.SoundFile/setBuffer.mdx b/src/content/reference/en/p5.SoundFile/setBuffer.mdx new file mode 100644 index 0000000000..bdb92a5005 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/setBuffer.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setBuffer +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Replace the current Audio Buffer with a new Buffer.

+line: 2630 +params: + - name: buf + description: | +

Array of Float32 Array(s). 2 Float32 Arrays + will create a stereo source. 1 will create + a mono source.

+ type: Array +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# setBuffer diff --git a/src/content/reference/en/p5.SoundFile/setLoop.mdx b/src/content/reference/en/p5.SoundFile/setLoop.mdx new file mode 100644 index 0000000000..aa9b245023 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/setLoop.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setLoop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set a p5.SoundFile's looping flag to true or false. If the sound + is currently playing, this change will take effect when it + reaches the end of the current playback.

+line: 1950 +params: + - name: Boolean + description: | +

set looping to true or false

+ type: Boolean +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# setLoop diff --git a/src/content/reference/en/p5.SoundFile/setPath.mdx b/src/content/reference/en/p5.SoundFile/setPath.mdx new file mode 100644 index 0000000000..bdc995ef6a --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/setPath.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setPath +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Reset the source for this SoundFile to a + new path (URL).

+line: 2612 +params: + - name: path + description: | +

path to audio file

+ type: String + - name: callback + description: | +

Callback

+ type: Function +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# setPath diff --git a/src/content/reference/en/p5.SoundFile/setVolume.mdx b/src/content/reference/en/p5.SoundFile/setVolume.mdx new file mode 100644 index 0000000000..28e7302f6b --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/setVolume.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setVolume +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Multiply the output volume (amplitude) of a sound file + between 0.0 (silence) and 1.0 (full volume). + 1.0 is the maximum amplitude of a digital sound, so multiplying + by greater than 1.0 may cause digital distortion. To + fade, provide a rampTime parameter. For more + complex fades, see the Envelope class.

+

Alternately, you can pass in a signal source such as an + oscillator to modulate the amplitude with an audio signal.

+line: 2239 +params: + - name: volume + description: | +

Volume (amplitude) between 0.0 + and 1.0 or modulating signal/oscillator

+ type: Number|Object + - name: rampTime + description: | +

Fade for t seconds

+ type: Number + optional: true + - name: timeFromNow + description: | +

Schedule this event to happen at + t seconds in the future

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# setVolume diff --git a/src/content/reference/en/p5.SoundFile/stop.mdx b/src/content/reference/en/p5.SoundFile/stop.mdx new file mode 100644 index 0000000000..5f7dbf7af8 --- /dev/null +++ b/src/content/reference/en/p5.SoundFile/stop.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop soundfile playback.

+line: 2025 +params: + - name: startTime + description: | +

(optional) schedule event to occur + in seconds from now

+ type: Number + optional: true +itemtype: method +class: p5.SoundFile +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.SoundLoop/bpm.mdx b/src/content/reference/en/p5.SoundLoop/bpm.mdx new file mode 100644 index 0000000000..a76ac43e6b --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/bpm.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bpm +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Getters and Setters, setting any paramter will result in a change in the + clock's + + frequency, that will be reflected after the next callback + + beats per minute (defaults to 60)

+line: 9729 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# bpm diff --git a/src/content/reference/en/p5.SoundLoop/interval.mdx b/src/content/reference/en/p5.SoundLoop/interval.mdx new file mode 100644 index 0000000000..cad2c0386b --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/interval.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: interval +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

length of the loops interval

+line: 9770 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# interval diff --git a/src/content/reference/en/p5.SoundLoop/iterations.mdx b/src/content/reference/en/p5.SoundLoop/iterations.mdx new file mode 100644 index 0000000000..3574e575bc --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/iterations.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: iterations +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

how many times the callback has been called so far

+line: 9787 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# iterations diff --git a/src/content/reference/en/p5.SoundLoop/maxIterations.mdx b/src/content/reference/en/p5.SoundLoop/maxIterations.mdx new file mode 100644 index 0000000000..ce1e93e806 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/maxIterations.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: maxIterations +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set a limit to the number of loops to play. defaults to Infinity

+line: 9816 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# maxIterations diff --git a/src/content/reference/en/p5.SoundLoop/musicalTimeMode.mdx b/src/content/reference/en/p5.SoundLoop/musicalTimeMode.mdx new file mode 100644 index 0000000000..b006d161f6 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/musicalTimeMode.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: musicalTimeMode +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

musicalTimeMode uses Tone.Time convention + + true if string, false if number

+line: 9800 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# musicalTimeMode diff --git a/src/content/reference/en/p5.SoundLoop/pause.mdx b/src/content/reference/en/p5.SoundLoop/pause.mdx new file mode 100644 index 0000000000..4c664223b4 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/pause.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pause +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Pause the loop

+line: 9878 +params: + - name: timeFromNow + description: | +

schedule a pausing time

+ type: Number + optional: true +itemtype: method +class: p5.SoundLoop +chainable: false +--- + + +# pause diff --git a/src/content/reference/en/p5.SoundLoop/start.mdx b/src/content/reference/en/p5.SoundLoop/start.mdx new file mode 100644 index 0000000000..c63dce7f64 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/start.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: start +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start the loop

+line: 9841 +params: + - name: timeFromNow + description: | +

schedule a starting time

+ type: Number + optional: true +itemtype: method +class: p5.SoundLoop +chainable: false +--- + + +# start diff --git a/src/content/reference/en/p5.SoundLoop/stop.mdx b/src/content/reference/en/p5.SoundLoop/stop.mdx new file mode 100644 index 0000000000..06b0308fd2 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/stop.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop the loop

+line: 9860 +params: + - name: timeFromNow + description: | +

schedule a stopping time

+ type: Number + optional: true +itemtype: method +class: p5.SoundLoop +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.SoundLoop/syncedStart.mdx b/src/content/reference/en/p5.SoundLoop/syncedStart.mdx new file mode 100644 index 0000000000..1bd6c6f1ca --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/syncedStart.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: syncedStart +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Synchronize loops. Use this method to start two or more loops in + synchronization + + or to start a loop in synchronization with a loop that is already playing + + This method will schedule the implicit loop in sync with the explicit master + loop + + i.e. loopToStart.syncedStart(loopToSyncWith)

+line: 9896 +params: + - name: otherLoop + description: | +

a p5.SoundLoop to sync with

+ type: Object + - name: timeFromNow + description: | +

Start the loops in sync after timeFromNow seconds

+ type: Number + optional: true +itemtype: method +class: p5.SoundLoop +chainable: false +--- + + +# syncedStart diff --git a/src/content/reference/en/p5.SoundLoop/timeSignature.mdx b/src/content/reference/en/p5.SoundLoop/timeSignature.mdx new file mode 100644 index 0000000000..40180eac91 --- /dev/null +++ b/src/content/reference/en/p5.SoundLoop/timeSignature.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: timeSignature +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

number of quarter notes in a measure (defaults to 4)

+line: 9750 +itemtype: property +class: p5.SoundLoop +chainable: false +--- + + +# timeSignature diff --git a/src/content/reference/en/p5.SoundRecorder/record.mdx b/src/content/reference/en/p5.SoundRecorder/record.mdx new file mode 100644 index 0000000000..e052747694 --- /dev/null +++ b/src/content/reference/en/p5.SoundRecorder/record.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: record +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Start recording. To access the recording, provide + a p5.SoundFile as the first parameter. The p5.SoundRecorder + will send its recording to that p5.SoundFile for playback once + recording is complete. Optional parameters include duration + (in seconds) of the recording, and a callback function that + will be called once the complete recording has been + transfered to the p5.SoundFile.

+line: 10703 +params: + - name: soundFile + description: | +

p5.SoundFile

+ type: p5.SoundFile + - name: duration + description: | +

Time (in seconds)

+ type: Number + optional: true + - name: callback + description: | +

The name of a function that will be + called once the recording completes

+ type: Function + optional: true +itemtype: method +class: p5.SoundRecorder +chainable: false +--- + + +# record diff --git a/src/content/reference/en/p5.SoundRecorder/setInput.mdx b/src/content/reference/en/p5.SoundRecorder/setInput.mdx new file mode 100644 index 0000000000..2a8676b80b --- /dev/null +++ b/src/content/reference/en/p5.SoundRecorder/setInput.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setInput +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Connect a specific device to the p5.SoundRecorder. + If no parameter is given, p5.SoundRecorer will record + all audible p5.sound from your sketch.

+line: 10676 +params: + - name: unit + description: | +

p5.sound object or a web audio unit + that outputs sound

+ type: Object + optional: true +itemtype: method +class: p5.SoundRecorder +chainable: false +--- + + +# setInput diff --git a/src/content/reference/en/p5.SoundRecorder/stop.mdx b/src/content/reference/en/p5.SoundRecorder/stop.mdx new file mode 100644 index 0000000000..a2cc40683e --- /dev/null +++ b/src/content/reference/en/p5.SoundRecorder/stop.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: stop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Stop the recording. Once the recording is stopped, + the results will be sent to the p5.SoundFile that + was given on .record(), and if a callback function + was provided on record, that function will be called.

+line: 10739 +itemtype: method +class: p5.SoundRecorder +chainable: false +--- + + +# stop diff --git a/src/content/reference/en/p5.Table/addColumn.mdx b/src/content/reference/en/p5.Table/addColumn.mdx new file mode 100644 index 0000000000..1a89e8f89f --- /dev/null +++ b/src/content/reference/en/p5.Table/addColumn.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addColumn +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Use addColumn() to add a new column to a Table object. + + Typically, you will want to specify a title, so the column + + may be easily referenced later by name. (If no title is + + specified, the new column's title will be null.)

+line: 631 +params: + - name: title + description: | +

title of the given column

+ type: String + optional: true +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + table.addColumn('carnivore'); + table.set(0, 'carnivore', 'no'); + table.set(1, 'carnivore', 'yes'); + table.set(2, 'carnivore', 'no'); + + //print the results + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) + print(table.getString(r, c)); + + describe('no image displayed'); + } + +
+chainable: false +--- + + +# addColumn diff --git a/src/content/reference/en/p5.Table/addRow.mdx b/src/content/reference/en/p5.Table/addRow.mdx new file mode 100644 index 0000000000..51fa7798cd --- /dev/null +++ b/src/content/reference/en/p5.Table/addRow.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addRow +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Use addRow() to add a new row of data to a p5.Table object. By default, + + an empty row is created. Typically, you would store a reference to + + the new row in a TableRow object (see newRow in the example above), + + and then set individual values using set().

+ +

If a p5.TableRow object is included as a + parameter, then that row is + + duplicated and added to the table.

+line: 90 +params: + - name: row + description: | +

row to be added to the table

+ type: p5.TableRow + optional: true +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //add a row + let newRow = table.addRow(); + newRow.setString('id', table.getRowCount() - 1); + newRow.setString('species', 'Canis Lupus'); + newRow.setString('name', 'Wolf'); + + //print the results + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) + print(table.getString(r, c)); + + describe('no image displayed'); + } + +
+return: + description: the row that was added + type: p5.TableRow +chainable: false +--- + + +# addRow diff --git a/src/content/reference/en/p5.Table/clearRows.mdx b/src/content/reference/en/p5.Table/clearRows.mdx new file mode 100644 index 0000000000..10221cf585 --- /dev/null +++ b/src/content/reference/en/p5.Table/clearRows.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearRows +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Removes all rows from a Table. While all rows are removed, + columns and column titles are maintained.

+line: 592 +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + table.clearRows(); + print(table.getRowCount() + ' total rows in table'); + print(table.getColumnCount() + ' total columns in table'); + describe('no image displayed'); + } + +
+chainable: false +--- + + +# clearRows diff --git a/src/content/reference/en/p5.Table/columns.mdx b/src/content/reference/en/p5.Table/columns.mdx new file mode 100644 index 0000000000..66cfbea052 --- /dev/null +++ b/src/content/reference/en/p5.Table/columns.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: columns +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

An array containing the names of the columns in the table, if the "header" + the table is + + loaded with the "header" parameter.

+line: 43 +itemtype: property +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //print the column names + for (let c = 0; c < table.getColumnCount(); c++) { + print('column ' + c + ' is named ' + table.columns[c]); + } + } + +
+chainable: false +--- + + +# columns diff --git a/src/content/reference/en/p5.Table/findRow.mdx b/src/content/reference/en/p5.Table/findRow.mdx new file mode 100644 index 0000000000..f532c69c09 --- /dev/null +++ b/src/content/reference/en/p5.Table/findRow.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: findRow +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Finds the first row in the Table that contains the value + provided, and returns a reference to that row. Even if + multiple rows are possible matches, only the first matching + row is returned. The column to search may be specified by + either its ID or title.

+line: 289 +params: + - name: value + description: | +

The value to match

+ type: String + - name: column + description: | +

ID number or title of the + column to search

+ type: Integer|String +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //find the animal named zebra + let row = table.findRow('Zebra', 'name'); + //find the corresponding species + print(row.getString('species')); + describe('no image displayed'); + } + +
+return: + description: '' + type: p5.TableRow +chainable: false +--- + + +# findRow diff --git a/src/content/reference/en/p5.Table/findRows.mdx b/src/content/reference/en/p5.Table/findRows.mdx new file mode 100644 index 0000000000..e91930567b --- /dev/null +++ b/src/content/reference/en/p5.Table/findRows.mdx @@ -0,0 +1,68 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: findRows +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Finds the rows in the Table that contain the value + provided, and returns references to those rows. Returns an + Array, so for must be used to iterate through all the rows, + as shown in the example above. The column to search may be + specified by either its ID or title.

+line: 351 +params: + - name: value + description: | +

The value to match

+ type: String + - name: column + description: | +

ID number or title of the + column to search

+ type: Integer|String +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //add another goat + let newRow = table.addRow(); + newRow.setString('id', table.getRowCount() - 1); + newRow.setString('species', 'Scape Goat'); + newRow.setString('name', 'Goat'); + + //find the rows containing animals named Goat + let rows = table.findRows('Goat', 'name'); + print(rows.length + ' Goats found'); + describe('no image displayed'); + } + +
+return: + description: An Array of TableRow objects + type: 'p5.TableRow[]' +chainable: false +--- + + +# findRows diff --git a/src/content/reference/en/p5.Table/get.mdx b/src/content/reference/en/p5.Table/get.mdx new file mode 100644 index 0000000000..bba1d1a435 --- /dev/null +++ b/src/content/reference/en/p5.Table/get.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves a value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+line: 1087 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + print(table.get(0, 1)); + //Capra hircus + print(table.get(0, 'species')); + //Capra hircus + describe('no image displayed'); + } + +
+return: + description: '' + type: String|Number +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5.Table/getArray.mdx b/src/content/reference/en/p5.Table/getArray.mdx new file mode 100644 index 0000000000..5f3878f4e1 --- /dev/null +++ b/src/content/reference/en/p5.Table/getArray.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getArray +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves all table data and returns it as a multidimensional array.

+line: 1285 +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leoperd + // 2,Equus zebra,Zebra + + let table; + + function preload() { + // table is comma separated value "CSV" + // and has specifiying header for column labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let tableArray = table.getArray(); + for (let i = 0; i < tableArray.length; i++) { + print(tableArray[i]); + } + describe('no image displayed'); + } + +
+return: + description: '' + type: Array +chainable: false +--- + + +# getArray diff --git a/src/content/reference/en/p5.Table/getColumn.mdx b/src/content/reference/en/p5.Table/getColumn.mdx new file mode 100644 index 0000000000..8aeefc6ff4 --- /dev/null +++ b/src/content/reference/en/p5.Table/getColumn.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getColumn +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves all values in the specified column, and returns them + as an array. The column may be specified by either its ID or title.

+line: 542 +params: + - name: column + description: | +

String or Number of the column to return

+ type: String|Number +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //getColumn returns an array that can be printed directly + print(table.getColumn('species')); + //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"] + describe('no image displayed'); + } + +
+return: + description: Array of column values + type: Array +chainable: false +--- + + +# getColumn diff --git a/src/content/reference/en/p5.Table/getColumnCount.mdx b/src/content/reference/en/p5.Table/getColumnCount.mdx new file mode 100644 index 0000000000..a1fae6afe0 --- /dev/null +++ b/src/content/reference/en/p5.Table/getColumnCount.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getColumnCount +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Returns the total number of columns in a Table.

+line: 680 +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // given the cvs file "blobs.csv" in /assets directory + // ID, Name, Flavor, Shape, Color + // Blob1, Blobby, Sweet, Blob, Pink + // Blob2, Saddy, Savory, Blob, Blue + + let table; + + function preload() { + table = loadTable('assets/blobs.csv'); + } + + function setup() { + createCanvas(200, 100); + textAlign(CENTER); + background(255); + } + + function draw() { + let numOfColumn = table.getColumnCount(); + text('There are ' + numOfColumn + ' columns in the table.', 100, 50); + } + +
+return: + description: Number of columns in this table + type: Integer +chainable: false +--- + + +# getColumnCount diff --git a/src/content/reference/en/p5.Table/getNum.mdx b/src/content/reference/en/p5.Table/getNum.mdx new file mode 100644 index 0000000000..eb5e48dc99 --- /dev/null +++ b/src/content/reference/en/p5.Table/getNum.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getNum +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves a Float value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+line: 1131 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + print(table.getNum(1, 0) + 100); + //id 1 + 100 = 101 + describe('no image displayed'); + } + +
+return: + description: '' + type: Number +chainable: false +--- + + +# getNum diff --git a/src/content/reference/en/p5.Table/getObject.mdx b/src/content/reference/en/p5.Table/getObject.mdx new file mode 100644 index 0000000000..c414dec60d --- /dev/null +++ b/src/content/reference/en/p5.Table/getObject.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getObject +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves all table data and returns as an object. If a column name is + passed in, each row object will be stored with that attribute as its + title.

+line: 1223 +params: + - name: headerColumn + description: | +

Name of the column which should be used to + title each row object (optional)

+ type: String + optional: true +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let tableObject = table.getObject(); + + print(tableObject); + //outputs an object + + describe('no image displayed'); + } + +
+return: + description: '' + type: Object +chainable: false +--- + + +# getObject diff --git a/src/content/reference/en/p5.Table/getRow.mdx b/src/content/reference/en/p5.Table/getRow.mdx new file mode 100644 index 0000000000..3d90850d9f --- /dev/null +++ b/src/content/reference/en/p5.Table/getRow.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getRow +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Returns a reference to the specified p5.TableRow. The reference + + can then be used to get and set values of the selected row.

+line: 198 +params: + - name: rowID + description: | +

ID number of the row to get

+ type: Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let row = table.getRow(1); + //print it column by column + //note: a row is an object, not an array + for (let c = 0; c < table.getColumnCount(); c++) { + print(row.getString(c)); + } + + describe('no image displayed'); + } + +
+return: + description: p5.TableRow object + type: p5.TableRow +chainable: false +--- + + +# getRow diff --git a/src/content/reference/en/p5.Table/getRowCount.mdx b/src/content/reference/en/p5.Table/getRowCount.mdx new file mode 100644 index 0000000000..e6d88270c9 --- /dev/null +++ b/src/content/reference/en/p5.Table/getRowCount.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getRowCount +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Returns the total number of rows in a Table.

+line: 716 +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // given the cvs file "blobs.csv" in /assets directory + // + // ID, Name, Flavor, Shape, Color + // Blob1, Blobby, Sweet, Blob, Pink + // Blob2, Saddy, Savory, Blob, Blue + + let table; + + function preload() { + table = loadTable('assets/blobs.csv'); + } + + function setup() { + createCanvas(200, 100); + textAlign(CENTER); + background(255); + } + + function draw() { + text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50); + } + +
+return: + description: Number of rows in this table + type: Integer +chainable: false +--- + + +# getRowCount diff --git a/src/content/reference/en/p5.Table/getRows.mdx b/src/content/reference/en/p5.Table/getRows.mdx new file mode 100644 index 0000000000..33ce25cbf3 --- /dev/null +++ b/src/content/reference/en/p5.Table/getRows.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getRows +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Gets all rows from the table. Returns an array of p5.TableRows.

+line: 242 +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + + //warning: rows is an array of objects + for (let r = 0; r < rows.length; r++) { + rows[r].set('name', 'Unicorn'); + } + + //print the results + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) + print(table.getString(r, c)); + + describe('no image displayed'); + } + +
+return: + description: Array of p5.TableRows + type: 'p5.TableRow[]' +chainable: false +--- + + +# getRows diff --git a/src/content/reference/en/p5.Table/getString.mdx b/src/content/reference/en/p5.Table/getString.mdx new file mode 100644 index 0000000000..a31bc70739 --- /dev/null +++ b/src/content/reference/en/p5.Table/getString.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getString +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Retrieves a String value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+line: 1173 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + // table is comma separated value "CSV" + // and has specifiying header for column labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + print(table.getString(0, 0)); // 0 + print(table.getString(0, 1)); // Capra hircus + print(table.getString(0, 2)); // Goat + print(table.getString(1, 0)); // 1 + print(table.getString(1, 1)); // Panthera pardus + print(table.getString(1, 2)); // Leopard + print(table.getString(2, 0)); // 2 + print(table.getString(2, 1)); // Equus zebra + print(table.getString(2, 2)); // Zebra + describe('no image displayed'); + } + +
+return: + description: '' + type: String +chainable: false +--- + + +# getString diff --git a/src/content/reference/en/p5.Table/matchRow.mdx b/src/content/reference/en/p5.Table/matchRow.mdx new file mode 100644 index 0000000000..02b85c6163 --- /dev/null +++ b/src/content/reference/en/p5.Table/matchRow.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: matchRow +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Finds the first row in the Table that matches the regular + expression provided, and returns a reference to that row. + Even if multiple rows are possible matches, only the first + matching row is returned. The column to search may be + specified by either its ID or title.

+line: 417 +params: + - name: regexp + description: | +

The regular expression to match

+ type: String|RegExp + - name: column + description: | +

The column ID (number) or + title (string)

+ type: String|Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //Search using specified regex on a given column, return TableRow object + let mammal = table.matchRow(new RegExp('ant'), 1); + print(mammal.getString(1)); + //Output "Panthera pardus" + } + +
+return: + description: TableRow object + type: p5.TableRow +chainable: false +--- + + +# matchRow diff --git a/src/content/reference/en/p5.Table/matchRows.mdx b/src/content/reference/en/p5.Table/matchRows.mdx new file mode 100644 index 0000000000..2bdcfda7cf --- /dev/null +++ b/src/content/reference/en/p5.Table/matchRows.mdx @@ -0,0 +1,72 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: matchRows +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Finds the rows in the Table that match the regular expression provided, + and returns references to those rows. Returns an array, so for must be + used to iterate through all the rows, as shown in the example. The + column to search may be specified by either its ID or title.

+line: 475 +params: + - name: regexp + description: | +

The regular expression to match

+ type: String + - name: column + description: | +

The column ID (number) or + title (string)

+ type: String|Integer + optional: true +itemtype: method +class: p5.Table +example: + - |- + +
+ + let table; + + function setup() { + table = new p5.Table(); + + table.addColumn('name'); + table.addColumn('type'); + + let newRow = table.addRow(); + newRow.setString('name', 'Lion'); + newRow.setString('type', 'Mammal'); + + newRow = table.addRow(); + newRow.setString('name', 'Snake'); + newRow.setString('type', 'Reptile'); + + newRow = table.addRow(); + newRow.setString('name', 'Mosquito'); + newRow.setString('type', 'Insect'); + + newRow = table.addRow(); + newRow.setString('name', 'Lizard'); + newRow.setString('type', 'Reptile'); + + let rows = table.matchRows('R.*', 'type'); + for (let i = 0; i < rows.length; i++) { + print(rows[i].getString('name') + ': ' + rows[i].getString('type')); + } + } + // Sketch prints: + // Snake: Reptile + // Lizard: Reptile + +
+return: + description: An Array of TableRow objects + type: 'p5.TableRow[]' +chainable: false +--- + + +# matchRows diff --git a/src/content/reference/en/p5.Table/removeColumn.mdx b/src/content/reference/en/p5.Table/removeColumn.mdx new file mode 100644 index 0000000000..3798f0844e --- /dev/null +++ b/src/content/reference/en/p5.Table/removeColumn.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeColumn +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Use removeColumn() to remove an existing + column from a Table + + object. The column to be removed may be identified by either + + its title (a String) or its index value (an int). + + removeColumn(0) would remove the first column, removeColumn(1) + + would remove the second column, and so on.

+line: 888 +params: + - name: column + description: | +

columnName (string) or ID (number)

+ type: String|Integer +itemtype: method +class: p5.Table +example: + - |2- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + table.removeColumn('id'); + print(table.getColumnCount()); + describe('no image displayed'); + } + +
+chainable: false +--- + + +# removeColumn diff --git a/src/content/reference/en/p5.Table/removeRow.mdx b/src/content/reference/en/p5.Table/removeRow.mdx new file mode 100644 index 0000000000..9a47d1c3ab --- /dev/null +++ b/src/content/reference/en/p5.Table/removeRow.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeRow +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Removes a row from the table object.

+line: 152 +params: + - name: id + description: | +

ID number of the row to remove

+ type: Integer +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //remove the first row + table.removeRow(0); + + //print the results + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) + print(table.getString(r, c)); + + describe('no image displayed'); + } + +
+chainable: false +--- + + +# removeRow diff --git a/src/content/reference/en/p5.Table/removeTokens.mdx b/src/content/reference/en/p5.Table/removeTokens.mdx new file mode 100644 index 0000000000..d30f40f37b --- /dev/null +++ b/src/content/reference/en/p5.Table/removeTokens.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeTokens +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Removes any of the specified characters (or "tokens").

+

If no column is specified, then the values in all columns and + rows are processed. A specific column may be referenced by + either its ID or title.

+line: 752 +params: + - name: chars + description: | +

String listing characters to be removed

+ type: String + - name: column + description: | +

Column ID (number) + or name (string)

+ type: String|Integer + optional: true +itemtype: method +class: p5.Table +example: + - |2- + +
+ function setup() { + let table = new p5.Table(); + + table.addColumn('name'); + table.addColumn('type'); + + let newRow = table.addRow(); + newRow.setString('name', ' $Lion ,'); + newRow.setString('type', ',,,Mammal'); + + newRow = table.addRow(); + newRow.setString('name', '$Snake '); + newRow.setString('type', ',,,Reptile'); + + table.removeTokens(',$ '); + print(table.getArray()); + } + + // prints: + // 0 "Lion" "Mamal" + // 1 "Snake" "Reptile" +
+chainable: false +--- + + +# removeTokens diff --git a/src/content/reference/en/p5.Table/rows.mdx b/src/content/reference/en/p5.Table/rows.mdx new file mode 100644 index 0000000000..6cfac953cb --- /dev/null +++ b/src/content/reference/en/p5.Table/rows.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rows +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

An array containing the p5.TableRow objects that + make up the + + rows of the table. The same result as calling getRows()

+line: 80 +itemtype: property +class: p5.Table +chainable: false +--- + + +# rows diff --git a/src/content/reference/en/p5.Table/set.mdx b/src/content/reference/en/p5.Table/set.mdx new file mode 100644 index 0000000000..390c9253d9 --- /dev/null +++ b/src/content/reference/en/p5.Table/set.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Stores a value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+line: 950 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

column ID (Number) + or title (String)

+ type: String|Integer + - name: value + description: | +

value to assign

+ type: String|Number +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + table.set(0, 'species', 'Canis Lupus'); + table.set(0, 'name', 'Wolf'); + + //print the results + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) + print(table.getString(r, c)); + + describe('no image displayed'); + } + +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.Table/setNum.mdx b/src/content/reference/en/p5.Table/setNum.mdx new file mode 100644 index 0000000000..032b3b299b --- /dev/null +++ b/src/content/reference/en/p5.Table/setNum.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setNum +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Stores a Float value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+line: 998 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

column ID (Number) + or title (String)

+ type: String|Integer + - name: value + description: | +

value to assign

+ type: Number +itemtype: method +class: p5.Table +example: + - |- + +
+ + // Given the CSV file "mammals.csv" + // in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + table.setNum(1, 'id', 1); + + print(table.getColumn(0)); + //["0", 1, "2"] + + describe('no image displayed'); + } + +
+chainable: false +--- + + +# setNum diff --git a/src/content/reference/en/p5.Table/setString.mdx b/src/content/reference/en/p5.Table/setString.mdx new file mode 100644 index 0000000000..42592c608e --- /dev/null +++ b/src/content/reference/en/p5.Table/setString.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setString +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Stores a String value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+line: 1043 +params: + - name: row + description: | +

row ID

+ type: Integer + - name: column + description: | +

column ID (Number) + or title (String)

+ type: String|Integer + - name: value + description: | +

value to assign

+ type: String +itemtype: method +class: p5.Table +example: + - |- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + //add a row + let newRow = table.addRow(); + newRow.setString('id', table.getRowCount() - 1); + newRow.setString('species', 'Canis Lupus'); + newRow.setString('name', 'Wolf'); + + print(table.getArray()); + + describe('no image displayed'); + } +
+chainable: false +--- + + +# setString diff --git a/src/content/reference/en/p5.Table/trim.mdx b/src/content/reference/en/p5.Table/trim.mdx new file mode 100644 index 0000000000..c94b184aa0 --- /dev/null +++ b/src/content/reference/en/p5.Table/trim.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: trim +module: IO +submodule: Table +file: src/io/p5.Table.js +description: | +

Trims leading and trailing whitespace, such as spaces and tabs, + from String table values. If no column is specified, then the + values in all columns and rows are trimmed. A specific column + may be referenced by either its ID or title.

+line: 824 +params: + - name: column + description: | +

Column ID (number) + or name (string)

+ type: String|Integer + optional: true +itemtype: method +class: p5.Table +example: + - |2- + +
+ function setup() { + let table = new p5.Table(); + + table.addColumn('name'); + table.addColumn('type'); + + let newRow = table.addRow(); + newRow.setString('name', ' Lion ,'); + newRow.setString('type', ' Mammal '); + + newRow = table.addRow(); + newRow.setString('name', ' Snake '); + newRow.setString('type', ' Reptile '); + + table.trim(); + print(table.getArray()); + } + + // prints: + // 0 "Lion" "Mamal" + // 1 "Snake" "Reptile" +
+chainable: false +--- + + +# trim diff --git a/src/content/reference/en/p5.TableRow/get.mdx b/src/content/reference/en/p5.TableRow/get.mdx new file mode 100644 index 0000000000..280567fdbc --- /dev/null +++ b/src/content/reference/en/p5.TableRow/get.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Retrieves a value from the TableRow's specified column. + The column may be specified by either its ID or title.

+line: 184 +params: + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let names = []; + let rows = table.getRows(); + for (let r = 0; r < rows.length; r++) { + names.push(rows[r].get('name')); + } + + print(names); + + describe('no image displayed'); + } +
+return: + description: '' + type: String|Number +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5.TableRow/getNum.mdx b/src/content/reference/en/p5.TableRow/getNum.mdx new file mode 100644 index 0000000000..b9e9bc8322 --- /dev/null +++ b/src/content/reference/en/p5.TableRow/getNum.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getNum +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Retrieves a Float value from the TableRow's specified + column. The column may be specified by either its ID or + title.

+line: 231 +params: + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + let minId = Infinity; + let maxId = -Infinity; + for (let r = 0; r < rows.length; r++) { + let id = rows[r].getNum('id'); + minId = min(minId, id); + maxId = min(maxId, id); + } + print('minimum id = ' + minId + ', maximum id = ' + maxId); + describe('no image displayed'); + } +
+return: + description: Float Floating point number + type: Number +chainable: false +--- + + +# getNum diff --git a/src/content/reference/en/p5.TableRow/getString.mdx b/src/content/reference/en/p5.TableRow/getString.mdx new file mode 100644 index 0000000000..2c93a38ba6 --- /dev/null +++ b/src/content/reference/en/p5.TableRow/getString.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getString +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Retrieves an String value from the TableRow's specified + column. The column may be specified by either its ID or + title.

+line: 285 +params: + - name: column + description: | +

columnName (string) or + ID (number)

+ type: String|Integer +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + let longest = ''; + for (let r = 0; r < rows.length; r++) { + let species = rows[r].getString('species'); + if (longest.length < species.length) { + longest = species; + } + } + + print('longest: ' + longest); + + describe('no image displayed'); + } +
+return: + description: String + type: String +chainable: false +--- + + +# getString diff --git a/src/content/reference/en/p5.TableRow/set.mdx b/src/content/reference/en/p5.TableRow/set.mdx new file mode 100644 index 0000000000..8c794a21cb --- /dev/null +++ b/src/content/reference/en/p5.TableRow/set.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Stores a value in the TableRow's specified column. + The column may be specified by either its ID or title.

+line: 36 +params: + - name: column + description: | +

Column ID (Number) + or Title (String)

+ type: String|Integer + - name: value + description: | +

The value to be stored

+ type: String|Number +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + for (let r = 0; r < rows.length; r++) { + rows[r].set('name', 'Unicorn'); + } + + //print the results + print(table.getArray()); + + describe('no image displayed'); + } +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.TableRow/setNum.mdx b/src/content/reference/en/p5.TableRow/setNum.mdx new file mode 100644 index 0000000000..adf8aeec25 --- /dev/null +++ b/src/content/reference/en/p5.TableRow/setNum.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setNum +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Stores a Float value in the TableRow's specified column. + The column may be specified by either its ID or title.

+line: 97 +params: + - name: column + description: | +

Column ID (Number) + or Title (String)

+ type: String|Integer + - name: value + description: | +

The value to be stored + as a Float

+ type: Number|String +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + for (let r = 0; r < rows.length; r++) { + rows[r].setNum('id', r + 10); + } + + print(table.getArray()); + + describe('no image displayed'); + } +
+chainable: false +--- + + +# setNum diff --git a/src/content/reference/en/p5.TableRow/setString.mdx b/src/content/reference/en/p5.TableRow/setString.mdx new file mode 100644 index 0000000000..54e2e0a5a3 --- /dev/null +++ b/src/content/reference/en/p5.TableRow/setString.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setString +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

Stores a String value in the TableRow's specified column. + The column may be specified by either its ID or title.

+line: 140 +params: + - name: column + description: | +

Column ID (Number) + or Title (String)

+ type: String|Integer + - name: value + description: | +

The value to be stored + as a String

+ type: String|Number|Boolean|Object +itemtype: method +class: p5.TableRow +example: + - |2- + +
+ // Given the CSV file "mammals.csv" in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + } + + function setup() { + let rows = table.getRows(); + for (let r = 0; r < rows.length; r++) { + let name = rows[r].getString('name'); + rows[r].setString('name', 'A ' + name + ' named George'); + } + + print(table.getArray()); + + describe('no image displayed'); + } +
+chainable: false +--- + + +# setString diff --git a/src/content/reference/en/p5.TypedDict/clear.mdx b/src/content/reference/en/p5.TypedDict/clear.mdx new file mode 100644 index 0000000000..f27f921c3a --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/clear.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clear +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Removes all previously stored key-value pairs from the Dictionary.

+line: 245 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + print(myDictionary.hasKey('p5')); // prints 'true' + myDictionary.clear(); + print(myDictionary.hasKey('p5')); // prints 'false' + } + +
+chainable: false +--- + + +# clear diff --git a/src/content/reference/en/p5.TypedDict/create.mdx b/src/content/reference/en/p5.TypedDict/create.mdx new file mode 100644 index 0000000000..fcb35ebc84 --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/create.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: create +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Creates a new key-value pair in the Dictionary.

+line: 209 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + myDictionary.create('happy', 'coding'); + myDictionary.print(); + // above logs "key: p5 - value: js, key: happy - value: coding" to console + } +
+chainable: false +--- + + +# create diff --git a/src/content/reference/en/p5.TypedDict/get.mdx b/src/content/reference/en/p5.TypedDict/get.mdx new file mode 100644 index 0000000000..cee8f93a1d --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/get.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Returns the value stored at the given key.

+line: 145 +params: + - name: the + description: | +

key you want to access

+ type: Number|String +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + let myValue = myDictionary.get('p5'); + print(myValue === 'js'); // logs true to console + } +
+return: + description: the value stored at that key + type: Number|String +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5.TypedDict/hasKey.mdx b/src/content/reference/en/p5.TypedDict/hasKey.mdx new file mode 100644 index 0000000000..5a846f3916 --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/hasKey.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hasKey +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Returns true if the given key exists in the Dictionary, + otherwise returns false.

+line: 123 +params: + - name: key + description: | +

that you want to look up

+ type: Number|String +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + print(myDictionary.hasKey('p5')); // logs true to console + } +
+return: + description: whether that key exists in Dictionary + type: Boolean +chainable: false +--- + + +# hasKey diff --git a/src/content/reference/en/p5.TypedDict/print.mdx b/src/content/reference/en/p5.TypedDict/print.mdx new file mode 100644 index 0000000000..05f1ffec27 --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/print.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: print +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: > +

Logs the set of items currently stored in the Dictionary to the + console.

+line: 295 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + myDictionary.create('happy', 'coding'); + myDictionary.print(); + // above logs "key: p5 - value: js, key: happy - value: coding" to console + } + +
+chainable: false +--- + + +# print diff --git a/src/content/reference/en/p5.TypedDict/remove.mdx b/src/content/reference/en/p5.TypedDict/remove.mdx new file mode 100644 index 0000000000..235debcdcd --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/remove.mdx @@ -0,0 +1,36 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: remove +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Removes the key-value pair stored at the given key from the Dictionary.

+line: 266 +params: + - name: key + description: | +

for the pair to remove

+ type: Number|String +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + myDictionary.create('happy', 'coding'); + myDictionary.print(); + // above logs "key: p5 - value: js, key: happy - value: coding" to console + myDictionary.remove('p5'); + myDictionary.print(); + // above logs "key: happy value: coding" to console + } +
+chainable: false +--- + + +# remove diff --git a/src/content/reference/en/p5.TypedDict/saveJSON.mdx b/src/content/reference/en/p5.TypedDict/saveJSON.mdx new file mode 100644 index 0000000000..eddc09202f --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/saveJSON.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveJSON +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Converts the Dictionary into a JSON file for local download.

+line: 357 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + text('click here to save', 10, 10, 70, 80); + } + + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + createStringDict({ + john: 1940, + paul: 1942, + george: 1943, + ringo: 1940 + }).saveJSON('beatles'); + } + } + +
+chainable: false +--- + + +# saveJSON diff --git a/src/content/reference/en/p5.TypedDict/saveTable.mdx b/src/content/reference/en/p5.TypedDict/saveTable.mdx new file mode 100644 index 0000000000..e52acfca89 --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/saveTable.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveTable +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Converts the Dictionary into a CSV file for local download.

+line: 319 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + text('click here to save', 10, 10, 70, 80); + } + + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + createStringDict({ + john: 1940, + paul: 1942, + george: 1943, + ringo: 1940 + }).saveTable('beatles'); + } + } + +
+chainable: false +--- + + +# saveTable diff --git a/src/content/reference/en/p5.TypedDict/set.mdx b/src/content/reference/en/p5.TypedDict/set.mdx new file mode 100644 index 0000000000..fceb7c354e --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/set.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Updates the value associated with the given key in case it already exists + in the Dictionary. Otherwise a new key-value pair is added.

+line: 171 +params: + - name: key + description: '' + type: Number|String + - name: value + description: '' + type: Number|String +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + myDictionary.set('p5', 'JS'); + myDictionary.print(); // logs "key: p5 - value: JS" to console + } +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5.TypedDict/size.mdx b/src/content/reference/en/p5.TypedDict/size.mdx new file mode 100644 index 0000000000..781a250cc1 --- /dev/null +++ b/src/content/reference/en/p5.TypedDict/size.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: size +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: > +

Returns the number of key-value pairs currently stored in the + Dictionary.

+line: 102 +itemtype: method +class: p5.TypedDict +example: + - |- + +
+ + function setup() { + let myDictionary = createNumberDict(1, 10); + myDictionary.create(2, 20); + myDictionary.create(3, 30); + print(myDictionary.size()); // logs 3 to the console + } +
+return: + description: the number of key-value pairs in the Dictionary + type: Integer +chainable: false +--- + + +# size diff --git a/src/content/reference/en/p5.Vector/add.mdx b/src/content/reference/en/p5.Vector/add.mdx new file mode 100644 index 0000000000..d683d3069c --- /dev/null +++ b/src/content/reference/en/p5.Vector/add.mdx @@ -0,0 +1,151 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: add +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Adds to a vector's x, y, and z + components using separate numbers, + + another p5.Vector object, or an array of numbers. + + Calling add() with no arguments has no effect.

+ +

The static version of add(), as in p5.Vector.add(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+line: 249 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + strokeWeight(5); + + + // Top left. + + let pos = createVector(25, 25); + + point(pos); + + + // Top right. + + pos.add(50, 0); + + point(pos); + + + // Bottom right. + + let p2 = createVector(0, 50); + + pos.add(p2); + + point(pos); + + + // Bottom left. + + let arr = [-50, 0]; + + pos.add(arr); + + point(pos); + + + describe('Four black dots arranged in a square on a gray background.'); + + + +
+ + +
+ + + + // Top left. + + let p1 = createVector(25, 25); + + + // Center. + + let p2 = createVector(50, 50); + + + // Bottom right. + + let p3 = p5.Vector.add(p1, p2); + + + strokeWeight(5); + + point(p1); + + point(p2); + + point(p3); + + + describe('Three black dots in a diagonal line from top left to bottom + right.'); + + + +
+ + +
+ + + + function draw() { + background(200); + + let origin = createVector(0, 0); + let v1 = createVector(50, 50); + drawArrow(origin, v1, 'red'); + + let v2 = createVector(-30, 20); + drawArrow(v1, v2, 'blue'); + + let v3 = p5.Vector.add(v1, v2); + drawArrow(origin, v3, 'purple'); + + describe('Three arrows drawn on a gray square. A red arrow extends from the top left corner to the center. A blue arrow extends from the tip of the red arrow. A purple arrow extends from the origin to the tip of the blue arrow.'); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+chainable: true +--- + + +# add diff --git a/src/content/reference/en/p5.Vector/angleBetween.mdx b/src/content/reference/en/p5.Vector/angleBetween.mdx new file mode 100644 index 0000000000..4db7d7394e --- /dev/null +++ b/src/content/reference/en/p5.Vector/angleBetween.mdx @@ -0,0 +1,117 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: angleBetween +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Returns the angle between two vectors. The angles returned are signed, + + which means that v1.angleBetween(v2) === + -v2.angleBetween(v1).

+ +

If the vector was created with + + createVector(), angleBetween() + returns + + angles in the units of the current + + angleMode().

+line: 1797 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v0 = createVector(1, 0); + let v1 = createVector(0, 1); + // Prints "1.570..." to the console. + print(v0.angleBetween(v1)); + // Prints "-1.570..." to the console. + print(v1.angleBetween(v0)); + +
+ +
+ + angleMode(DEGREES); + let v0 = createVector(1, 0); + let v1 = createVector(0, 1); + // Prints "90" to the console. + print(v0.angleBetween(v1)); + // Prints "-90" to the console. + print(v1.angleBetween(v0)); + +
+ +
+ + let v0 = createVector(1, 0); + let v1 = createVector(0, 1); + // Prints "1.570..." to the console. + print(p5.Vector.angleBetween(v0, v1)); + // Prints "-1.570..." to the console. + print(p5.Vector.angleBetween(v1, v0)); + +
+ +
+ + angleMode(DEGREES); + let v0 = createVector(1, 0); + let v1 = createVector(0, 1); + // Prints "90" to the console. + print(p5.Vector.angleBetween(v0, v1)); + // Prints "-90" to the console. + print(p5.Vector.angleBetween(v1, v0)); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(50, 50); + let v1 = createVector(30, 0); + let v2 = createVector(0, 30); + + drawArrow(v0, v1, 'red'); + drawArrow(v0, v2, 'blue'); + + angleMode(RADIANS); + let angle = round(v1.angleBetween(v2), 2); + text(`Radians: ${angle}`, 20, 20); + angleMode(DEGREES); + angle = round(v1.angleBetween(v2), 2); + text(`Degrees: ${angle}`, 20, 35); + + describe('Two arrows extend from the center of a gray square. A red arrow points to the right and a blue arrow points down. The text "Radians: 1.57" and "Degrees: 90" is written above the arrows.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: angle between the vectors. + type: Number +chainable: false +--- + + +# angleBetween diff --git a/src/content/reference/en/p5.Vector/array.mdx b/src/content/reference/en/p5.Vector/array.mdx new file mode 100644 index 0000000000..72c95d6601 --- /dev/null +++ b/src/content/reference/en/p5.Vector/array.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: array +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Returns the vector's components as an array of numbers.

+line: 2250 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(20, 30); + // Prints "[20, 30, 0]" to the console. + print(v.array()); + +
+return: + description: array with the vector's components. + type: 'Number[]' +chainable: false +--- + + +# array diff --git a/src/content/reference/en/p5.Vector/copy.mdx b/src/content/reference/en/p5.Vector/copy.mdx new file mode 100644 index 0000000000..259ecd6c60 --- /dev/null +++ b/src/content/reference/en/p5.Vector/copy.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: copy +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Returns a copy of the p5.Vector object.

+line: 217 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let pos = createVector(50, 50); + let pc = pos.copy(); + + strokeWeight(5); + point(pc); + + describe('A black point drawn in the middle of a gray square.'); + +
+return: + description: copy of the p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# copy diff --git a/src/content/reference/en/p5.Vector/cross.mdx b/src/content/reference/en/p5.Vector/cross.mdx new file mode 100644 index 0000000000..72123d16b0 --- /dev/null +++ b/src/content/reference/en/p5.Vector/cross.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: cross +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Returns the cross product of two vectors. The cross product is a vector + + that points straight out of the plane created by two vectors. The cross + + product's magnitude is the area of the parallelogram formed by the original + + two vectors.

+ +

The static version of cross(), as in p5.Vector.cross(v1, + v2), is the same + + as calling v1.cross(v2).

+line: 1192 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v1 = createVector(1, 0); + let v2 = createVector(3, 4); + let cp = v1.cross(v2); + // Prints "p5.Vector Object : [0, 0, 4]" to the console. + print(cp.toString()); + +
+ +
+ + let v1 = createVector(1, 0); + let v2 = createVector(3, 4); + let cp = p5.Vector.cross(v1, v2); + // Prints "p5.Vector Object : [0, 0, 4]" to the console. + print(cp.toString()); + +
+return: + description: cross product as a p5.Vector. + type: p5.Vector +chainable: false +--- + + +# cross diff --git a/src/content/reference/en/p5.Vector/dist.mdx b/src/content/reference/en/p5.Vector/dist.mdx new file mode 100644 index 0000000000..51b7856733 --- /dev/null +++ b/src/content/reference/en/p5.Vector/dist.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dist +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Returns the distance between two points represented by vectors. A point's + + coordinates can be thought of as a vector's components.

+ +

The static version of dist(), as in p5.Vector.dist(v1, + v2), is the same + + as calling v1.dist(v2).

+ +

Use dist() to calculate the distance between points + + using coordinates as in dist(x1, y1, x2, y2).

+line: 1236 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v1 = createVector(1, 0); + let v2 = createVector(0, 1); + let d = v1.dist(v2); + // Prints "1.414..." to the console. + print(d); + +
+ +
+ + let v1 = createVector(1, 0); + let v2 = createVector(0, 1); + let d = p5.Vector.dist(v1, v2); + // Prints "1.414..." to the console. + print(d); + +
+ +
+ + function draw() { + background(200); + + let origin = createVector(0, 0); + let v1 = createVector(50, 50); + drawArrow(origin, v1, 'red'); + + let v2 = createVector(20, 70); + drawArrow(origin, v2, 'blue'); + + let v3 = p5.Vector.sub(v2, v1); + drawArrow(v1, v3, 'purple'); + + let m = floor(v3.mag()); + text(m, 50, 75); + + describe('Three arrows drawn on a gray square. A red and a blue arrow extend from the top left. A purple arrow extends from the tip of the red arrow to the tip of the blue arrow. The number 36 is written in black near the purple arrow.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: distance. + type: Number +chainable: false +--- + + +# dist diff --git a/src/content/reference/en/p5.Vector/div.mdx b/src/content/reference/en/p5.Vector/div.mdx new file mode 100644 index 0000000000..d38d9662ff --- /dev/null +++ b/src/content/reference/en/p5.Vector/div.mdx @@ -0,0 +1,199 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: div +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Divides a vector's x, y, and z + components by the same number, + + separate numbers, the components of another + + p5.Vector object, or an array of numbers. Calling + + div() with no arguments has no effect.

+ +

The static version of div(), as in p5.Vector.div(v, + 2), returns a new + + p5.Vector object and doesn't change the + + originals.

+line: 822 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + strokeWeight(5); + + + let p = createVector(50, 50); + + point(p); + + + p.div(2); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(50, 75); + + point(p); + + + p.div(2, 3); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(50, 75); + + point(p); + + + let arr = [2, 3]; + + p.div(arr); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(50, 75); + + point(p); + + + let p2 = createVector(2, 3); + + p.div(p2); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(50, 75); + + point(p); + + + let p2 = createVector(2, 3); + + let p3 = p5.Vector.div(p, p2); + + point(p3); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + function draw() { + background(200); + + let origin = createVector(0, 0); + let v1 = createVector(50, 50); + drawArrow(origin, v1, 'red'); + + let v2 = p5.Vector.div(v1, 2); + drawArrow(origin, v2, 'blue'); + + describe('Two arrows extending from the top left corner. The blue arrow is half the length of the red arrow.'); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+chainable: true +--- + + +# div diff --git a/src/content/reference/en/p5.Vector/dot.mdx b/src/content/reference/en/p5.Vector/dot.mdx new file mode 100644 index 0000000000..9071af6868 --- /dev/null +++ b/src/content/reference/en/p5.Vector/dot.mdx @@ -0,0 +1,99 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dot +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Returns the dot product of two vectors. The dot product is a number that + + describes the overlap between two vectors. Visually, the dot product can be + + thought of as the "shadow" one vector casts on another. The dot product's + + magnitude is largest when two vectors point in the same or opposite + + directions. Its magnitude is 0 when two vectors form a right angle.

+ +

The version of dot() with one parameter interprets it as + another + + p5.Vector object.

+ +

The version of dot() with multiple parameters interprets them + as the + + x, y, and z components of another + vector.

+ +

The static version of dot(), as in p5.Vector.dot(v1, + v2), is the same + + as calling v1.dot(v2).

+line: 1103 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v1 = createVector(3, 4); + let v2 = createVector(3, 0); + let dp = v1.dot(v2); + // Prints "9" to the console. + print(dp); + +
+ +
+ + let v1 = createVector(1, 0); + let v2 = createVector(0, 1); + let dp = p5.Vector.dot(v1, v2); + // Prints "0" to the console. + print(dp); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(width / 2, height / 2); + let v1 = createVector(30, 0); + drawArrow(v0, v1, 'black'); + + let v2 = createVector(mouseX - width / 2, mouseY - height / 2); + drawArrow(v0, v2, 'red'); + + let dp = v2.dot(v1); + text(`v2 • v1 = ${dp}`, 15, 20); + + describe('Two arrows drawn on a gray square. A black arrow points to the right and a red arrow follows the mouse. The text "v1 • v2 = something" changes as the mouse moves.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: dot product. + type: Number +chainable: false +--- + + +# dot diff --git a/src/content/reference/en/p5.Vector/equals.mdx b/src/content/reference/en/p5.Vector/equals.mdx new file mode 100644 index 0000000000..352958ad5e --- /dev/null +++ b/src/content/reference/en/p5.Vector/equals.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: equals +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Returns true if the vector's components are all the same as + another + + vector's and false if not.

+ +

The version of equals() with one parameter interprets it as + another + + p5.Vector object.

+ +

The version of equals() with multiple parameters interprets + them as the + + components of another vector. Any missing parameters are assigned the value + + 0.

+ +

The static version of equals(), as in + p5.Vector.equals(v0, v1), + + interprets both parameters as p5.Vector objects.

+line: 2268 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v0 = createVector(10, 20, 30); + let v1 = createVector(10, 20, 30); + let v2 = createVector(0, 0, 0); + + // Prints "true" to the console. + print(v0.equals(v1)); + // Prints "false" to the console. + print(v0.equals(v2)); + +
+ +
+ + let v0 = createVector(5, 10, 20); + let v1 = createVector(5, 10, 20); + let v2 = createVector(13, 10, 19); + + // Prints "true" to the console. + print(v0.equals(v1.x, v1.y, v1.z)); + // Prints "false" to the console. + print(v0.equals(v2.x, v2.y, v2.z)); + +
+ +
+ + let v0 = createVector(10, 20, 30); + let v1 = createVector(10, 20, 30); + let v2 = createVector(0, 0, 0); + + // Prints "true" to the console. + print(p5.Vector.equals(v0, v1)); + // Prints "false" to the console. + print(p5.Vector.equals(v0, v2)); + +
+return: + description: whether the vectors are equal. + type: Boolean +chainable: false +--- + + +# equals diff --git a/src/content/reference/en/p5.Vector/fromAngle.mdx b/src/content/reference/en/p5.Vector/fromAngle.mdx new file mode 100644 index 0000000000..9b9ac53b95 --- /dev/null +++ b/src/content/reference/en/p5.Vector/fromAngle.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: fromAngle +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Make a new 2D vector from an angle.

+line: 2352 +params: + - name: angle + description: > +

desired angle, in radians. Unaffected by angleMode().

+ type: Number + - name: length + description: | +

length of the new vector (defaults to 1).

+ type: Number + optional: true +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = p5.Vector.fromAngle(0); + // Prints "p5.Vector Object : [1, 0, 0]" to the console. + print(v.toString()); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(50, 50); + let v1 = p5.Vector.fromAngle(0, 30); + + drawArrow(v0, v1, 'black'); + + describe('A black arrow extends from the center of a gray square. It points to the right.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: new p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# fromAngle diff --git a/src/content/reference/en/p5.Vector/fromAngles.mdx b/src/content/reference/en/p5.Vector/fromAngles.mdx new file mode 100644 index 0000000000..7b9b4f2ce5 --- /dev/null +++ b/src/content/reference/en/p5.Vector/fromAngles.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: fromAngles +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Make a new 3D vector from a pair of ISO spherical angles.

+line: 2405 +params: + - name: theta + description: | +

polar angle in radians (zero is up).

+ type: Number + - name: phi + description: | +

azimuthal angle in radians + (zero is out of the screen).

+ type: Number + - name: length + description: | +

length of the new vector (defaults to 1).

+ type: Number + optional: true +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = p5.Vector.fromAngles(0, 0); + // Prints "p5.Vector Object : [0, -1, 0]" to the console. + print(v.toString()); + +
+ +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(0); + + fill(255); + noStroke(); + + let theta = frameCount * 0.05; + let phi = 0; + let v = p5.Vector.fromAngles(theta, phi, 100); + let c = color('deeppink'); + pointLight(c, v); + + sphere(35); + + describe('A light shines on a pink sphere as it orbits.'); + } + +
+return: + description: new p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# fromAngles diff --git a/src/content/reference/en/p5.Vector/heading.mdx b/src/content/reference/en/p5.Vector/heading.mdx new file mode 100644 index 0000000000..c4634f56fe --- /dev/null +++ b/src/content/reference/en/p5.Vector/heading.mdx @@ -0,0 +1,95 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: heading +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Calculates the angle a 2D vector makes with the positive x-axis. Angles + + increase in the clockwise direction.

+ +

If the vector was created with + + createVector(), heading() returns + angles + + in the units of the current angleMode().

+ +

The static version of heading(), as in + p5.Vector.heading(v), works the + + same way.

+line: 1530 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(1, 1); + // Prints "0.785..." to the console. + print(v.heading()); + + angleMode(DEGREES); + // Prints "45" to the console. + print(v.heading()); + +
+ +
+ + let v = createVector(1, 1); + // Prints "0.785..." to the console. + print(p5.Vector.heading(v)); + + angleMode(DEGREES); + // Prints "45" to the console. + print(p5.Vector.heading(v)); + +
+ +
+ + function draw() { + background(200); + + let origin = createVector(0, 0); + let v = createVector(50, 50); + + drawArrow(origin, v, 'black'); + + angleMode(RADIANS); + let h = round(v.heading(), 2); + text(`Radians: ${h}`, 20, 70); + angleMode(DEGREES); + h = v.heading(); + text(`Degrees: ${h}`, 20, 85); + + describe('A black arrow extends from the top left of a square to its center. The text "Radians: 0.79" and "Degrees: 45" is written near the tip of the arrow.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: angle of rotation. + type: Number +chainable: false +--- + + +# heading diff --git a/src/content/reference/en/p5.Vector/lerp.mdx b/src/content/reference/en/p5.Vector/lerp.mdx new file mode 100644 index 0000000000..765b21b448 --- /dev/null +++ b/src/content/reference/en/p5.Vector/lerp.mdx @@ -0,0 +1,97 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lerp +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Calculates new x, y, and z + components that are proportionally the + + same distance between two vectors. The amt parameter is the + amount to + + interpolate between the old vector and the new vector. 0.0 keeps all + + components equal to the old vector's, 0.5 is halfway between, and 1.0 sets + + all components equal to the new vector's.

+ +

The static version of lerp(), as in p5.Vector.lerp(v0, + v1, 0.5), + + returns a new p5.Vector object and doesn't change + + the original.

+line: 1911 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v0 = createVector(1, 1, 1); + let v1 = createVector(3, 3, 3); + v0.lerp(v1, 0.5); + // Prints "p5.Vector Object : [2, 2, 2]" to the console. + print(v0.toString()); + +
+ +
+ + let v = createVector(1, 1, 1); + v.lerp(3, 3, 3, 0.5); + // Prints "p5.Vector Object : [2, 2, 2]" to the console. + print(v.toString()); + +
+ +
+ + let v0 = createVector(1, 1, 1); + let v1 = createVector(3, 3, 3); + let v2 = p5.Vector.lerp(v0, v1, 0.5); + // Prints "p5.Vector Object : [2, 2, 2]" to the console. + print(v2.toString()); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(50, 50); + let v1 = createVector(30, 0); + let v2 = createVector(0, 30); + let v3 = p5.Vector.lerp(v1, v2, 0.5); + + drawArrow(v0, v1, 'red'); + drawArrow(v0, v2, 'blue'); + drawArrow(v0, v3, 'purple'); + + describe('Three arrows extend from the center of a gray square. A red arrow points to the right, a blue arrow points down, and a purple arrow points to the bottom right.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+chainable: true +--- + + +# lerp diff --git a/src/content/reference/en/p5.Vector/limit.mdx b/src/content/reference/en/p5.Vector/limit.mdx new file mode 100644 index 0000000000..0343cf9d58 --- /dev/null +++ b/src/content/reference/en/p5.Vector/limit.mdx @@ -0,0 +1,100 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: limit +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Limits a vector's magnitude to a maximum value.

+ +

The static version of limit(), as in p5.Vector.limit(v, + 5), returns a + + new p5.Vector object and doesn't change the + + original.

+line: 1388 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + let v = createVector(10, 20, 2); + + v.limit(5); + + // Prints "p5.Vector Object : [2.227..., 4.454..., 0.445...]" to the + console. + + print(v.toString()); + + + +
+ + +
+ + + + let v0 = createVector(10, 20, 2); + + let v1 = p5.Vector.limit(v0, 5); + + // Prints "p5.Vector Object : [2.227..., 4.454..., 0.445...]" to the + console. + + print(v1.toString()); + + + +
+ + +
+ + + + function draw() { + background(240); + + let v0 = createVector(50, 50); + let v1 = createVector(mouseX - 50, mouseY - 50); + + let r = 25; + drawArrow(v0, v1, 'red'); + drawArrow(v0, v1.limit(r), 'blue'); + + noFill(); + circle(50, 50, r * 2); + + describe("A red and blue arrow extend from the center of a circle. Both arrows follow the mouse, but the blue arrow never crosses the circle's edge."); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+chainable: true +--- + + +# limit diff --git a/src/content/reference/en/p5.Vector/mag.mdx b/src/content/reference/en/p5.Vector/mag.mdx new file mode 100644 index 0000000000..7b4522beb7 --- /dev/null +++ b/src/content/reference/en/p5.Vector/mag.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mag +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Returns the magnitude (length) of the vector.

+line: 1056 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + let p = createVector(30, 40); + + line(0, 0, p.x, p.y); + + + let m = p.mag(); + + text(m, p.x, p.y); + + + describe('A diagonal black line extends from the top left corner of a gray + square. The number 50 is written at the end of the line.'); + + + +
+return: + description: magnitude of the vector. + type: Number +chainable: false +--- + + +# mag diff --git a/src/content/reference/en/p5.Vector/magSq.mdx b/src/content/reference/en/p5.Vector/magSq.mdx new file mode 100644 index 0000000000..123fad921b --- /dev/null +++ b/src/content/reference/en/p5.Vector/magSq.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: magSq +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Returns the magnitude (length) of the vector squared.

+line: 1078 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + let p = createVector(30, 40); + + line(0, 0, p.x, p.y); + + + let m = p.magSq(); + + text(m, p.x, p.y); + + + describe('A diagonal black line extends from the top left corner of a gray + square. The number 2500 is written at the end of the line.'); + + + +
+return: + description: squared magnitude of the vector. + type: Number +chainable: false +--- + + +# magSq diff --git a/src/content/reference/en/p5.Vector/mult.mdx b/src/content/reference/en/p5.Vector/mult.mdx new file mode 100644 index 0000000000..7a10d4a812 --- /dev/null +++ b/src/content/reference/en/p5.Vector/mult.mdx @@ -0,0 +1,199 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mult +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Multiplies a vector's x, y, and z + components by the same number, + + separate numbers, the components of another + + p5.Vector object, or an array of numbers. Calling + + mult() with no arguments has no effect.

+ +

The static version of mult(), as in p5.Vector.mult(v, + 2), returns a new + + p5.Vector object and doesn't change the + + originals.

+line: 604 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + strokeWeight(5); + + + let p = createVector(25, 25); + + point(p); + + + p.mult(2); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(25, 25); + + point(p); + + + p.mult(2, 3); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(25, 25); + + point(p); + + + let arr = [2, 3]; + + p.mult(arr); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(25, 25); + + point(p); + + + let p2 = createVector(2, 3); + + p.mult(p2); + + point(p); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + strokeWeight(5); + + + let p = createVector(25, 25); + + point(p); + + + let p2 = createVector(2, 3); + + let p3 = p5.Vector.mult(p, p2); + + point(p3); + + + describe('Two black dots drawn on a gray square. One dot is in the top left + corner and the other is in the bottom center.'); + + + +
+ + +
+ + + + function draw() { + background(200); + + let origin = createVector(0, 0); + let v1 = createVector(25, 25); + drawArrow(origin, v1, 'red'); + + let v2 = p5.Vector.mult(v1, 2); + drawArrow(origin, v2, 'blue'); + + describe('Two arrows extending from the top left corner. The blue arrow is twice the length of the red arrow.'); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+chainable: true +--- + + +# mult diff --git a/src/content/reference/en/p5.Vector/normalize.mdx b/src/content/reference/en/p5.Vector/normalize.mdx new file mode 100644 index 0000000000..73f5e34fd1 --- /dev/null +++ b/src/content/reference/en/p5.Vector/normalize.mdx @@ -0,0 +1,110 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: normalize +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Scales the components of a p5.Vector object so + + that its magnitude is 1.

+ +

The static version of normalize(), as in + p5.Vector.normalize(v), + + returns a new p5.Vector object and doesn't change + + the original.

+line: 1314 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + let v = createVector(10, 20, 2); + + v.normalize(); + + // Prints "p5.Vector Object : [0.445..., 0.890..., 0.089...]" to the + console. + + print(v.toString()); + + + +
+ + +
+ + + + let v0 = createVector(10, 20, 2); + + let v1 = p5.Vector.normalize(v0); + + // Prints "p5.Vector Object : [10, 20, 2]" to the console. + + print(v0.toString()); + + // Prints "p5.Vector Object : [0.445..., 0.890..., 0.089...]" to the + console. + + print(v1.toString()); + + + +
+ + +
+ + + + function draw() { + background(240); + + let v0 = createVector(50, 50); + let v1 = createVector(mouseX - 50, mouseY - 50); + + let r = 25; + drawArrow(v0, v1, 'red'); + v1.normalize(); + drawArrow(v0, v1.mult(r), 'blue'); + + noFill(); + circle(50, 50, r * 2); + + describe("A red and blue arrow extend from the center of a circle. Both arrows follow the mouse, but the blue arrow's length is fixed to the circle's radius."); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+return: + description: normalized p5.Vector. + type: p5.Vector +chainable: false +--- + + +# normalize diff --git a/src/content/reference/en/p5.Vector/random2D.mdx b/src/content/reference/en/p5.Vector/random2D.mdx new file mode 100644 index 0000000000..b3f1e8e808 --- /dev/null +++ b/src/content/reference/en/p5.Vector/random2D.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: random2D +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Make a new 2D unit vector with a random heading.

+line: 2465 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = p5.Vector.random2D(); + // Prints "p5.Vector Object : [x, y, 0]" to the console + // where x and y are small random numbers. + print(v.toString()); + +
+ +
+ + function draw() { + background(200); + + frameRate(1); + + let v0 = createVector(50, 50); + let v1 = p5.Vector.random2D(); + v1.mult(30); + drawArrow(v0, v1, 'black'); + + describe('A black arrow in extends from the center of a gray square. It changes direction once per second.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: new p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# random2D diff --git a/src/content/reference/en/p5.Vector/random3D.mdx b/src/content/reference/en/p5.Vector/random3D.mdx new file mode 100644 index 0000000000..3cd00d9eb4 --- /dev/null +++ b/src/content/reference/en/p5.Vector/random3D.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: random3D +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Make a new 3D unit vector with a random heading.

+line: 2516 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = p5.Vector.random3D(); + // Prints "p5.Vector Object : [x, y, z]" to the console + // where x, y, and z are small random numbers. + print(v.toString()); + +
+return: + description: new p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# random3D diff --git a/src/content/reference/en/p5.Vector/reflect.mdx b/src/content/reference/en/p5.Vector/reflect.mdx new file mode 100644 index 0000000000..1e97a46aa7 --- /dev/null +++ b/src/content/reference/en/p5.Vector/reflect.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reflect +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Reflects a vector about a line in 2D or a plane in 3D. The orientation of + + the line or plane is described by a normal vector that points away from the + + shape.

+ +

The static version of reflect(), as in + p5.Vector.reflect(v, n), + + returns a new p5.Vector object and doesn't change + + the original.

+line: 2175 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let n = createVector(0, 1); + let v = createVector(4, 6); + v.reflect(n); + // Prints "p5.Vector Object : [4, -6, 0]" to the console. + print(v.toString()); + +
+ +
+ + let n = createVector(0, 1); + let v0 = createVector(4, 6); + let v1 = p5.Vector.reflect(v0, n); + // Prints "p5.Vector Object : [4, -6, 0]" to the console. + print(v1.toString()); + +
+ +
+ + function draw() { + background(200); + + line(50, 0, 50, 100); + let n = createVector(1, 0); + + let v0 = createVector(50, 50); + let v1 = createVector(30, 40); + let v2 = p5.Vector.reflect(v1, n); + + n.setMag(30); + drawArrow(v0, n, 'black'); + drawArrow(v0, v1, 'red'); + drawArrow(v0, v2, 'blue'); + + describe('Three arrows extend from the center of a gray square with a vertical line down its middle. A black arrow points to the right, a blue arrow points to the bottom left, and a red arrow points to the bottom right.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+chainable: true +--- + + +# reflect diff --git a/src/content/reference/en/p5.Vector/rem.mdx b/src/content/reference/en/p5.Vector/rem.mdx new file mode 100644 index 0000000000..c9969ee08e --- /dev/null +++ b/src/content/reference/en/p5.Vector/rem.mdx @@ -0,0 +1,72 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rem +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Performs modulo (remainder) division with a vector's x, + y, and z + + components using separate numbers, another + + p5.Vector object, or an array of numbers.

+ +

The static version of rem() as in p5.Vector.rem(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+line: 368 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(3, 4, 5); + v.rem(2, 3, 4); + // Prints 'p5.Vector Object : [1, 1, 1]'. + print(v.toString()); + +
+ +
+ + let v1 = createVector(3, 4, 5); + let v2 = createVector(2, 3, 4); + v1.rem(v2); + + // Prints 'p5.Vector Object : [1, 1, 1]'. + print(v1.toString()); + +
+ +
+ + let v = createVector(3, 4, 5); + let arr = [2, 3, 4]; + v.rem(arr); + + // Prints 'p5.Vector Object : [1, 1, 1]'. + print(v.toString()); + +
+ +
+ + let v1 = createVector(3, 4, 5); + let v2 = createVector(2, 3, 4); + let v3 = p5.Vector.rem(v1, v2); + + // Prints 'p5.Vector Object : [1, 1, 1]'. + print(v3.toString()); + +
+chainable: true +--- + + +# rem diff --git a/src/content/reference/en/p5.Vector/rotate.mdx b/src/content/reference/en/p5.Vector/rotate.mdx new file mode 100644 index 0000000000..eed636dbe6 --- /dev/null +++ b/src/content/reference/en/p5.Vector/rotate.mdx @@ -0,0 +1,117 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotate +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Rotates a 2D vector by an angle without changing its magnitude. + + By convention, the positive x-axis has an angle of 0. Angles increase in + + the clockwise direction.

+ +

If the vector was created with + + createVector(), rotate() uses + + the units of the current angleMode().

+ +

The static version of rotate(), as in + p5.Vector.rotate(v, PI), + + returns a new p5.Vector object and doesn't change + + the original.

+line: 1689 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(1, 0); + // Prints "p5.Vector Object : [1, 0, 0]" to the console. + print(v.toString()); + v.rotate(HALF_PI); + // Prints "p5.Vector Object : [0, 1, 0]" to the console. + print(v.toString()); + +
+ +
+ + angleMode(DEGREES); + let v = createVector(1, 0); + // Prints "p5.Vector Object : [1, 0, 0]" to the console. + print(v.toString()); + v.rotate(90); + // Prints "p5.Vector Object : [0, 1, 0]" to the console. + print(v.toString()); + +
+ +
+ + let v0 = createVector(1, 0); + let v1 = p5.Vector.rotate(v0, HALF_PI); + // Prints "p5.Vector Object : [1, 0, 0]" to the console. + print(v0.toString()); + // Prints "p5.Vector Object : [0, 1, 0]" to the console. + print(v1.toString()); + +
+ +
+ + angleMode(DEGREES); + let v0 = createVector(1, 0); + let v1 = p5.Vector.rotate(v0, 90); + // Prints "p5.Vector Object : [1, 0, 0]" to the console. + print(v0.toString()); + // Prints "p5.Vector Object : [0, 1, 0]" to the console. + print(v1.toString()); + +
+ +
+ + let v0; + let v1; + + function setup() { + v0 = createVector(50, 50); + v1 = createVector(30, 0); + } + + function draw() { + background(240); + + v1.rotate(0.01); + + drawArrow(v0, v1, 'black'); + + describe('A black arrow extends from the center of a gray square. The arrow rotates clockwise.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+chainable: true +--- + + +# rotate diff --git a/src/content/reference/en/p5.Vector/set.mdx b/src/content/reference/en/p5.Vector/set.mdx new file mode 100644 index 0000000000..f242d8b217 --- /dev/null +++ b/src/content/reference/en/p5.Vector/set.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Sets the x, y, and z components of + the vector using separate numbers, + + a p5.Vector object, or an array of numbers. + + Calling set() with no arguments sets the vector's components to + 0.

+line: 156 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + strokeWeight(5); + + // Top left. + let pos = createVector(25, 25); + point(pos); + + // Top right. + pos.set(75, 25); + point(pos); + + // Bottom right. + let p2 = createVector(75, 75); + pos.set(p2); + point(pos); + + // Bottom left. + let arr = [25, 75]; + pos.set(arr); + point(pos); + + describe('Four black dots arranged in a square on a gray background.'); + +
+chainable: true +--- + + +# set diff --git a/src/content/reference/en/p5.Vector/setHeading.mdx b/src/content/reference/en/p5.Vector/setHeading.mdx new file mode 100644 index 0000000000..28fa552e51 --- /dev/null +++ b/src/content/reference/en/p5.Vector/setHeading.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setHeading +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Rotates a 2D vector to a specific angle without changing its magnitude. + By convention, the positive x-axis has an angle of 0. Angles increase in + the clockwise direction.

+

If the vector was created with + createVector(), setHeading() uses + the units of the current angleMode().

+line: 1610 +params: + - name: angle + description: | +

angle of rotation.

+ type: Number +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(0, 1); + // Prints "1.570..." to the console. + print(v.heading()); + + v.setHeading(PI); + // Prints "3.141..." to the console. + print(v.heading()); + +
+ +
+ + angleMode(DEGREES); + let v = createVector(0, 1); + // Prints "90" to the console. + print(v.heading()); + + v.setHeading(180); + // Prints "180" to the console. + print(v.heading()); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(50, 50); + let v1 = createVector(30, 0); + + drawArrow(v0, v1, 'red'); + + v1.setHeading(HALF_PI); + drawArrow(v0, v1, 'blue'); + + describe('Two arrows extend from the center of a gray square. The red arrow points to the right and the blue arrow points down.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+chainable: true +--- + + +# setHeading diff --git a/src/content/reference/en/p5.Vector/setMag.mdx b/src/content/reference/en/p5.Vector/setMag.mdx new file mode 100644 index 0000000000..f93a25cd56 --- /dev/null +++ b/src/content/reference/en/p5.Vector/setMag.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setMag +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Sets a vector's magnitude to a given value.

+ +

The static version of setMag(), as in + p5.Vector.setMag(v, 10), returns + + a new p5.Vector object and doesn't change the + + original.

+line: 1460 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v = createVector(3, 4, 0); + // Prints "5" to the console. + print(v.mag()); + + v.setMag(10); + // Prints "p5.Vector Object : [6, 8, 0]" to the console. + print(v.toString()); + +
+ +
+ + let v0 = createVector(3, 4, 0); + let v1 = p5.Vector.setMag(v0, 10); + // Prints "5" to the console. + print(v0.mag()); + // Prints "p5.Vector Object : [6, 8, 0]" to the console. + print(v1.toString()); + +
+ +
+ + function draw() { + background(240); + + let origin = createVector(0, 0); + let v = createVector(50, 50); + + drawArrow(origin, v, 'red'); + + v.setMag(30); + drawArrow(origin, v, 'blue'); + + describe('Two arrows extend from the top left corner of a square toward its center. The red arrow reaches the center and the blue arrow only extends part of the way.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+chainable: true +--- + + +# setMag diff --git a/src/content/reference/en/p5.Vector/slerp.mdx b/src/content/reference/en/p5.Vector/slerp.mdx new file mode 100644 index 0000000000..22ad10fb6c --- /dev/null +++ b/src/content/reference/en/p5.Vector/slerp.mdx @@ -0,0 +1,125 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: slerp +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Calculates a new heading and magnitude that are between two vectors. The + + amt parameter is the amount to interpolate between the old vector + and + + the new vector. 0.0 keeps the heading and magnitude equal to the old + + vector's, 0.5 sets them halfway between, and 1.0 sets the heading and + + magnitude equal to the new vector's.

+ +

slerp() differs from lerp() + because + + it interpolates magnitude. Calling v0.slerp(v1, 0.5) sets + v0's + + magnitude to a value halfway between its original magnitude and + v1's. + + Calling v0.lerp(v1, 0.5) makes no such guarantee.

+ +

The static version of slerp(), as in p5.Vector.slerp(v0, + v1, 0.5), + + returns a new p5.Vector object and doesn't change + + the original.

+line: 2009 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + let v0 = createVector(3, 0); + // Prints "3" to the console. + print(v0.mag()); + // Prints "0" to the console. + print(v0.heading()); + + let v1 = createVector(0, 1); + // Prints "1" to the console. + print(v1.mag()); + // Prints "1.570..." to the console. + print(v1.heading()); + + v0.slerp(v1, 0.5); + // Prints "2" to the console. + print(v0.mag()); + // Prints "0.785..." to the console. + print(v0.heading()); + +
+ +
+ + let v0 = createVector(3, 0); + // Prints "3" to the console. + print(v0.mag()); + // Prints "0" to the console. + print(v0.heading()); + + let v1 = createVector(0, 1); + // Prints "1" to the console. + print(v1.mag()); + // Prints "1.570..." to the console. + print(v1.heading()); + + let v3 = p5.Vector.slerp(v0, v1, 0.5); + // Prints "2" to the console. + print(v3.mag()); + // Prints "0.785..." to the console. + print(v3.heading()); + +
+ +
+ + function draw() { + background(200); + + let v0 = createVector(50, 50); + let v1 = createVector(20, 0); + let v2 = createVector(-40, 0); + let v3 = p5.Vector.slerp(v1, v2, 0.5); + + drawArrow(v0, v1, 'red'); + drawArrow(v0, v2, 'blue'); + drawArrow(v0, v3, 'purple'); + + describe('Three arrows extend from the center of a gray square. A red arrow points to the right, a blue arrow points to the left, and a purple arrow points down.'); + } + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + +
+return: + description: '' + type: p5.Vector +chainable: false +--- + + +# slerp diff --git a/src/content/reference/en/p5.Vector/sub.mdx b/src/content/reference/en/p5.Vector/sub.mdx new file mode 100644 index 0000000000..9f8cb826b9 --- /dev/null +++ b/src/content/reference/en/p5.Vector/sub.mdx @@ -0,0 +1,151 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sub +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

Subtracts from a vector's x, y, and + z components using separate + + numbers, another p5.Vector object, or an array of + + numbers. Calling sub() with no arguments has no effect.

+ +

The static version of sub(), as in p5.Vector.sub(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+line: 485 +itemtype: method +class: p5.Vector +example: + - >- + +
+ + + + strokeWeight(5); + + + // Bottom right. + + let pos = createVector(75, 75); + + point(pos); + + + // Top right. + + pos.sub(0, 50); + + point(pos); + + + // Top left. + + let p2 = createVector(50, 0); + + pos.sub(p2); + + point(pos); + + + // Bottom left. + + let arr = [0, -50]; + + pos.sub(arr); + + point(pos); + + + describe('Four black dots arranged in a square on a gray background.'); + + + +
+ + +
+ + + + // Bottom right. + + let p1 = createVector(75, 75); + + + // Center. + + let p2 = createVector(50, 50); + + + // Top left. + + let p3 = p5.Vector.sub(p1, p2); + + + strokeWeight(5); + + point(p1); + + point(p2); + + point(p3); + + + describe('Three black dots in a diagonal line from top left to bottom + right.'); + + + +
+ + +
+ + + + function draw() { + background(200); + + let origin = createVector(0, 0); + let v1 = createVector(50, 50); + drawArrow(origin, v1, 'red'); + + let v2 = createVector(20, 70); + drawArrow(origin, v2, 'blue'); + + let v3 = p5.Vector.sub(v2, v1); + drawArrow(v1, v3, 'purple'); + + describe('Three arrows drawn on a gray square. A red and a blue arrow extend from the top left. A purple arrow extends from the tip of the red arrow to the tip of the blue arrow.'); + } + + + function drawArrow(base, vec, myColor) { + push(); + stroke(myColor); + strokeWeight(3); + fill(myColor); + translate(base.x, base.y); + line(0, 0, vec.x, vec.y); + rotate(vec.heading()); + let arrowSize = 7; + translate(vec.mag() - arrowSize, 0); + triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + pop(); + } + + + +
+chainable: true +--- + + +# sub diff --git a/src/content/reference/en/p5.Vector/toString.mdx b/src/content/reference/en/p5.Vector/toString.mdx new file mode 100644 index 0000000000..ce44cd0f77 --- /dev/null +++ b/src/content/reference/en/p5.Vector/toString.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: toString +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

Returns a string representation of a vector. This method is useful for + printing vectors to the console while debugging.

+line: 136 +itemtype: method +class: p5.Vector +example: + - |- + +
+ + function setup() { + let v = createVector(20, 30); + // Prints 'p5.Vector Object : [20, 30, 0]'. + print(v.toString()); + } + +
+return: + description: string representation of the vector. + type: String +chainable: false +--- + + +# toString diff --git a/src/content/reference/en/p5.Vector/x.mdx b/src/content/reference/en/p5.Vector/x.mdx new file mode 100644 index 0000000000..da989c4a5d --- /dev/null +++ b/src/content/reference/en/p5.Vector/x.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: x +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

The x component of the vector

+line: 113 +itemtype: property +class: p5.Vector +chainable: false +--- + + +# x diff --git a/src/content/reference/en/p5.Vector/y.mdx b/src/content/reference/en/p5.Vector/y.mdx new file mode 100644 index 0000000000..d1b3fb6dc6 --- /dev/null +++ b/src/content/reference/en/p5.Vector/y.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: 'y' +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

The y component of the vector

+line: 120 +itemtype: property +class: p5.Vector +chainable: false +--- + + +# y diff --git a/src/content/reference/en/p5.Vector/z.mdx b/src/content/reference/en/p5.Vector/z.mdx new file mode 100644 index 0000000000..4717e00dbf --- /dev/null +++ b/src/content/reference/en/p5.Vector/z.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: z +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: | +

The z component of the vector

+line: 127 +itemtype: property +class: p5.Vector +chainable: false +--- + + +# z diff --git a/src/content/reference/en/p5.XML/addChild.mdx b/src/content/reference/en/p5.XML/addChild.mdx new file mode 100644 index 0000000000..2511694261 --- /dev/null +++ b/src/content/reference/en/p5.XML/addChild.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: addChild +module: IO +submodule: Input +file: src/io/p5.XML.js +description: > +

Appends a new child to the element. The child can be specified with + + either a String, which will be used as the new tag's name, or as a + + reference to an existing p5.XML object. + + A reference to the newly created child is returned as an p5.XML object.

+line: 368 +params: + - name: node + description: > +

a p5.XML Object which will be the child to be + added

+ type: p5.XML +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let child = new p5.XML(); + child.setName('animal'); + child.setAttribute('id', '3'); + child.setAttribute('species', 'Ornithorhynchus anatinus'); + child.setContent('Platypus'); + xml.addChild(child); + + let animals = xml.getChildren('animal'); + print(animals[animals.length - 1].getContent()); + } + + // Sketch prints: + // "Goat" + // "Leopard" + // "Zebra" +
+chainable: false +--- + + +# addChild diff --git a/src/content/reference/en/p5.XML/getAttributeCount.mdx b/src/content/reference/en/p5.XML/getAttributeCount.mdx new file mode 100644 index 0000000000..d911f4c1e3 --- /dev/null +++ b/src/content/reference/en/p5.XML/getAttributeCount.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getAttributeCount +module: IO +submodule: Input +file: src/io/p5.XML.js +description: > +

Counts the specified element's number of attributes, returned as an + Number.

+line: 492 +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getAttributeCount()); + } + + // Sketch prints: + // 2 +
+return: + description: '' + type: Integer +chainable: false +--- + + +# getAttributeCount diff --git a/src/content/reference/en/p5.XML/getChild.mdx b/src/content/reference/en/p5.XML/getChild.mdx new file mode 100644 index 0000000000..8f44c66f0f --- /dev/null +++ b/src/content/reference/en/p5.XML/getChild.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getChild +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Returns the first of the element's children that matches the name parameter + or the child of the given index.It returns undefined if no matching + child is found.

+line: 308 +params: + - name: name + description: | +

element name or index

+ type: String|Integer +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getContent()); + } + + // Sketch prints: + // "Goat" +
+
+ let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let secondChild = xml.getChild(1); + print(secondChild.getContent()); + } + + // Sketch prints: + // "Leopard" +
+return: + description: '' + type: p5.XML +chainable: false +--- + + +# getChild diff --git a/src/content/reference/en/p5.XML/getChildren.mdx b/src/content/reference/en/p5.XML/getChildren.mdx new file mode 100644 index 0000000000..4725a00d69 --- /dev/null +++ b/src/content/reference/en/p5.XML/getChildren.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getChildren +module: IO +submodule: Input +file: src/io/p5.XML.js +description: > +

Returns all of the element's children as an array of p5.XML objects. When + + the name parameter is specified, then it will return all children that match + + that name.

+line: 258 +params: + - name: name + description: | +

element name

+ type: String + optional: true +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let animals = xml.getChildren('animal'); + + for (let i = 0; i < animals.length; i++) { + print(animals[i].getContent()); + } + } + + // Sketch prints: + // "Goat" + // "Leopard" + // "Zebra" +
+return: + description: children of the element + type: 'p5.XML[]' +chainable: false +--- + + +# getChildren diff --git a/src/content/reference/en/p5.XML/getContent.mdx b/src/content/reference/en/p5.XML/getContent.mdx new file mode 100644 index 0000000000..ae2d255c4f --- /dev/null +++ b/src/content/reference/en/p5.XML/getContent.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getContent +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Returns the content of an element. If there is no such content, + defaultValue is returned if specified, otherwise null is returned.

+line: 751 +params: + - name: defaultValue + description: | +

value returned if no content is found

+ type: String + optional: true +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getContent()); + } + + // Sketch prints: + // "Goat" +
+return: + description: '' + type: String +chainable: false +--- + + +# getContent diff --git a/src/content/reference/en/p5.XML/getName.mdx b/src/content/reference/en/p5.XML/getName.mdx new file mode 100644 index 0000000000..ab1fb7ae79 --- /dev/null +++ b/src/content/reference/en/p5.XML/getName.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getName +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Gets the element's full name, which is returned as a String.

+line: 100 +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + print(xml.getName()); + } + + // Sketch prints: + // mammals +
+return: + description: the name of the node + type: String +chainable: false +--- + + +# getName diff --git a/src/content/reference/en/p5.XML/getNum.mdx b/src/content/reference/en/p5.XML/getNum.mdx new file mode 100644 index 0000000000..b9eb5a10ea --- /dev/null +++ b/src/content/reference/en/p5.XML/getNum.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getNum +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Returns an attribute value of the element as an Number. If the defaultValue + parameter is specified and the attribute doesn't exist, then defaultValue + is returned. If no defaultValue is specified and the attribute doesn't + exist, the value 0 is returned.

+line: 616 +params: + - name: name + description: | +

the non-null full name of the attribute

+ type: String + - name: defaultValue + description: | +

the default value of the attribute

+ type: Number + optional: true +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getNum('id')); + } + + // Sketch prints: + // 0 +
+return: + description: '' + type: Number +chainable: false +--- + + +# getNum diff --git a/src/content/reference/en/p5.XML/getParent.mdx b/src/content/reference/en/p5.XML/getParent.mdx new file mode 100644 index 0000000000..535e5f2403 --- /dev/null +++ b/src/content/reference/en/p5.XML/getParent.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getParent +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Gets a copy of the element's parent. Returns the parent as another + p5.XML object.

+line: 62 +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let children = xml.getChildren('animal'); + let parent = children[1].getParent(); + print(parent.getName()); + } + + // Sketch prints: + // mammals +
+return: + description: element parent + type: p5.XML +chainable: false +--- + + +# getParent diff --git a/src/content/reference/en/p5.XML/getString.mdx b/src/content/reference/en/p5.XML/getString.mdx new file mode 100644 index 0000000000..ede8e4f6ea --- /dev/null +++ b/src/content/reference/en/p5.XML/getString.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getString +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Returns an attribute value of the element as an String. If the defaultValue + parameter is specified and the attribute doesn't exist, then defaultValue + is returned. If no defaultValue is specified and the attribute doesn't + exist, null is returned.

+line: 663 +params: + - name: name + description: | +

the non-null full name of the attribute

+ type: String + - name: defaultValue + description: | +

the default value of the attribute

+ type: Number + optional: true +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getString('species')); + } + + // Sketch prints: + // "Capra hircus" +
+return: + description: '' + type: String +chainable: false +--- + + +# getString diff --git a/src/content/reference/en/p5.XML/hasAttribute.mdx b/src/content/reference/en/p5.XML/hasAttribute.mdx new file mode 100644 index 0000000000..b839a09110 --- /dev/null +++ b/src/content/reference/en/p5.XML/hasAttribute.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hasAttribute +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Checks whether or not an element has the specified attribute.

+line: 571 +params: + - name: the + description: | +

attribute to be checked

+ type: String +itemtype: method +class: p5.XML +example: + - |2- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.hasAttribute('species')); + print(firstChild.hasAttribute('color')); + } + + // Sketch prints: + // true + // false +
+return: + description: true if attribute found else false + type: Boolean +chainable: false +--- + + +# hasAttribute diff --git a/src/content/reference/en/p5.XML/hasChildren.mdx b/src/content/reference/en/p5.XML/hasChildren.mdx new file mode 100644 index 0000000000..d211d32599 --- /dev/null +++ b/src/content/reference/en/p5.XML/hasChildren.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hasChildren +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Checks whether or not the element has any children, and returns the result + as a boolean.

+line: 181 +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + print(xml.hasChildren()); + } + + // Sketch prints: + // true +
+return: + description: '' + type: Boolean +chainable: false +--- + + +# hasChildren diff --git a/src/content/reference/en/p5.XML/listAttributes.mdx b/src/content/reference/en/p5.XML/listAttributes.mdx new file mode 100644 index 0000000000..829ae03e25 --- /dev/null +++ b/src/content/reference/en/p5.XML/listAttributes.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: listAttributes +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Gets all of the specified element's attributes, and returns them as an + array of Strings.

+line: 528 +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.listAttributes()); + } + + // Sketch prints: + // ["id", "species"] +
+return: + description: an array of strings containing the names of attributes + type: 'String[]' +chainable: false +--- + + +# listAttributes diff --git a/src/content/reference/en/p5.XML/listChildren.mdx b/src/content/reference/en/p5.XML/listChildren.mdx new file mode 100644 index 0000000000..7e6e9f3499 --- /dev/null +++ b/src/content/reference/en/p5.XML/listChildren.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: listChildren +module: IO +submodule: Input +file: src/io/p5.XML.js +description: > +

Get the names of all of the element's children, and returns the names as an + + array of Strings. This is the same as looping through and calling getName() + + on each child element individually.

+line: 217 +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + print(xml.listChildren()); + } + + // Sketch prints: + // ["animal", "animal", "animal"] +
+return: + description: names of the children of the element + type: 'String[]' +chainable: false +--- + + +# listChildren diff --git a/src/content/reference/en/p5.XML/removeChild.mdx b/src/content/reference/en/p5.XML/removeChild.mdx new file mode 100644 index 0000000000..c88d23fe55 --- /dev/null +++ b/src/content/reference/en/p5.XML/removeChild.mdx @@ -0,0 +1,72 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeChild +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Removes the element specified by name or index.

+line: 420 +params: + - name: name + description: | +

element name or index

+ type: String|Integer +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + xml.removeChild('animal'); + let children = xml.getChildren(); + for (let i = 0; i < children.length; i++) { + print(children[i].getContent()); + } + } + + // Sketch prints: + // "Leopard" + // "Zebra" +
+
+ let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + xml.removeChild(1); + let children = xml.getChildren(); + for (let i = 0; i < children.length; i++) { + print(children[i].getContent()); + } + } + + // Sketch prints: + // "Goat" + // "Zebra" +
+chainable: false +--- + + +# removeChild diff --git a/src/content/reference/en/p5.XML/serialize.mdx b/src/content/reference/en/p5.XML/serialize.mdx new file mode 100644 index 0000000000..5ec5f46ea2 --- /dev/null +++ b/src/content/reference/en/p5.XML/serialize.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: serialize +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Serializes the element into a string. This function is useful for preparing + the content to be sent over a http request or saved to file.

+line: 833 +itemtype: method +class: p5.XML +example: + - |- + +
+ let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + print(xml.serialize()); + } + + // Sketch prints: + // + // Goat + // Leopard + // Zebra + // +
+return: + description: Serialized string of the element + type: String +chainable: false +--- + + +# serialize diff --git a/src/content/reference/en/p5.XML/setAttribute.mdx b/src/content/reference/en/p5.XML/setAttribute.mdx new file mode 100644 index 0000000000..5f906a7076 --- /dev/null +++ b/src/content/reference/en/p5.XML/setAttribute.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setAttribute +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Sets the content of an element's attribute. The first parameter specifies + the attribute name, while the second specifies the new content.

+line: 710 +params: + - name: name + description: | +

the full name of the attribute

+ type: String + - name: value + description: | +

the value of the attribute

+ type: Number|String|Boolean +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getString('species')); + firstChild.setAttribute('species', 'Jamides zebra'); + print(firstChild.getString('species')); + } + + // Sketch prints: + // "Capra hircus" + // "Jamides zebra" +
+chainable: false +--- + + +# setAttribute diff --git a/src/content/reference/en/p5.XML/setContent.mdx b/src/content/reference/en/p5.XML/setContent.mdx new file mode 100644 index 0000000000..abc7a439f0 --- /dev/null +++ b/src/content/reference/en/p5.XML/setContent.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setContent +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Sets the element's content.

+line: 792 +params: + - name: text + description: | +

the new content

+ type: String +itemtype: method +class: p5.XML +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let firstChild = xml.getChild('animal'); + print(firstChild.getContent()); + firstChild.setContent('Mountain Goat'); + print(firstChild.getContent()); + } + + // Sketch prints: + // "Goat" + // "Mountain Goat" +
+chainable: false +--- + + +# setContent diff --git a/src/content/reference/en/p5.XML/setName.mdx b/src/content/reference/en/p5.XML/setName.mdx new file mode 100644 index 0000000000..f29834dcb2 --- /dev/null +++ b/src/content/reference/en/p5.XML/setName.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setName +module: IO +submodule: Input +file: src/io/p5.XML.js +description: | +

Sets the element's name, which is specified as a String.

+line: 135 +params: + - name: the + description: | +

new name of the node

+ type: String +itemtype: method +class: p5.XML +example: + - |- + <animal +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + print(xml.getName()); + xml.setName('fish'); + print(xml.getName()); + } + + // Sketch prints: + // mammals + // fish +
+chainable: false +--- + + +# setName diff --git a/src/content/reference/en/p5.sound/p5.Amplitude.mdx b/src/content/reference/en/p5.sound/p5.Amplitude.mdx new file mode 100644 index 0000000000..9c6f7e4a39 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Amplitude.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Amplitude +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Amplitude measures volume between 0.0 and 1.0. + Listens to all p5sound by default, or use setInput() + to listen to a specific sound source. Accepts an optional + smoothing value, which defaults to 0.

+isConstructor: true +line: 3022 +params: + - name: smoothing + description: | +

between 0.0 and .999 to smooth + amplitude readings (defaults to 0)

+ type: Number + optional: true +memberMethodPreviews: + setInput: + description: | +

Connects to the p5sound instance (main output) by default. + Optionally, you can pass in a specific source (i.e. a soundfile).

+ path: .././src/content/reference/en//p5.Amplitude/setInput + getLevel: + description: | +

Returns a single Amplitude reading at the moment it is called. + For continuous readings, run in the draw loop.

+ path: .././src/content/reference/en//p5.Amplitude/getLevel + toggleNormalize: + description: | +

Determines whether the results of Amplitude.process() will be + Normalized. To normalize, Amplitude finds the difference the + loudest reading it has processed and the maximum amplitude of + 1.0. Amplitude adds this difference to all values to produce + results that will reliably map between 0.0 and 1.0. However, + if a louder moment occurs, the amount that Normalize adds to + all the values will change. Accepts an optional boolean parameter + (true or false). Normalizing is off by default.

+ path: .././src/content/reference/en//p5.Amplitude/toggleNormalize + smooth: + description: | +

Smooth Amplitude analysis by averaging with the last analysis + frame. Off by default.

+ path: .././src/content/reference/en//p5.Amplitude/smooth +--- + + +# p5.Amplitude diff --git a/src/content/reference/en/p5.sound/p5.AudioIn.mdx b/src/content/reference/en/p5.sound/p5.AudioIn.mdx new file mode 100644 index 0000000000..00c32467f0 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.AudioIn.mdx @@ -0,0 +1,112 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.AudioIn +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: >- +

Get audio from an input, i.e. your computer's microphone.

+ + +

Turn the mic on/off with the start() and stop() methods. When the mic + + is on, its volume can be measured with getLevel or by connecting an + + FFT object.

+ + +

If you want to hear the AudioIn, use the .connect() method. + + AudioIn does not connect to p5.sound output by default to prevent + + feedback.

+ + +

Note: This uses the getUserMedia/ + + Stream API, which is not supported by certain browsers. Access in Chrome + browser + + is limited to localhost and https, but access over http may be + limited.

+isConstructor: true +line: 6015 +params: + - name: errorCallback + description: | +

A function to call if there is an error + accessing the AudioIn. For example, + Safari and iOS devices do not + currently allow microphone access.

+ type: Function + optional: true +memberMethodPreviews: + enabled: + description: | +

Client must allow browser to access their microphone / audioin source. + Default: false. Will become true when the client enables access.

+ path: .././src/content/reference/en//p5.AudioIn/enabled + amplitude: + description: | +

Input amplitude, connect to it by default but not to master out

+ path: .././src/content/reference/en//p5.AudioIn/amplitude + start: + description: | +

Start processing audio input. This enables the use of other + AudioIn methods like getLevel(). Note that by default, AudioIn + is not connected to p5.sound's output. So you won't hear + anything unless you use the connect() method.

+

Certain browsers limit access to the user's microphone. For example, + Chrome only allows access from localhost and over https. For this reason, + you may want to include an errorCallback—a function that is called in case + the browser won't provide mic access.

+ path: .././src/content/reference/en//p5.AudioIn/start + stop: + description: | +

Turn the AudioIn off. If the AudioIn is stopped, it cannot getLevel(). + If re-starting, the user may be prompted for permission access.

+ path: .././src/content/reference/en//p5.AudioIn/stop + connect: + description: | +

Connect to an audio unit. If no parameter is provided, will + connect to the main output (i.e. your speakers).

+ path: .././src/content/reference/en//p5.AudioIn/connect + disconnect: + description: | +

Disconnect the AudioIn from all audio units. For example, if + connect() had been called, disconnect() will stop sending + signal to your speakers.

+ path: .././src/content/reference/en//p5.AudioIn/disconnect + getLevel: + description: | +

Read the Amplitude (volume level) of an AudioIn. The AudioIn + class contains its own instance of the Amplitude class to help + make it easy to get a microphone's volume level. Accepts an + optional smoothing value (0.0 < 1.0). NOTE: AudioIn must + .start() before using .getLevel().

+ path: .././src/content/reference/en//p5.AudioIn/getLevel + amp: + description: | +

Set amplitude (volume) of a mic input between 0 and 1.0.

+ path: .././src/content/reference/en//p5.AudioIn/amp + getSources: + description: | +

Returns a list of available input sources. This is a wrapper + for + MediaDevices.enumerateDevices() - Web APIs | MDN + and it returns a Promise.

+ path: .././src/content/reference/en//p5.AudioIn/getSources + setSource: + description: | +

Set the input source. Accepts a number representing a + position in the array returned by getSources(). + This is only available in browsers that support + + navigator.mediaDevices.enumerateDevices()

+ path: .././src/content/reference/en//p5.AudioIn/setSource +--- + + +# p5.AudioIn diff --git a/src/content/reference/en/p5.sound/p5.AudioVoice.mdx b/src/content/reference/en/p5.sound/p5.AudioVoice.mdx new file mode 100644 index 0000000000..cf2b0529c9 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.AudioVoice.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.AudioVoice +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Base class for monophonic synthesizers. Any extensions of this class + should follow the API and implement the methods below in order to + remain compatible with p5.PolySynth();

+isConstructor: true +line: 11149 +memberMethodPreviews: + connect: + description: | +

Connect to p5 objects or Web Audio Nodes

+ path: .././src/content/reference/en//p5.AudioVoice/connect + disconnect: + description: | +

Disconnect from soundOut

+ path: .././src/content/reference/en//p5.AudioVoice/disconnect +--- + + +# p5.AudioVoice diff --git a/src/content/reference/en/p5.sound/p5.BandPass.mdx b/src/content/reference/en/p5.sound/p5.BandPass.mdx new file mode 100644 index 0000000000..2350e9ef15 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.BandPass.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.BandPass +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.BandPass() Filter. + This is the same as creating a p5.Filter and then calling + its method setType('bandpass'). + See p5.Filter for methods.

+isConstructor: true +line: 6962 +--- + + +# p5.BandPass diff --git a/src/content/reference/en/p5.sound/p5.Compressor.mdx b/src/content/reference/en/p5.sound/p5.Compressor.mdx new file mode 100644 index 0000000000..2e72d8c1a4 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Compressor.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Compressor +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Compressor is an audio effect class that performs dynamics compression + + on an audio input source. This is a very commonly used technique in music + + and sound production. Compression creates an overall louder, richer, + + and fuller sound by lowering the volume of louds and raising that of softs. + + Compression can be used to avoid clipping (sound distortion due to + + peaks in volume) and is especially useful when many sounds are played + + at once. Compression can be used on indivudal sound sources in addition + + to the main output.

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 10036 +memberMethodPreviews: + compressor: + description: > +

The p5.Compressor is built with a Web Audio Dynamics Compressor Node +

+ path: .././src/content/reference/en//p5.Compressor/compressor + process: + description: | +

Performs the same function as .connect, but also accepts + optional parameters to set compressor's audioParams

+ path: .././src/content/reference/en//p5.Compressor/process + set: + description: | +

Set the paramters of a compressor.

+ path: .././src/content/reference/en//p5.Compressor/set + attack: + description: | +

Get current attack or set value w/ time ramp

+ path: .././src/content/reference/en//p5.Compressor/attack + knee: + description: | +

Get current knee or set value w/ time ramp

+ path: .././src/content/reference/en//p5.Compressor/knee + ratio: + description: | +

Get current ratio or set value w/ time ramp

+ path: .././src/content/reference/en//p5.Compressor/ratio + threshold: + description: | +

Get current threshold or set value w/ time ramp

+ path: .././src/content/reference/en//p5.Compressor/threshold + release: + description: | +

Get current release or set value w/ time ramp

+ path: .././src/content/reference/en//p5.Compressor/release + reduction: + description: | +

Return the current reduction value

+ path: .././src/content/reference/en//p5.Compressor/reduction +--- + + +# p5.Compressor diff --git a/src/content/reference/en/p5.sound/p5.Convolver.mdx b/src/content/reference/en/p5.sound/p5.Convolver.mdx new file mode 100644 index 0000000000..6493f59e00 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Convolver.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Convolver +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

p5.Convolver extends p5.Reverb. It can emulate the sound of real + physical spaces through a process called + convolution.

+ +

Convolution multiplies any audio input by an "impulse response" + to simulate the dispersion of sound over time. The impulse response is + generated from an audio file that you provide. One way to + generate an impulse response is to pop a balloon in a reverberant space + and record the echo. Convolution can also be used to experiment with + sound.

+ +

Use the method createConvolution(path) to instantiate a + p5.Convolver with a path to your impulse response audio file.

+isConstructor: true +line: 8549 +params: + - name: path + description: | +

path to a sound file

+ type: String + - name: callback + description: | +

function to call when loading succeeds

+ type: Function + optional: true + - name: errorCallback + description: | +

function to call if loading fails. + This function will receive an error or + XMLHttpRequest object with information + about what went wrong.

+ type: Function + optional: true +memberMethodPreviews: + convolverNode: + description: | +

Internally, the p5.Convolver uses the a + + Web Audio Convolver Node.

+ path: .././src/content/reference/en//p5.Convolver/convolverNode + impulses: + description: | +

If you load multiple impulse files using the .addImpulse method, + they will be stored as Objects in this Array. Toggle between them + with the toggleImpulse(id) method.

+ path: .././src/content/reference/en//p5.Convolver/impulses + process: + description: | +

Connect a source to the convolver.

+ path: .././src/content/reference/en//p5.Convolver/process + addImpulse: + description: | +

Load and assign a new Impulse Response to the p5.Convolver. + The impulse is added to the .impulses array. Previous + impulses can be accessed with the .toggleImpulse(id) + method.

+ path: .././src/content/reference/en//p5.Convolver/addImpulse + resetImpulse: + description: | +

Similar to .addImpulse, except that the .impulses + Array is reset to save memory. A new .impulses + array is created with this impulse as the only item.

+ path: .././src/content/reference/en//p5.Convolver/resetImpulse + toggleImpulse: + description: | +

If you have used .addImpulse() to add multiple impulses + to a p5.Convolver, then you can use this method to toggle between + the items in the .impulses Array. Accepts a parameter + to identify which impulse you wish to use, identified either by its + original filename (String) or by its position in the .impulses + Array (Number).
+ You can access the objects in the .impulses Array directly. Each + Object has two attributes: an .audioBuffer (type: + Web Audio + AudioBuffer) and a .name, a String that corresponds + with the original filename.

+ path: .././src/content/reference/en//p5.Convolver/toggleImpulse +--- + + +# p5.Convolver diff --git a/src/content/reference/en/p5.sound/p5.Delay.mdx b/src/content/reference/en/p5.sound/p5.Delay.mdx new file mode 100644 index 0000000000..1a41382749 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Delay.mdx @@ -0,0 +1,98 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Delay +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Delay is an echo effect. It processes an existing sound source, + + and outputs a delayed version of that sound. The p5.Delay can + + produce different effects depending on the delayTime, feedback, + + filter, and type. In the example below, a feedback of 0.5 (the + + default value) will produce a looping delay that decreases in + + volume by 50% each repeat. A filter will cut out the high + + frequencies so that the delay does not sound as piercing as the + + original source.

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 7926 +memberMethodPreviews: + leftDelay: + description: | +

The p5.Delay is built with two + + Web Audio Delay Nodes, one for each stereo channel.

+ path: .././src/content/reference/en//p5.Delay/leftDelay + rightDelay: + description: | +

The p5.Delay is built with two + + Web Audio Delay Nodes, one for each stereo channel.

+ path: .././src/content/reference/en//p5.Delay/rightDelay + process: + description: | +

Add delay to an audio signal according to a set + of delay parameters.

+ path: .././src/content/reference/en//p5.Delay/process + delayTime: + description: | +

Set the delay (echo) time, in seconds. Usually this value will be + a floating point number between 0.0 and 1.0.

+ path: .././src/content/reference/en//p5.Delay/delayTime + feedback: + description: > +

Feedback occurs when Delay sends its signal back through its input + + in a loop. The feedback amount determines how much signal to send each + + time through the loop. A feedback greater than 1.0 is not desirable + because + + it will increase the overall output each time through the loop, + + creating an infinite feedback loop. The default value is 0.5

+ path: .././src/content/reference/en//p5.Delay/feedback + filter: + description: | +

Set a lowpass filter frequency for the delay. A lowpass filter + will cut off any frequencies higher than the filter frequency.

+ path: .././src/content/reference/en//p5.Delay/filter + setType: + description: | +

Choose a preset type of delay. 'pingPong' bounces the signal + from the left to the right channel to produce a stereo effect. + Any other parameter will revert to the default delay setting.

+ path: .././src/content/reference/en//p5.Delay/setType + amp: + description: | +

Set the output level of the delay effect.

+ path: .././src/content/reference/en//p5.Delay/amp + connect: + description: | +

Send output to a p5.sound or web audio object

+ path: .././src/content/reference/en//p5.Delay/connect + disconnect: + description: | +

Disconnect all output.

+ path: .././src/content/reference/en//p5.Delay/disconnect +--- + + +# p5.Delay diff --git a/src/content/reference/en/p5.sound/p5.Distortion.mdx b/src/content/reference/en/p5.sound/p5.Distortion.mdx new file mode 100644 index 0000000000..5febdc7086 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Distortion.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Distortion +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

A Distortion effect created with a Waveshaper Node, + + with an approach adapted from + + Kevin + Ennis

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 10816 +params: + - name: amount + description: | +

Unbounded distortion amount. + Normal values range from 0-1.

+ type: Number + optional: true + optdefault: '0.25' + - name: oversample + description: | +

'none', '2x', or '4x'.

+ type: String + optional: true + optdefault: '''none''' +memberMethodPreviews: + WaveShaperNode: + description: | +

The p5.Distortion is built with a + + Web Audio WaveShaper Node.

+ path: .././src/content/reference/en//p5.Distortion/WaveShaperNode + process: + description: > +

Process a sound source, optionally specify amount and oversample + values.

+ path: .././src/content/reference/en//p5.Distortion/process + set: + description: | +

Set the amount and oversample of the waveshaper distortion.

+ path: .././src/content/reference/en//p5.Distortion/set + getAmount: + description: | +

Return the distortion amount, typically between 0-1.

+ path: .././src/content/reference/en//p5.Distortion/getAmount + getOversample: + description: | +

Return the oversampling.

+ path: .././src/content/reference/en//p5.Distortion/getOversample +--- + + +# p5.Distortion diff --git a/src/content/reference/en/p5.sound/p5.EQ.mdx b/src/content/reference/en/p5.sound/p5.EQ.mdx new file mode 100644 index 0000000000..ccfba9f5ca --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.EQ.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.EQ +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

p5.EQ is an audio effect that performs the function of a multiband + + audio equalizer. Equalization is used to adjust the balance of + + frequency compoenents of an audio signal. This process is commonly used + + in sound production and recording to change the waveform before it reaches + + a sound output device. EQ can also be used as an audio effect to create + + interesting distortions by filtering out parts of the spectrum. p5.EQ is + + built using a chain of Web Audio Biquad Filter Nodes and can be + + instantiated with 3 or 8 bands. Bands can be added or removed from + + the EQ by directly modifying p5.EQ.bands (the array that stores filters).

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 7105 +params: + - name: _eqsize + description: | +

Constructor will accept 3 or 8, defaults to 3

+ type: Number + optional: true +return: + description: p5.EQ object + type: Object +memberMethodPreviews: + bands: + description: | +

The p5.EQ is built with abstracted p5.Filter objects. + To modify any bands, use methods of the + p5.Filter API, especially gain and freq. + Bands are stored in an array, with indices 0 - 3, or 0 - 7

+ path: .././src/content/reference/en//p5.EQ/bands + process: + description: | +

Process an input by connecting it to the EQ

+ path: .././src/content/reference/en//p5.EQ/process +--- + + +# p5.EQ diff --git a/src/content/reference/en/p5.sound/p5.Effect.mdx b/src/content/reference/en/p5.sound/p5.Effect.mdx new file mode 100644 index 0000000000..4a36b220b2 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Effect.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Effect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Effect is a base class for audio effects in p5.
+ + This module handles the nodes and methods that are + + common and useful for current and future effects.

+ +

This class is extended by p5.Distortion, + + p5.Compressor, + + p5.Delay, + + p5.Filter, + + p5.Reverb.

+isConstructor: true +line: 6423 +params: + - name: ac + description: | +

Reference to the audio context of the p5 object

+ type: Object + optional: true + - name: input + description: | +

Gain Node effect wrapper

+ type: AudioNode + optional: true + - name: output + description: | +

Gain Node effect wrapper

+ type: AudioNode + optional: true + - name: _drywet + description: | +

Tone.JS CrossFade node (defaults to value: 1)

+ type: Object + optional: true + - name: wet + description: | +

Effects that extend this class should connect + to the wet signal to this gain node, so that dry and wet + signals are mixed properly.

+ type: AudioNode + optional: true +memberMethodPreviews: + amp: + description: | +

Set the output volume of the filter.

+ path: .././src/content/reference/en//p5.Effect/amp + chain: + description: | +

Link effects together in a chain + Example usage: filter.chain(reverb, delay, panner); + May be used with an open-ended number of arguments

+ path: .././src/content/reference/en//p5.Effect/chain + drywet: + description: | +

Adjust the dry/wet value.

+ path: .././src/content/reference/en//p5.Effect/drywet + connect: + description: | +

Send output to a p5.js-sound, Web Audio Node, or use signal to + control an AudioParam

+ path: .././src/content/reference/en//p5.Effect/connect + disconnect: + description: | +

Disconnect all output.

+ path: .././src/content/reference/en//p5.Effect/disconnect +--- + + +# p5.Effect diff --git a/src/content/reference/en/p5.sound/p5.Envelope.mdx b/src/content/reference/en/p5.sound/p5.Envelope.mdx new file mode 100644 index 0000000000..153ef64bab --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Envelope.mdx @@ -0,0 +1,160 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Envelope +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: >- +

Envelopes are pre-defined amplitude distribution over time. + + Typically, envelopes are used to control the output volume + + of an object, a series of fades referred to as Attack, Decay, + + Sustain and Release ( + + ADSR + + ). Envelopes can also control other Web Audio Parameters—for example, a + p5.Envelope can + + control an Oscillator's frequency like this: osc.freq(env).

+ +

Use setRange to change + the attack/release level. + + Use setADSR to change + attackTime, decayTime, sustainPercent and releaseTime.

+ +

Use the play method to play + the entire envelope, + + the ramp method for a pingable + trigger, + + or triggerAttack/ + + triggerRelease to + trigger noteOn/noteOff.

+isConstructor: true +line: 4721 +memberMethodPreviews: + attackTime: + description: | +

Time until envelope reaches attackLevel

+ path: .././src/content/reference/en//p5.Envelope/attackTime + attackLevel: + description: | +

Level once attack is complete.

+ path: .././src/content/reference/en//p5.Envelope/attackLevel + decayTime: + description: | +

Time until envelope reaches decayLevel.

+ path: .././src/content/reference/en//p5.Envelope/decayTime + decayLevel: + description: > +

Level after decay. The envelope will sustain here until it is + released.

+ path: .././src/content/reference/en//p5.Envelope/decayLevel + releaseTime: + description: | +

Duration of the release portion of the envelope.

+ path: .././src/content/reference/en//p5.Envelope/releaseTime + releaseLevel: + description: | +

Level at the end of the release.

+ path: .././src/content/reference/en//p5.Envelope/releaseLevel + set: + description: | +

Reset the envelope with a series of time/value pairs.

+ path: .././src/content/reference/en//p5.Envelope/set + setADSR: + description: > +

Set values like a traditional + + + + ADSR envelope + + .

+ path: .././src/content/reference/en//p5.Envelope/setADSR + setRange: + description: | +

Set max (attackLevel) and min (releaseLevel) of envelope.

+ path: .././src/content/reference/en//p5.Envelope/setRange + setInput: + description: | +

Assign a parameter to be controlled by this envelope. + If a p5.Sound object is given, then the p5.Envelope will control its + output gain. If multiple inputs are provided, the env will + control all of them.

+ path: .././src/content/reference/en//p5.Envelope/setInput + setExp: + description: | +

Set whether the envelope ramp is linear (default) or exponential. + Exponential ramps can be useful because we perceive amplitude + and frequency logarithmically.

+ path: .././src/content/reference/en//p5.Envelope/setExp + play: + description: |- +

Play tells the envelope to start acting on a given input. + If the input is a p5.sound object (i.e. AudioIn, Oscillator, + SoundFile), then Envelope will control its output volume. + Envelopes can also be used to control any + Web Audio Audio Param.

+ path: .././src/content/reference/en//p5.Envelope/play + triggerAttack: + description: | +

Trigger the Attack, and Decay portion of the Envelope. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go. Input can be + any p5.sound object, or a + Web Audio Param.

+ path: .././src/content/reference/en//p5.Envelope/triggerAttack + triggerRelease: + description: | +

Trigger the Release of the Envelope. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+ path: .././src/content/reference/en//p5.Envelope/triggerRelease + ramp: + description: > +

Exponentially ramp to a value using the first two + + values from setADSR(attackTime, + decayTime) + + as + + time constants for simple exponential ramps. + + If the value is higher than current value, it uses attackTime, + + while a decrease uses decayTime.

+ path: .././src/content/reference/en//p5.Envelope/ramp + add: + description: | +

Add a value to the p5.Oscillator's output amplitude, + and return the oscillator. Calling this method + again will override the initial add() with new values.

+ path: .././src/content/reference/en//p5.Envelope/add + mult: + description: | +

Multiply the p5.Envelope's output amplitude + by a fixed value. Calling this method + again will override the initial mult() with new values.

+ path: .././src/content/reference/en//p5.Envelope/mult + scale: + description: | +

Scale this envelope's amplitude values to a given + range, and return the envelope. Calling this method + again will override the initial scale() with new values.

+ path: .././src/content/reference/en//p5.Envelope/scale +--- + + +# p5.Envelope diff --git a/src/content/reference/en/p5.sound/p5.FFT.mdx b/src/content/reference/en/p5.sound/p5.FFT.mdx new file mode 100644 index 0000000000..a04f845d8a --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.FFT.mdx @@ -0,0 +1,148 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.FFT +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

FFT (Fast Fourier Transform) is an analysis algorithm that + isolates individual + + audio frequencies within a waveform.

+ +

Once instantiated, a p5.FFT object can return an array based on + two types of analyses:
FFT.waveform() computes + amplitude values along the time domain. The array indices correspond + to samples across a brief moment in time. Each value represents + amplitude of the waveform at that sample of time.
+ • FFT.analyze() computes amplitude values along the + frequency domain. The array indices correspond to frequencies (i.e. + pitches), from the lowest to the highest that humans can hear. Each + value represents amplitude at that slice of the frequency spectrum. + Use with getEnergy() to measure amplitude at specific + frequencies, or within a range of frequencies.

+ +

FFT analyzes a very short snapshot of sound called a sample + buffer. It returns an array of amplitude measurements, referred + to as bins. The array is 1024 bins long by default. + You can change the bin array length, but it must be a power of 2 + between 16 and 1024 in order for the FFT algorithm to function + correctly. The actual size of the FFT buffer is twice the + number of bins, so given a standard sample rate, the buffer is + 2048/44100 seconds long.

+isConstructor: true +line: 3347 +params: + - name: smoothing + description: | +

Smooth results of Freq Spectrum. + 0.0 < smoothing < 1.0. + Defaults to 0.8.

+ type: Number + optional: true + - name: bins + description: | +

Length of resulting array. + Must be a power of two between + 16 and 1024. Defaults to 1024.

+ type: Number + optional: true +memberMethodPreviews: + setInput: + description: | +

Set the input source for the FFT analysis. If no source is + provided, FFT will analyze all sound in the sketch.

+ path: .././src/content/reference/en//p5.FFT/setInput + waveform: + description: > +

Returns an array of amplitude values (between -1.0 and +1.0) that + represent + + a snapshot of amplitude readings in a single buffer. Length will be + + equal to bins (defaults to 1024). Can be used to draw the waveform + + of a sound.

+ path: .././src/content/reference/en//p5.FFT/waveform + analyze: + description: | +

Returns an array of amplitude values (between 0 and 255) + across the frequency spectrum. Length is equal to FFT bins + (1024 by default). The array indices correspond to frequencies + (i.e. pitches), from the lowest to the highest that humans can + hear. Each value represents amplitude at that slice of the + frequency spectrum. Must be called prior to using + getEnergy().

+ path: .././src/content/reference/en//p5.FFT/analyze + getEnergy: + description: | +

Returns the amount of energy (volume) at a specific + + frequency, or the average amount of energy between two + frequencies. Accepts Number(s) corresponding + to frequency (in Hz), or a "string" corresponding to predefined + frequency ranges ("bass", "lowMid", "mid", "highMid", "treble"). + Returns a range between 0 (no energy/volume at that frequency) and + 255 (maximum energy). + NOTE: analyze() must be called prior to getEnergy(). analyze() + tells the FFT to analyze frequency data, and getEnergy() uses + the results to determine the value at a specific frequency or + range of frequencies.

+ path: .././src/content/reference/en//p5.FFT/getEnergy + getCentroid: + description: | +

Returns the + + spectral centroid of the input signal. + NOTE: analyze() must be called prior to getCentroid(). Analyze() + tells the FFT to analyze frequency data, and getCentroid() uses + the results determine the spectral centroid.

+ path: .././src/content/reference/en//p5.FFT/getCentroid + smooth: + description: | +

Smooth FFT analysis by averaging with the last analysis frame.

+ path: .././src/content/reference/en//p5.FFT/smooth + linAverages: + description: | +

Returns an array of average amplitude values for a given number + of frequency bands split equally. N defaults to 16. + NOTE: analyze() must be called prior to linAverages(). Analyze() + tells the FFT to analyze frequency data, and linAverages() uses + the results to group them into a smaller set of averages.

+ path: .././src/content/reference/en//p5.FFT/linAverages + logAverages: + description: > +

Returns an array of average amplitude values of the spectrum, for a + given + + set of + + Octave Bands + + NOTE: analyze() must be called prior to logAverages(). Analyze() + + tells the FFT to analyze frequency data, and logAverages() uses + + the results to group them into a smaller set of averages.

+ path: .././src/content/reference/en//p5.FFT/logAverages + getOctaveBands: + description: > +

Calculates and Returns the 1/N + + Octave + Bands + + N defaults to 3 and minimum central frequency to 15.625Hz. + + (1/3 Octave Bands ~= 31 Frequency Bands) + + Setting fCtr0 to a central value of a higher octave will ignore the lower + bands + + and produce less frequency groups.

+ path: .././src/content/reference/en//p5.FFT/getOctaveBands +--- + + +# p5.FFT diff --git a/src/content/reference/en/p5.sound/p5.Filter.mdx b/src/content/reference/en/p5.sound/p5.Filter.mdx new file mode 100644 index 0000000000..c56837d670 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Filter.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Filter +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

A p5.Filter uses a Web Audio Biquad Filter to filter + + the frequency response of an input source. Subclasses + + include:

+ + p5.LowPass: + + Allows frequencies below the cutoff frequency to pass through, + + and attenuates frequencies above the cutoff.
+ + p5.HighPass: + + The opposite of a lowpass filter.
+ + p5.BandPass: + + Allows a range of frequencies to pass through and attenuates + + the frequencies below and above this frequency range.
+ + +

The .res() method controls either width of the + + bandpass, or resonance of the low/highpass cutoff frequency.

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 6628 +params: + - name: type + description: | +

'lowpass' (default), 'highpass', 'bandpass'

+ type: String + optional: true +memberMethodPreviews: + biquadFilter: + description: | +

The p5.Filter is built with a + + Web Audio BiquadFilter Node.

+ path: .././src/content/reference/en//p5.Filter/biquadFilter + process: + description: | +

Filter an audio signal according to a set + of filter parameters.

+ path: .././src/content/reference/en//p5.Filter/process + set: + description: | +

Set the frequency and the resonance of the filter.

+ path: .././src/content/reference/en//p5.Filter/set + freq: + description: | +

Set the filter frequency, in Hz, from 10 to 22050 (the range of + human hearing, although in reality most people hear in a narrower + range).

+ path: .././src/content/reference/en//p5.Filter/freq + res: + description: | +

Controls either width of a bandpass frequency, + or the resonance of a low/highpass cutoff frequency.

+ path: .././src/content/reference/en//p5.Filter/res + gain: + description: | +

Controls the gain attribute of a Biquad Filter. + This is distinctly different from .amp() which is inherited from p5.Effect + .amp() controls the volume via the output gain node + p5.Filter.gain() controls the gain parameter of a Biquad Filter node.

+ path: .././src/content/reference/en//p5.Filter/gain + toggle: + description: | +

Toggle function. Switches between the specified type and allpass

+ path: .././src/content/reference/en//p5.Filter/toggle + setType: + description: | +

Set the type of a p5.Filter. Possible types include: + "lowpass" (default), "highpass", "bandpass", + "lowshelf", "highshelf", "peaking", "notch", + "allpass".

+ path: .././src/content/reference/en//p5.Filter/setType +--- + + +# p5.Filter diff --git a/src/content/reference/en/p5.sound/p5.Gain.mdx b/src/content/reference/en/p5.sound/p5.Gain.mdx new file mode 100644 index 0000000000..bf20150900 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Gain.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Gain +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

A gain node is usefull to set the relative volume of sound. + It's typically used to build mixers.

+isConstructor: true +line: 10973 +memberMethodPreviews: + setInput: + description: | +

Connect a source to the gain node.

+ path: .././src/content/reference/en//p5.Gain/setInput + connect: + description: | +

Send output to a p5.sound or web audio object

+ path: .././src/content/reference/en//p5.Gain/connect + disconnect: + description: | +

Disconnect all output.

+ path: .././src/content/reference/en//p5.Gain/disconnect + amp: + description: | +

Set the output level of the gain node.

+ path: .././src/content/reference/en//p5.Gain/amp +--- + + +# p5.Gain diff --git a/src/content/reference/en/p5.sound/p5.HighPass.mdx b/src/content/reference/en/p5.sound/p5.HighPass.mdx new file mode 100644 index 0000000000..8602ba55e1 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.HighPass.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.HighPass +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.HighPass() Filter. + This is the same as creating a p5.Filter and then calling + its method setType('highpass'). + See p5.Filter for methods.

+isConstructor: true +line: 6938 +--- + + +# p5.HighPass diff --git a/src/content/reference/en/p5.sound/p5.LowPass.mdx b/src/content/reference/en/p5.sound/p5.LowPass.mdx new file mode 100644 index 0000000000..671312bb3b --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.LowPass.mdx @@ -0,0 +1,17 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.LowPass +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.LowPass() Filter. + This is the same as creating a p5.Filter and then calling + its method setType('lowpass'). + See p5.Filter for methods.

+isConstructor: true +line: 6914 +--- + + +# p5.LowPass diff --git a/src/content/reference/en/p5.sound/p5.MonoSynth.mdx b/src/content/reference/en/p5.sound/p5.MonoSynth.mdx new file mode 100644 index 0000000000..15ae444ae7 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.MonoSynth.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.MonoSynth +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

A MonoSynth is used as a single voice for sound synthesis. + This is a class to be used in conjunction with the PolySynth + class. Custom synthetisers should be built inheriting from + this class.

+isConstructor: true +line: 11247 +memberMethodPreviews: + attack: + description: | +

Getters and Setters

+ path: .././src/content/reference/en//p5.MonoSynth/attack + play: + description: | +

Play tells the MonoSynth to start playing a note. This method schedules + the calling of .triggerAttack and .triggerRelease.

+ path: .././src/content/reference/en//p5.MonoSynth/play + triggerAttack: + description: | +

Trigger the Attack, and Decay portion of the Envelope. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go.

+ path: .././src/content/reference/en//p5.MonoSynth/triggerAttack + triggerRelease: + description: | +

Trigger the release of the Envelope. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+ path: .././src/content/reference/en//p5.MonoSynth/triggerRelease + setADSR: + description: > +

Set values like a traditional + + + + ADSR envelope + + .

+ path: .././src/content/reference/en//p5.MonoSynth/setADSR + amp: + description: | +

MonoSynth amp

+ path: .././src/content/reference/en//p5.MonoSynth/amp + connect: + description: | +

Connect to a p5.sound / Web Audio object.

+ path: .././src/content/reference/en//p5.MonoSynth/connect + disconnect: + description: | +

Disconnect all outputs

+ path: .././src/content/reference/en//p5.MonoSynth/disconnect + dispose: + description: | +

Get rid of the MonoSynth and free up its resources / memory.

+ path: .././src/content/reference/en//p5.MonoSynth/dispose +--- + + +# p5.MonoSynth diff --git a/src/content/reference/en/p5.sound/p5.Noise.mdx b/src/content/reference/en/p5.sound/p5.Noise.mdx new file mode 100644 index 0000000000..7902936da6 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Noise.mdx @@ -0,0 +1,27 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Noise +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Noise is a type of oscillator that generates a buffer with random + values.

+isConstructor: true +line: 5620 +params: + - name: type + description: | +

Type of noise can be 'white' (default), + 'brown' or 'pink'.

+ type: String +memberMethodPreviews: + setType: + description: | +

Set type of noise to 'white', 'pink' or 'brown'. + White is the default.

+ path: .././src/content/reference/en//p5.Noise/setType +--- + + +# p5.Noise diff --git a/src/content/reference/en/p5.sound/p5.OnsetDetect.mdx b/src/content/reference/en/p5.sound/p5.OnsetDetect.mdx new file mode 100644 index 0000000000..4cf6a28d36 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.OnsetDetect.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.OnsetDetect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Listen for onsets (a sharp increase in volume) within a given + frequency range.

+isConstructor: true +line: 11624 +params: + - name: freqLow + description: | +

Low frequency

+ type: Number + - name: freqHigh + description: | +

High frequency

+ type: Number + - name: threshold + description: | +

Amplitude threshold between 0 (no energy) and 1 (maximum)

+ type: Number + - name: callback + description: | +

Function to call when an onset is detected

+ type: Function +--- + + +# p5.OnsetDetect diff --git a/src/content/reference/en/p5.sound/p5.Oscillator.mdx b/src/content/reference/en/p5.sound/p5.Oscillator.mdx new file mode 100644 index 0000000000..e097ea9730 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Oscillator.mdx @@ -0,0 +1,121 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Oscillator +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

Creates a signal that oscillates between -1.0 and 1.0. + By default, the oscillation takes the form of a sinusoidal + shape ('sine'). Additional types include 'triangle', + 'sawtooth' and 'square'. The frequency defaults to + 440 oscillations per second (440Hz, equal to the pitch of an + 'A' note).

+ +

Set the type of oscillation with setType(), or by instantiating a + specific oscillator: p5.SinOsc, p5.TriOsc, p5.SqrOsc, or p5.SawOsc. +

+isConstructor: true +line: 4060 +params: + - name: freq + description: | +

frequency defaults to 440Hz

+ type: Number + optional: true + - name: type + description: | +

type of oscillator. Options: + 'sine' (default), 'triangle', + 'sawtooth', 'square'

+ type: String + optional: true +memberMethodPreviews: + start: + description: | +

Start an oscillator.

+

Starting an oscillator on a user gesture will enable audio in browsers + that have a strict autoplay policy, including Chrome and most mobile + devices. See also: userStartAudio().

+ path: .././src/content/reference/en//p5.Oscillator/start + stop: + description: | +

Stop an oscillator. Accepts an optional parameter + to determine how long (in seconds from now) until the + oscillator stops.

+ path: .././src/content/reference/en//p5.Oscillator/stop + amp: + description: | +

Set the amplitude between 0 and 1.0. Or, pass in an object + such as an oscillator to modulate amplitude with an audio signal.

+ path: .././src/content/reference/en//p5.Oscillator/amp + getAmp: + description: | +

Returns the value of output gain

+ path: .././src/content/reference/en//p5.Oscillator/getAmp + freq: + description: | +

Set frequency of an oscillator to a value. Or, pass in an object + such as an oscillator to modulate the frequency with an audio signal.

+ path: .././src/content/reference/en//p5.Oscillator/freq + getFreq: + description: | +

Returns the value of frequency of oscillator

+ path: .././src/content/reference/en//p5.Oscillator/getFreq + setType: + description: | +

Set type to 'sine', 'triangle', 'sawtooth' or 'square'.

+ path: .././src/content/reference/en//p5.Oscillator/setType + getType: + description: > +

Returns current type of oscillator eg. 'sine', 'triangle', 'sawtooth' + or 'square'.

+ path: .././src/content/reference/en//p5.Oscillator/getType + connect: + description: | +

Connect to a p5.sound / Web Audio object.

+ path: .././src/content/reference/en//p5.Oscillator/connect + disconnect: + description: | +

Disconnect all outputs

+ path: .././src/content/reference/en//p5.Oscillator/disconnect + pan: + description: | +

Pan between Left (-1) and Right (1)

+ path: .././src/content/reference/en//p5.Oscillator/pan + getPan: + description: > +

Returns the current value of panPosition , between Left (-1) and Right + (1)

+ path: .././src/content/reference/en//p5.Oscillator/getPan + phase: + description: | +

Set the phase of an oscillator between 0.0 and 1.0. + In this implementation, phase is a delay time + based on the oscillator's current frequency.

+ path: .././src/content/reference/en//p5.Oscillator/phase + add: + description: | +

Add a value to the p5.Oscillator's output amplitude, + and return the oscillator. Calling this method again + will override the initial add() with a new value.

+ path: .././src/content/reference/en//p5.Oscillator/add + mult: + description: | +

Multiply the p5.Oscillator's output amplitude + by a fixed value (i.e. turn it up!). Calling this method + again will override the initial mult() with a new value.

+ path: .././src/content/reference/en//p5.Oscillator/mult + scale: + description: | +

Scale this oscillator's amplitude values to a given + range, and return the oscillator. Calling this method + again will override the initial scale() with new values.

+ path: .././src/content/reference/en//p5.Oscillator/scale +--- + + +# p5.Oscillator diff --git a/src/content/reference/en/p5.sound/p5.Panner3D.mdx b/src/content/reference/en/p5.sound/p5.Panner3D.mdx new file mode 100644 index 0000000000..c4dda39ec5 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Panner3D.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Panner3D +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Panner3D is based on the + Web Audio Spatial Panner Node. + This panner is a spatial processing node that allows audio to be positioned + and oriented in 3D space.

+

The position is relative to an + Audio Context Listener, which can be accessed + by p5.soundOut.audiocontext.listener

+isConstructor: true +line: 7602 +memberMethodPreviews: + panner: + description: | +

+ Web Audio Spatial Panner Node

+

Properties include
+ Panning Model + : "equal power" or "HRTF"
+ DistanceModel + : "linear", "inverse", or "exponential"

+ path: .././src/content/reference/en//p5.Panner3D/panner + process: + description: | +

Connect an audio sorce

+ path: .././src/content/reference/en//p5.Panner3D/process + set: + description: | +

Set the X,Y,Z position of the Panner

+ path: .././src/content/reference/en//p5.Panner3D/set + positionX: + description: | +

Getter and setter methods for position coordinates

+ path: .././src/content/reference/en//p5.Panner3D/positionX + positionY: + description: | +

Getter and setter methods for position coordinates

+ path: .././src/content/reference/en//p5.Panner3D/positionY + positionZ: + description: | +

Getter and setter methods for position coordinates

+ path: .././src/content/reference/en//p5.Panner3D/positionZ + orient: + description: | +

Set the X,Y,Z position of the Panner

+ path: .././src/content/reference/en//p5.Panner3D/orient + orientX: + description: | +

Getter and setter methods for orient coordinates

+ path: .././src/content/reference/en//p5.Panner3D/orientX + orientY: + description: | +

Getter and setter methods for orient coordinates

+ path: .././src/content/reference/en//p5.Panner3D/orientY + orientZ: + description: | +

Getter and setter methods for orient coordinates

+ path: .././src/content/reference/en//p5.Panner3D/orientZ + setFalloff: + description: | +

Set the rolloff factor and max distance

+ path: .././src/content/reference/en//p5.Panner3D/setFalloff + maxDist: + description: | +

Maxium distance between the source and the listener

+ path: .././src/content/reference/en//p5.Panner3D/maxDist + rollof: + description: > +

How quickly the volume is reduced as the source moves away from the + listener

+ path: .././src/content/reference/en//p5.Panner3D/rollof +--- + + +# p5.Panner3D diff --git a/src/content/reference/en/p5.sound/p5.Part.mdx b/src/content/reference/en/p5.sound/p5.Part.mdx new file mode 100644 index 0000000000..a34e104378 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Part.mdx @@ -0,0 +1,88 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Part +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

A p5.Part plays back one or more p5.Phrases. Instantiate a part + with steps and tatums. By default, each step represents a 1/16th note.

+ +

See p5.Phrase for more about musical timing.

+isConstructor: true +line: 9185 +params: + - name: steps + description: | +

Steps in the part

+ type: Number + optional: true + - name: tatums + description: > +

Divisions of a beat, e.g. use 1/4, or 0.25 for a quater note (default + is 1/16, a sixteenth note)

+ type: Number + optional: true +memberMethodPreviews: + setBPM: + description: | +

Set the tempo of this part, in Beats Per Minute.

+ path: .././src/content/reference/en//p5.Part/setBPM + getBPM: + description: | +

Returns the tempo, in Beats Per Minute, of this part.

+ path: .././src/content/reference/en//p5.Part/getBPM + start: + description: | +

Start playback of this part. It will play + through all of its phrases at a speed + determined by setBPM.

+ path: .././src/content/reference/en//p5.Part/start + loop: + description: | +

Loop playback of this part. It will begin + looping through all of its phrases at a speed + determined by setBPM.

+ path: .././src/content/reference/en//p5.Part/loop + noLoop: + description: | +

Tell the part to stop looping.

+ path: .././src/content/reference/en//p5.Part/noLoop + stop: + description: > +

Stop the part and cue it to step 0. Playback will resume from the + begining of the Part when it is played again.

+ path: .././src/content/reference/en//p5.Part/stop + pause: + description: | +

Pause the part. Playback will resume + from the current step.

+ path: .././src/content/reference/en//p5.Part/pause + addPhrase: + description: | +

Add a p5.Phrase to this Part.

+ path: .././src/content/reference/en//p5.Part/addPhrase + removePhrase: + description: | +

Remove a phrase from this part, based on the name it was + given when it was created.

+ path: .././src/content/reference/en//p5.Part/removePhrase + getPhrase: + description: | +

Get a phrase from this part, based on the name it was + given when it was created. Now you can modify its array.

+ path: .././src/content/reference/en//p5.Part/getPhrase + replaceSequence: + description: > +

Find all sequences with the specified name, and replace their patterns + with the specified array.

+ path: .././src/content/reference/en//p5.Part/replaceSequence + onStep: + description: > +

Set the function that will be called at every step. This will clear the + previous function.

+ path: .././src/content/reference/en//p5.Part/onStep +--- + + +# p5.Part diff --git a/src/content/reference/en/p5.sound/p5.PeakDetect.mdx b/src/content/reference/en/p5.sound/p5.PeakDetect.mdx new file mode 100644 index 0000000000..26369d49e3 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.PeakDetect.mdx @@ -0,0 +1,112 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.PeakDetect +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: >- +

PeakDetect works in conjunction with p5.FFT to + + look for onsets in some or all of the frequency spectrum. + +

+ +

+ + To use p5.PeakDetect, call update in the draw loop + + and pass in a p5.FFT object. + +

+ +

+ + You can listen for a specific part of the frequency spectrum by + + setting the range between freq1 and freq2. + +

+ + +

threshold is the threshold for detecting a peak, + + scaled between 0 and 1. It is logarithmic, so 0.1 is half as loud + + as 1.0.

+ + +

+ + The update method is meant to be run in the draw loop, and + + frames determines how many loops must pass before + + another peak can be detected. + + For example, if the frameRate() = 60, you could detect the beat of a + + 120 beat-per-minute song with this equation: + + framesPerPeak = 60 / (estimatedBPM / 60 ); + +

+ + +

+ + Based on example contribtued by @b2renger, and a simple beat detection + + explanation by Felix Turner. + +

+isConstructor: true +line: 10312 +params: + - name: freq1 + description: | +

lowFrequency - defaults to 20Hz

+ type: Number + optional: true + - name: freq2 + description: | +

highFrequency - defaults to 20000 Hz

+ type: Number + optional: true + - name: threshold + description: | +

Threshold for detecting a beat between 0 and 1 + scaled logarithmically where 0.1 is 1/2 the loudness + of 1.0. Defaults to 0.35.

+ type: Number + optional: true + - name: framesPerPeak + description: | +

Defaults to 20.

+ type: Number + optional: true +memberMethodPreviews: + isDetected: + description: | +

isDetected is set to true when a peak is detected.

+ path: .././src/content/reference/en//p5.PeakDetect/isDetected + update: + description: | +

The update method is run in the draw loop.

+

Accepts an FFT object. You must call .analyze() + on the FFT object prior to updating the peakDetect + because it relies on a completed FFT analysis.

+ path: .././src/content/reference/en//p5.PeakDetect/update + onPeak: + description: | +

onPeak accepts two arguments: a function to call when + a peak is detected. The value of the peak, + between 0.0 and 1.0, is passed to the callback.

+ path: .././src/content/reference/en//p5.PeakDetect/onPeak +--- + + +# p5.PeakDetect diff --git a/src/content/reference/en/p5.sound/p5.Phrase.mdx b/src/content/reference/en/p5.sound/p5.Phrase.mdx new file mode 100644 index 0000000000..0da91c8139 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Phrase.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Phrase +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

A phrase is a pattern of musical events over time, i.e. + a series of notes and rests.

+ +

Phrases must be added to a p5.Part for playback, and + each part can play multiple phrases at the same time. + For example, one Phrase might be a kick drum, another + could be a snare, and another could be the bassline.

+ +

The first parameter is a name so that the phrase can be + modified or deleted later. The callback is a a function that + this phrase will call at every step—for example it might be + called playNote(value){}. The array determines + which value is passed into the callback at each step of the + phrase. It can be numbers, an object with multiple numbers, + or a zero (0) indicates a rest so the callback won't be called).

+isConstructor: true +line: 9103 +params: + - name: name + description: | +

Name so that you can access the Phrase.

+ type: String + - name: callback + description: | +

The name of a function that this phrase + will call. Typically it will play a sound, + and accept two parameters: a time at which + to play the sound (in seconds from now), + and a value from the sequence array. The + time should be passed into the play() or + start() method to ensure precision.

+ type: Function + - name: sequence + description: | +

Array of values to pass into the callback + at each step of the phrase.

+ type: Array +memberMethodPreviews: + sequence: + description: | +

Array of values to pass into the callback + at each step of the phrase. Depending on the callback + function's requirements, these values may be numbers, + strings, or an object with multiple parameters. + Zero (0) indicates a rest.

+ path: .././src/content/reference/en//p5.Phrase/sequence +--- + + +# p5.Phrase diff --git a/src/content/reference/en/p5.sound/p5.PolySynth.mdx b/src/content/reference/en/p5.sound/p5.PolySynth.mdx new file mode 100644 index 0000000000..d65cd8ac81 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.PolySynth.mdx @@ -0,0 +1,103 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.PolySynth +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

An AudioVoice is used as a single voice for sound synthesis. + The PolySynth class holds an array of AudioVoice, and deals + with voices allocations, with setting notes to be played, and + parameters to be set.

+isConstructor: true +line: 11691 +params: + - name: synthVoice + description: | +

A monophonic synth voice inheriting + the AudioVoice class. Defaults to p5.MonoSynth

+ type: Number + optional: true + - name: maxVoices + description: | +

Number of voices, defaults to 8;

+ type: Number + optional: true +memberMethodPreviews: + notes: + description: > +

An object that holds information about which notes have been played and + + which notes are currently being played. New notes are added as keys + + on the fly. While a note has been attacked, but not released, the value of + the + + key is the audiovoice which is generating that note. When notes are + released, + + the value of the key becomes undefined.

+ path: .././src/content/reference/en//p5.PolySynth/notes + polyvalue: + description: | +

A PolySynth must have at least 1 voice, defaults to 8

+ path: .././src/content/reference/en//p5.PolySynth/polyvalue + AudioVoice: + description: | +

Monosynth that generates the sound for each note that is triggered. The + p5.PolySynth defaults to using the p5.MonoSynth as its voice.

+ path: .././src/content/reference/en//p5.PolySynth/AudioVoice + play: + description: > +

Play a note by triggering noteAttack and noteRelease with sustain + time

+ path: .././src/content/reference/en//p5.PolySynth/play + noteADSR: + description: > +

noteADSR sets the envelope for a specific note that has just been + triggered. + + Using this method modifies the envelope of whichever audiovoice is being + used + + to play the desired note. The envelope should be reset before noteRelease + is called + + in order to prevent the modified envelope from being used on other + notes.

+ path: .././src/content/reference/en//p5.PolySynth/noteADSR + setADSR: + description: > +

Set the PolySynths global envelope. This method modifies the envelopes + of each + + monosynth so that all notes are played with this envelope.

+ path: .././src/content/reference/en//p5.PolySynth/setADSR + noteAttack: + description: | +

Trigger the Attack, and Decay portion of a MonoSynth. + Similar to holding down a key on a piano, but it will + hold the sustain level until you let go.

+ path: .././src/content/reference/en//p5.PolySynth/noteAttack + noteRelease: + description: | +

Trigger the Release of an AudioVoice note. This is similar to releasing + the key on a piano and letting the sound fade according to the + release level and release time.

+ path: .././src/content/reference/en//p5.PolySynth/noteRelease + connect: + description: | +

Connect to a p5.sound / Web Audio object.

+ path: .././src/content/reference/en//p5.PolySynth/connect + disconnect: + description: | +

Disconnect all outputs

+ path: .././src/content/reference/en//p5.PolySynth/disconnect + dispose: + description: | +

Get rid of the MonoSynth and free up its resources / memory.

+ path: .././src/content/reference/en//p5.PolySynth/dispose +--- + + +# p5.PolySynth diff --git a/src/content/reference/en/p5.sound/p5.Pulse.mdx b/src/content/reference/en/p5.sound/p5.Pulse.mdx new file mode 100644 index 0000000000..7910ed69a7 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Pulse.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Pulse +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Creates a Pulse object, an oscillator that implements + Pulse Width Modulation. + The pulse is created with two oscillators. + Accepts a parameter for frequency, and to set the + width between the pulses. See + p5.Oscillator for a full list of methods.

+isConstructor: true +line: 5779 +params: + - name: freq + description: | +

Frequency in oscillations per second (Hz)

+ type: Number + optional: true + - name: w + description: | +

Width between the pulses (0 to 1.0, + defaults to 0)

+ type: Number + optional: true +memberMethodPreviews: + width: + description: | +

Set the width of a Pulse object (an oscillator that implements + Pulse Width Modulation).

+ path: .././src/content/reference/en//p5.Pulse/width +--- + + +# p5.Pulse diff --git a/src/content/reference/en/p5.sound/p5.Reverb.mdx b/src/content/reference/en/p5.sound/p5.Reverb.mdx new file mode 100644 index 0000000000..8d703bb1a4 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Reverb.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Reverb +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Reverb adds depth to a sound through a large number of decaying + + echoes. It creates the perception that sound is occurring in a + + physical space. The p5.Reverb has paramters for Time (how long does the + + reverb last) and decayRate (how much the sound decays with each echo) + + that can be set with the .set() or .process() methods. The p5.Convolver + + extends p5.Reverb allowing you to recreate the sound of actual physical + + spaces through convolution.

+ +

This class extends p5.Effect. + + Methods amp(), chain(), + + drywet(), connect(), and + + disconnect() are + available.

+isConstructor: true +line: 8308 +memberMethodPreviews: + process: + description: | +

Connect a source to the reverb, and assign reverb parameters.

+ path: .././src/content/reference/en//p5.Reverb/process + set: + description: | +

Set the reverb settings. Similar to .process(), but without + assigning a new input.

+ path: .././src/content/reference/en//p5.Reverb/set + amp: + description: | +

Set the output level of the reverb effect.

+ path: .././src/content/reference/en//p5.Reverb/amp + connect: + description: | +

Send output to a p5.sound or web audio object

+ path: .././src/content/reference/en//p5.Reverb/connect + disconnect: + description: | +

Disconnect all output.

+ path: .././src/content/reference/en//p5.Reverb/disconnect +--- + + +# p5.Reverb diff --git a/src/content/reference/en/p5.sound/p5.SawOsc.mdx b/src/content/reference/en/p5.sound/p5.SawOsc.mdx new file mode 100644 index 0000000000..bda11239aa --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SawOsc.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SawOsc +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.SawOsc(). + This creates a SawTooth Wave Oscillator and is + equivalent to new p5.Oscillator('sawtooth') + or creating a p5.Oscillator and then calling + its method setType('sawtooth'). + See p5.Oscillator for methods.

+isConstructor: true +line: 4656 +params: + - name: freq + description: | +

Set the frequency

+ type: Number + optional: true +--- + + +# p5.SawOsc diff --git a/src/content/reference/en/p5.sound/p5.Score.mdx b/src/content/reference/en/p5.sound/p5.Score.mdx new file mode 100644 index 0000000000..d029d07569 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.Score.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Score +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

A Score consists of a series of Parts. The parts will + be played back in order. For example, you could have an + A part, a B part, and a C part, and play them back in this order + new p5.Score(a, a, b, a, c)

+isConstructor: true +line: 9493 +params: + - name: parts + description: | +

One or multiple parts, to be played in sequence.

+ type: p5.Part + optional: true + multiple: true +memberMethodPreviews: + start: + description: | +

Start playback of the score.

+ path: .././src/content/reference/en//p5.Score/start + stop: + description: | +

Stop playback of the score.

+ path: .././src/content/reference/en//p5.Score/stop + pause: + description: | +

Pause playback of the score.

+ path: .././src/content/reference/en//p5.Score/pause + loop: + description: | +

Loop playback of the score.

+ path: .././src/content/reference/en//p5.Score/loop + noLoop: + description: | +

Stop looping playback of the score. If it + is currently playing, this will go into effect + after the current round of playback completes.

+ path: .././src/content/reference/en//p5.Score/noLoop + setBPM: + description: | +

Set the tempo for all parts in the score

+ path: .././src/content/reference/en//p5.Score/setBPM +--- + + +# p5.Score diff --git a/src/content/reference/en/p5.sound/p5.SinOsc.mdx b/src/content/reference/en/p5.sound/p5.SinOsc.mdx new file mode 100644 index 0000000000..7b931dc10b --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SinOsc.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SinOsc +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.SinOsc(). + This creates a Sine Wave Oscillator and is + equivalent to new p5.Oscillator('sine') + or creating a p5.Oscillator and then calling + its method setType('sine'). + See p5.Oscillator for methods.

+isConstructor: true +line: 4602 +params: + - name: freq + description: | +

Set the frequency

+ type: Number + optional: true +--- + + +# p5.SinOsc diff --git a/src/content/reference/en/p5.sound/p5.SoundFile.mdx b/src/content/reference/en/p5.sound/p5.SoundFile.mdx new file mode 100644 index 0000000000..a14025a303 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SoundFile.mdx @@ -0,0 +1,276 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SoundFile +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

SoundFile object with a path to a file.

+ +

The p5.SoundFile may not be available immediately because + it loads the file information asynchronously.

+ +

To do something with the sound as soon as it loads + pass the name of a function as the second parameter.

+ +

Only one file path is required. However, audio file formats + (i.e. mp3, ogg, wav and m4a/aac) are not supported by all + web browsers. If you want to ensure compatability, instead of a single + file path, you may include an Array of filepaths, and the browser will + choose a format that works.

+isConstructor: true +line: 1405 +params: + - name: path + description: | +

path to a sound file (String). Optionally, + you may include multiple file formats in + an array. Alternately, accepts an object + from the HTML5 File API, or a p5.File.

+ type: String|Array + - name: successCallback + description: | +

Name of a function to call once file loads

+ type: Function + optional: true + - name: errorCallback + description: | +

Name of a function to call if file fails to + load. This function will receive an error or + XMLHttpRequest object with information + about what went wrong.

+ type: Function + optional: true + - name: whileLoadingCallback + description: | +

Name of a function to call while file + is loading. That function will + receive progress of the request to + load the sound file + (between 0 and 1) as its first + parameter. This progress + does not account for the additional + time needed to decode the audio data.

+ type: Function + optional: true +memberMethodPreviews: + isLoaded: + description: | +

Returns true if the sound file finished loading successfully.

+ path: .././src/content/reference/en//p5.SoundFile/isLoaded + play: + description: | +

Play the p5.SoundFile

+ path: .././src/content/reference/en//p5.SoundFile/play + playMode: + description: | +

p5.SoundFile has two play modes: restart and + sustain. Play Mode determines what happens to a + p5.SoundFile if it is triggered while in the middle of playback. + In sustain mode, playback will continue simultaneous to the + new playback. In restart mode, play() will stop playback + and start over. With untilDone, a sound will play only if it's + not already playing. Sustain is the default mode.

+ path: .././src/content/reference/en//p5.SoundFile/playMode + pause: + description: | +

Pauses a file that is currently playing. If the file is not + playing, then nothing will happen.

+

After pausing, .play() will resume from the paused + position. + If p5.SoundFile had been set to loop before it was paused, + it will continue to loop after it is unpaused with .play().

+ path: .././src/content/reference/en//p5.SoundFile/pause + loop: + description: | +

Loop the p5.SoundFile. Accepts optional parameters to set the + playback rate, playback volume, loopStart, loopEnd.

+ path: .././src/content/reference/en//p5.SoundFile/loop + setLoop: + description: | +

Set a p5.SoundFile's looping flag to true or false. If the sound + is currently playing, this change will take effect when it + reaches the end of the current playback.

+ path: .././src/content/reference/en//p5.SoundFile/setLoop + isLooping: + description: > +

Returns 'true' if a p5.SoundFile is currently looping and playing, + 'false' if not.

+ path: .././src/content/reference/en//p5.SoundFile/isLooping + isPlaying: + description: | +

Returns true if a p5.SoundFile is playing, false if not (i.e. + paused or stopped).

+ path: .././src/content/reference/en//p5.SoundFile/isPlaying + isPaused: + description: | +

Returns true if a p5.SoundFile is paused, false if not (i.e. + playing or stopped).

+ path: .././src/content/reference/en//p5.SoundFile/isPaused + stop: + description: | +

Stop soundfile playback.

+ path: .././src/content/reference/en//p5.SoundFile/stop + pan: + description: | +

Set the stereo panning of a p5.sound object to + a floating point number between -1.0 (left) and 1.0 (right). + Default is 0.0 (center).

+ path: .././src/content/reference/en//p5.SoundFile/pan + getPan: + description: | +

Returns the current stereo pan position (-1.0 to 1.0)

+ path: .././src/content/reference/en//p5.SoundFile/getPan + rate: + description: > +

Set the playback rate of a sound file. Will change the speed and the + pitch. + + Values less than zero will reverse the audio buffer.

+ path: .././src/content/reference/en//p5.SoundFile/rate + setVolume: + description: | +

Multiply the output volume (amplitude) of a sound file + between 0.0 (silence) and 1.0 (full volume). + 1.0 is the maximum amplitude of a digital sound, so multiplying + by greater than 1.0 may cause digital distortion. To + fade, provide a rampTime parameter. For more + complex fades, see the Envelope class.

+

Alternately, you can pass in a signal source such as an + oscillator to modulate the amplitude with an audio signal.

+ path: .././src/content/reference/en//p5.SoundFile/setVolume + duration: + description: | +

Returns the duration of a sound file in seconds.

+ path: .././src/content/reference/en//p5.SoundFile/duration + currentTime: + description: > +

Return the current position of the p5.SoundFile playhead, in seconds. + + Time is relative to the normal buffer direction, so if + reverseBuffer + + has been called, currentTime will count backwards.

+ path: .././src/content/reference/en//p5.SoundFile/currentTime + jump: + description: > +

Move the playhead of a soundfile that is currently playing to a + + new position and a new duration, in seconds. + + If none are given, will reset the file to play entire duration + + from start to finish. To set the position of a soundfile that is + + not currently playing, use the play or loop + methods.

+ path: .././src/content/reference/en//p5.SoundFile/jump + channels: + description: | +

Return the number of channels in a sound file. + For example, Mono = 1, Stereo = 2.

+ path: .././src/content/reference/en//p5.SoundFile/channels + sampleRate: + description: | +

Return the sample rate of the sound file.

+ path: .././src/content/reference/en//p5.SoundFile/sampleRate + frames: + description: | +

Return the number of samples in a sound file. + Equal to sampleRate * duration.

+ path: .././src/content/reference/en//p5.SoundFile/frames + getPeaks: + description: | +

Returns an array of amplitude peaks in a p5.SoundFile that can be + used to draw a static waveform. Scans through the p5.SoundFile's + audio buffer to find the greatest amplitudes. Accepts one + parameter, 'length', which determines size of the array. + Larger arrays result in more precise waveform visualizations.

+

Inspired by Wavesurfer.js.

+ path: .././src/content/reference/en//p5.SoundFile/getPeaks + reverseBuffer: + description: | +

Reverses the p5.SoundFile's buffer source. + Playback must be handled separately (see example).

+ path: .././src/content/reference/en//p5.SoundFile/reverseBuffer + onended: + description: | +

Schedule an event to be called when the soundfile + reaches the end of a buffer. If the soundfile is + playing through once, this will be called when it + ends. If it is looping, it will be called when + stop is called.

+ path: .././src/content/reference/en//p5.SoundFile/onended + connect: + description: | +

Connects the output of a p5sound object to input of another + p5.sound object. For example, you may connect a p5.SoundFile to an + FFT or an Effect. If no parameter is given, it will connect to + the main output. Most p5sound objects connect to the master + output when they are created.

+ path: .././src/content/reference/en//p5.SoundFile/connect + disconnect: + description: | +

Disconnects the output of this p5sound object.

+ path: .././src/content/reference/en//p5.SoundFile/disconnect + setPath: + description: | +

Reset the source for this SoundFile to a + new path (URL).

+ path: .././src/content/reference/en//p5.SoundFile/setPath + setBuffer: + description: | +

Replace the current Audio Buffer with a new Buffer.

+ path: .././src/content/reference/en//p5.SoundFile/setBuffer + addCue: + description: | +

Schedule events to trigger every time a MediaElement + (audio/video) reaches a playback cue point.

+

Accepts a callback function, a time (in seconds) at which to trigger + the callback, and an optional parameter for the callback.

+

Time will be passed as the first parameter to the callback function, + and param will be the second parameter.

+ path: .././src/content/reference/en//p5.SoundFile/addCue + removeCue: + description: | +

Remove a callback based on its ID. The ID is returned by the + addCue method.

+ path: .././src/content/reference/en//p5.SoundFile/removeCue + clearCues: + description: | +

Remove all of the callbacks that had originally been scheduled + via the addCue method.

+ path: .././src/content/reference/en//p5.SoundFile/clearCues + save: + description: | +

Save a p5.SoundFile as a .wav file. The browser will prompt the user + to download the file to their device. To upload a file to a server, see + getBlob

+ path: .././src/content/reference/en//p5.SoundFile/save + getBlob: + description: > +

This method is useful for sending a SoundFile to a server. It returns + the + + .wav-encoded audio data as a "Blob". + + A Blob is a file-like data object that can be uploaded to a server + + with an http request. We'll + + use the httpDo options object to send a POST request with + some + + specific options: we encode the request as + multipart/form-data, + + and attach the blob as one of the form values using + FormData.

+ path: .././src/content/reference/en//p5.SoundFile/getBlob +--- + + +# p5.SoundFile diff --git a/src/content/reference/en/p5.sound/p5.SoundLoop.mdx b/src/content/reference/en/p5.sound/p5.SoundLoop.mdx new file mode 100644 index 0000000000..5b6d11f4d4 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SoundLoop.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SoundLoop +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

SoundLoop

+isConstructor: true +line: 9673 +params: + - name: callback + description: | +

this function will be called on each iteration of theloop

+ type: Function + - name: interval + description: > +

amount of time (if a number) or beats (if a string, following Tone.Time convention) + for each iteration of the loop. Defaults to 1 second.

+ type: Number|String + optional: true +memberMethodPreviews: + bpm: + description: > +

Getters and Setters, setting any paramter will result in a change in + the clock's + + frequency, that will be reflected after the next callback + + beats per minute (defaults to 60)

+ path: .././src/content/reference/en//p5.SoundLoop/bpm + timeSignature: + description: | +

number of quarter notes in a measure (defaults to 4)

+ path: .././src/content/reference/en//p5.SoundLoop/timeSignature + interval: + description: | +

length of the loops interval

+ path: .././src/content/reference/en//p5.SoundLoop/interval + iterations: + description: | +

how many times the callback has been called so far

+ path: .././src/content/reference/en//p5.SoundLoop/iterations + musicalTimeMode: + description: > +

musicalTimeMode uses Tone.Time convention + + true if string, false if number

+ path: .././src/content/reference/en//p5.SoundLoop/musicalTimeMode + maxIterations: + description: | +

Set a limit to the number of loops to play. defaults to Infinity

+ path: .././src/content/reference/en//p5.SoundLoop/maxIterations + start: + description: | +

Start the loop

+ path: .././src/content/reference/en//p5.SoundLoop/start + stop: + description: | +

Stop the loop

+ path: .././src/content/reference/en//p5.SoundLoop/stop + pause: + description: | +

Pause the loop

+ path: .././src/content/reference/en//p5.SoundLoop/pause + syncedStart: + description: > +

Synchronize loops. Use this method to start two or more loops in + synchronization + + or to start a loop in synchronization with a loop that is already playing + + This method will schedule the implicit loop in sync with the explicit + master loop + + i.e. loopToStart.syncedStart(loopToSyncWith)

+ path: .././src/content/reference/en//p5.SoundLoop/syncedStart +--- + + +# p5.SoundLoop diff --git a/src/content/reference/en/p5.sound/p5.SoundRecorder.mdx b/src/content/reference/en/p5.sound/p5.SoundRecorder.mdx new file mode 100644 index 0000000000..bb02b7ef04 --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SoundRecorder.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SoundRecorder +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

Record sounds for playback and/or to save as a .wav file. + The p5.SoundRecorder records all sound output from your sketch, + or can be assigned a specific source with setInput().

+

The record() method accepts a p5.SoundFile as a parameter. + When playback is stopped (either after the given amount of time, + or with the stop() method), the p5.SoundRecorder will send its + recording to that p5.SoundFile for playback.

+isConstructor: true +line: 10559 +memberMethodPreviews: + setInput: + description: | +

Connect a specific device to the p5.SoundRecorder. + If no parameter is given, p5.SoundRecorer will record + all audible p5.sound from your sketch.

+ path: .././src/content/reference/en//p5.SoundRecorder/setInput + record: + description: | +

Start recording. To access the recording, provide + a p5.SoundFile as the first parameter. The p5.SoundRecorder + will send its recording to that p5.SoundFile for playback once + recording is complete. Optional parameters include duration + (in seconds) of the recording, and a callback function that + will be called once the complete recording has been + transfered to the p5.SoundFile.

+ path: .././src/content/reference/en//p5.SoundRecorder/record + stop: + description: | +

Stop the recording. Once the recording is stopped, + the results will be sent to the p5.SoundFile that + was given on .record(), and if a callback function + was provided on record, that function will be called.

+ path: .././src/content/reference/en//p5.SoundRecorder/stop +--- + + +# p5.SoundRecorder diff --git a/src/content/reference/en/p5.sound/p5.SqrOsc.mdx b/src/content/reference/en/p5.sound/p5.SqrOsc.mdx new file mode 100644 index 0000000000..f5157a7b5e --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.SqrOsc.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.SqrOsc +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.SqrOsc(). + This creates a Square Wave Oscillator and is + equivalent to new p5.Oscillator('square') + or creating a p5.Oscillator and then calling + its method setType('square'). + See p5.Oscillator for methods.

+isConstructor: true +line: 4683 +params: + - name: freq + description: | +

Set the frequency

+ type: Number + optional: true +--- + + +# p5.SqrOsc diff --git a/src/content/reference/en/p5.sound/p5.TriOsc.mdx b/src/content/reference/en/p5.sound/p5.TriOsc.mdx new file mode 100644 index 0000000000..953f891d5e --- /dev/null +++ b/src/content/reference/en/p5.sound/p5.TriOsc.mdx @@ -0,0 +1,25 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.TriOsc +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Constructor: new p5.TriOsc(). + This creates a Triangle Wave Oscillator and is + equivalent to new p5.Oscillator('triangle') + or creating a p5.Oscillator and then calling + its method setType('triangle'). + See p5.Oscillator for methods.

+isConstructor: true +line: 4629 +params: + - name: freq + description: | +

Set the frequency

+ type: Number + optional: true +--- + + +# p5.TriOsc diff --git a/src/content/reference/en/p5/>.mdx b/src/content/reference/en/p5/>.mdx new file mode 100644 index 0000000000..b3fb8a2c98 --- /dev/null +++ b/src/content/reference/en/p5/>.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: '>' +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: >- +

The greater than operator > + + evaluates to true if the left value is greater than + + the right value.

+ + + + There is more info on comparison operators on MDN. +line: 115 +itemtype: property +class: p5 +example: + - |- + +
+ + console.log(100 > 1); // prints true to the console + console.log(1 > 100); // prints false to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# > diff --git a/src/content/reference/en/p5/>=.mdx b/src/content/reference/en/p5/>=.mdx new file mode 100644 index 0000000000..064748cc69 --- /dev/null +++ b/src/content/reference/en/p5/>=.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: '>=' +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

The greater than or equal to operator >= + + evaluates to true if the left value is greater than or equal to + + the right value.

+ +

There + is more info on comparison operators on MDN.

+line: 137 +itemtype: property +class: p5 +example: + - |- + +
+ + console.log(100 >= 100); // prints true to the console + console.log(101 >= 100); // prints true to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# >= diff --git a/src/content/reference/en/p5/<.mdx b/src/content/reference/en/p5/<.mdx new file mode 100644 index 0000000000..97c2d54428 --- /dev/null +++ b/src/content/reference/en/p5/<.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: '<' +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

The less than operator < + + evaluates to true if the left value is less than + + the right value.

+ +

There + is more info on comparison operators on MDN.

+line: 158 +itemtype: property +class: p5 +example: + - |- + +
+ + console.log(1 < 100); // prints true to the console + console.log(100 < 99); // prints false to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# \< diff --git a/src/content/reference/en/p5/<=.mdx b/src/content/reference/en/p5/<=.mdx new file mode 100644 index 0000000000..7d71c7cc6d --- /dev/null +++ b/src/content/reference/en/p5/<=.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: '<=' +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

The less than or equal to operator <= + + evaluates to true if the left value is less than or equal to + + the right value.

+ +

There + is more info on comparison operators on MDN.

+line: 179 +itemtype: property +class: p5 +example: + - |- + +
+ + console.log(100 <= 100); // prints true to the console + console.log(99 <= 100); // prints true to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# \<= diff --git a/src/content/reference/en/p5/===.mdx b/src/content/reference/en/p5/===.mdx new file mode 100644 index 0000000000..8e7ff5402b --- /dev/null +++ b/src/content/reference/en/p5/===.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: '===' +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

The strict equality operator === + + checks to see if two values are equal and of the same type.

+ +

A comparison expression always evaluates to a boolean.

+ +

From the + MDN entry: + + The non-identity operator returns true if the operands are not equal and/or + not of the same type.

+ +

Note: In some examples around the web you may see a double-equals-sign + + ==, + + used for comparison instead. This is the non-strict equality operator in + Javascript. + + This will convert the two values being compared to the same type before + comparing them.

+line: 87 +itemtype: property +class: p5 +example: + - |- + +
+ + console.log(1 === 1); // prints true to the console + console.log(1 === '1'); // prints false to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# === diff --git a/src/content/reference/en/p5/ADD.mdx b/src/content/reference/en/p5/ADD.mdx new file mode 100644 index 0000000000..219ea410c2 --- /dev/null +++ b/src/content/reference/en/p5/ADD.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ADD +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 480 +itemtype: property +class: p5 +chainable: false +--- + + +# ADD diff --git a/src/content/reference/en/p5/ALT.mdx b/src/content/reference/en/p5/ALT.mdx new file mode 100644 index 0000000000..228b7e059e --- /dev/null +++ b/src/content/reference/en/p5/ALT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ALT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 395 +itemtype: property +class: p5 +chainable: false +--- + + +# ALT diff --git a/src/content/reference/en/p5/ARROW.mdx b/src/content/reference/en/p5/ARROW.mdx new file mode 100644 index 0000000000..0420bd9658 --- /dev/null +++ b/src/content/reference/en/p5/ARROW.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ARROW +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 55 +itemtype: property +class: p5 +chainable: false +--- + + +# ARROW diff --git a/src/content/reference/en/p5/AUTO.mdx b/src/content/reference/en/p5/AUTO.mdx new file mode 100644 index 0000000000..8b66456e92 --- /dev/null +++ b/src/content/reference/en/p5/AUTO.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: AUTO +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

AUTO allows us to automatically set the width or height of an element (but + not both), + + based on the current height and width of the element. Only one parameter can + + be passed to the size function as + AUTO, at a time.

+line: 385 +itemtype: property +class: p5 +chainable: false +--- + + +# AUTO diff --git a/src/content/reference/en/p5/AXES.mdx b/src/content/reference/en/p5/AXES.mdx new file mode 100644 index 0000000000..7564399e8f --- /dev/null +++ b/src/content/reference/en/p5/AXES.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: AXES +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 746 +itemtype: property +class: p5 +chainable: false +--- + + +# AXES diff --git a/src/content/reference/en/p5/BACKSPACE.mdx b/src/content/reference/en/p5/BACKSPACE.mdx new file mode 100644 index 0000000000..8e98b11ad7 --- /dev/null +++ b/src/content/reference/en/p5/BACKSPACE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BACKSPACE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 401 +itemtype: property +class: p5 +chainable: false +--- + + +# BACKSPACE diff --git a/src/content/reference/en/p5/BASELINE.mdx b/src/content/reference/en/p5/BASELINE.mdx new file mode 100644 index 0000000000..7abeb9595b --- /dev/null +++ b/src/content/reference/en/p5/BASELINE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BASELINE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 250 +itemtype: property +class: p5 +chainable: false +--- + + +# BASELINE diff --git a/src/content/reference/en/p5/BEVEL.mdx b/src/content/reference/en/p5/BEVEL.mdx new file mode 100644 index 0000000000..78836d5236 --- /dev/null +++ b/src/content/reference/en/p5/BEVEL.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BEVEL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 352 +itemtype: property +class: p5 +chainable: false +--- + + +# BEVEL diff --git a/src/content/reference/en/p5/BLEND.mdx b/src/content/reference/en/p5/BLEND.mdx new file mode 100644 index 0000000000..c684fdee63 --- /dev/null +++ b/src/content/reference/en/p5/BLEND.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: blend +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Copies a region of pixels from one image to another. The + blendMode + + parameter blends the images' colors to create different effects.

+line: 106 +itemtype: method +class: p5 +example: + - |- + +
+ + let img0; + let img1; + + function preload() { + img0 = loadImage('assets/rockies.jpg'); + img1 = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + background(img0); + image(img1, 0, 0); + blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.'); + } + +
+ +
+ + let img0; + let img1; + + function preload() { + img0 = loadImage('assets/rockies.jpg'); + img1 = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + background(img0); + image(img1, 0, 0); + blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.'); + } + +
+ +
+ + let img0; + let img1; + + function preload() { + img0 = loadImage('assets/rockies.jpg'); + img1 = loadImage('assets/bricks_third.jpg'); + } + + function setup() { + background(img0); + image(img1, 0, 0); + blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD); + + describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.'); + } + +
+chainable: false +--- + + +# blend diff --git a/src/content/reference/en/p5/BLUR.mdx b/src/content/reference/en/p5/BLUR.mdx new file mode 100644 index 0000000000..52c76679a2 --- /dev/null +++ b/src/content/reference/en/p5/BLUR.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BLUR +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 594 +itemtype: property +class: p5 +chainable: false +--- + + +# BLUR diff --git a/src/content/reference/en/p5/BOLD.mdx b/src/content/reference/en/p5/BOLD.mdx new file mode 100644 index 0000000000..13057eba9e --- /dev/null +++ b/src/content/reference/en/p5/BOLD.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BOLD +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 611 +itemtype: property +class: p5 +chainable: false +--- + + +# BOLD diff --git a/src/content/reference/en/p5/BOLDITALIC.mdx b/src/content/reference/en/p5/BOLDITALIC.mdx new file mode 100644 index 0000000000..ac4489c1ea --- /dev/null +++ b/src/content/reference/en/p5/BOLDITALIC.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BOLDITALIC +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 616 +itemtype: property +class: p5 +chainable: false +--- + + +# BOLDITALIC diff --git a/src/content/reference/en/p5/BOTTOM.mdx b/src/content/reference/en/p5/BOTTOM.mdx new file mode 100644 index 0000000000..542c1b1302 --- /dev/null +++ b/src/content/reference/en/p5/BOTTOM.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BOTTOM +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 245 +itemtype: property +class: p5 +chainable: false +--- + + +# BOTTOM diff --git a/src/content/reference/en/p5/BURN.mdx b/src/content/reference/en/p5/BURN.mdx new file mode 100644 index 0000000000..1710a1df27 --- /dev/null +++ b/src/content/reference/en/p5/BURN.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BURN +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 551 +itemtype: property +class: p5 +chainable: false +--- + + +# BURN diff --git a/src/content/reference/en/p5/CENTER.mdx b/src/content/reference/en/p5/CENTER.mdx new file mode 100644 index 0000000000..0daf0f0c41 --- /dev/null +++ b/src/content/reference/en/p5/CENTER.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CENTER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 235 +itemtype: property +class: p5 +chainable: false +--- + + +# CENTER diff --git a/src/content/reference/en/p5/CHAR.mdx b/src/content/reference/en/p5/CHAR.mdx new file mode 100644 index 0000000000..a8cc701122 --- /dev/null +++ b/src/content/reference/en/p5/CHAR.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: char +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a number or string to its corresponding single-character + string representation. If a string parameter is provided, it is first + parsed as an integer and then translated into a single-character string. + When an array of number or string values is passed in, then an array of + single-character strings of the same length is returned.

+line: 180 +itemtype: method +class: p5 +example: + - |- + +
+ print(char(65)); // "A" + print(char('65')); // "A" + print(char([65, 66, 67])); // [ "A", "B", "C" ] + print(join(char([65, 66, 67]), '')); // "ABC" +
+return: + description: string representation of value + type: String +chainable: false +--- + + +# char diff --git a/src/content/reference/en/p5/CHORD.mdx b/src/content/reference/en/p5/CHORD.mdx new file mode 100644 index 0000000000..60c6989166 --- /dev/null +++ b/src/content/reference/en/p5/CHORD.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CHORD +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 325 +itemtype: property +class: p5 +chainable: false +--- + + +# CHORD diff --git a/src/content/reference/en/p5/CLAMP.mdx b/src/content/reference/en/p5/CLAMP.mdx new file mode 100644 index 0000000000..aa06f73d8e --- /dev/null +++ b/src/content/reference/en/p5/CLAMP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CLAMP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 701 +itemtype: property +class: p5 +chainable: false +--- + + +# CLAMP diff --git a/src/content/reference/en/p5/CLOSE.mdx b/src/content/reference/en/p5/CLOSE.mdx new file mode 100644 index 0000000000..f412a62acd --- /dev/null +++ b/src/content/reference/en/p5/CLOSE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CLOSE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 315 +itemtype: property +class: p5 +chainable: false +--- + + +# CLOSE diff --git a/src/content/reference/en/p5/CONTAIN.mdx b/src/content/reference/en/p5/CONTAIN.mdx new file mode 100644 index 0000000000..bf9aaf6e90 --- /dev/null +++ b/src/content/reference/en/p5/CONTAIN.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CONTAIN +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 763 +itemtype: property +class: p5 +chainable: false +--- + + +# CONTAIN diff --git a/src/content/reference/en/p5/CONTROL.mdx b/src/content/reference/en/p5/CONTROL.mdx new file mode 100644 index 0000000000..eb03c2a43e --- /dev/null +++ b/src/content/reference/en/p5/CONTROL.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CONTROL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 406 +itemtype: property +class: p5 +chainable: false +--- + + +# CONTROL diff --git a/src/content/reference/en/p5/CORNER.mdx b/src/content/reference/en/p5/CORNER.mdx new file mode 100644 index 0000000000..0fa56eb0a2 --- /dev/null +++ b/src/content/reference/en/p5/CORNER.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CORNER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 210 +itemtype: property +class: p5 +chainable: false +--- + + +# CORNER diff --git a/src/content/reference/en/p5/CORNERS.mdx b/src/content/reference/en/p5/CORNERS.mdx new file mode 100644 index 0000000000..e5df1dce11 --- /dev/null +++ b/src/content/reference/en/p5/CORNERS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CORNERS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 215 +itemtype: property +class: p5 +chainable: false +--- + + +# CORNERS diff --git a/src/content/reference/en/p5/COVER.mdx b/src/content/reference/en/p5/COVER.mdx new file mode 100644 index 0000000000..42f966f477 --- /dev/null +++ b/src/content/reference/en/p5/COVER.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: COVER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 769 +itemtype: property +class: p5 +chainable: false +--- + + +# COVER diff --git a/src/content/reference/en/p5/CROSS.mdx b/src/content/reference/en/p5/CROSS.mdx new file mode 100644 index 0000000000..0d5b2806b1 --- /dev/null +++ b/src/content/reference/en/p5/CROSS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CROSS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 60 +itemtype: property +class: p5 +chainable: false +--- + + +# CROSS diff --git a/src/content/reference/en/p5/DARKEST.mdx b/src/content/reference/en/p5/DARKEST.mdx new file mode 100644 index 0000000000..efdd908a3d --- /dev/null +++ b/src/content/reference/en/p5/DARKEST.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DARKEST +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 488 +itemtype: property +class: p5 +chainable: false +--- + + +# DARKEST diff --git a/src/content/reference/en/p5/DEGREES.mdx b/src/content/reference/en/p5/DEGREES.mdx new file mode 100644 index 0000000000..b0f56fa74b --- /dev/null +++ b/src/content/reference/en/p5/DEGREES.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: degrees +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: | +

Converts an angle measurement in radians to its corresponding value in + degrees. Degrees and radians are two ways of measuring the same thing. + There are 360 degrees in a circle and 2 × π (about 6.28) + radians in a circle. For example, 90° = π ÷ 2 (about 1.57) + radians. This function doesn't take into account the current + angleMode().

+line: 322 +params: + - name: radians + description: | +

radians value to convert to degrees.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let rad = QUARTER_PI; + let deg = degrees(rad); + text(`${round(rad, 2)} rad = ${deg}˚`, 10, 50); + + describe('The text "0.79 rad = 45˚".'); + +
+return: + description: converted angle. + type: Number +chainable: false +--- + + +# degrees diff --git a/src/content/reference/en/p5/DELETE.mdx b/src/content/reference/en/p5/DELETE.mdx new file mode 100644 index 0000000000..50baa241ea --- /dev/null +++ b/src/content/reference/en/p5/DELETE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DELETE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 411 +itemtype: property +class: p5 +chainable: false +--- + + +# DELETE diff --git a/src/content/reference/en/p5/DIFFERENCE.mdx b/src/content/reference/en/p5/DIFFERENCE.mdx new file mode 100644 index 0000000000..fb2c9444c3 --- /dev/null +++ b/src/content/reference/en/p5/DIFFERENCE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DIFFERENCE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 499 +itemtype: property +class: p5 +chainable: false +--- + + +# DIFFERENCE diff --git a/src/content/reference/en/p5/DILATE.mdx b/src/content/reference/en/p5/DILATE.mdx new file mode 100644 index 0000000000..ca835f5c5c --- /dev/null +++ b/src/content/reference/en/p5/DILATE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DILATE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 584 +itemtype: property +class: p5 +chainable: false +--- + + +# DILATE diff --git a/src/content/reference/en/p5/DODGE.mdx b/src/content/reference/en/p5/DODGE.mdx new file mode 100644 index 0000000000..25d0981555 --- /dev/null +++ b/src/content/reference/en/p5/DODGE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DODGE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 545 +itemtype: property +class: p5 +chainable: false +--- + + +# DODGE diff --git a/src/content/reference/en/p5/DOWN_ARROW.mdx b/src/content/reference/en/p5/DOWN_ARROW.mdx new file mode 100644 index 0000000000..0cf5aacb69 --- /dev/null +++ b/src/content/reference/en/p5/DOWN_ARROW.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: DOWN_ARROW +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 416 +itemtype: property +class: p5 +chainable: false +--- + + +# DOWN\_ARROW diff --git a/src/content/reference/en/p5/ENTER.mdx b/src/content/reference/en/p5/ENTER.mdx new file mode 100644 index 0000000000..7a6297faea --- /dev/null +++ b/src/content/reference/en/p5/ENTER.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ENTER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 421 +itemtype: property +class: p5 +chainable: false +--- + + +# ENTER diff --git a/src/content/reference/en/p5/ERODE.mdx b/src/content/reference/en/p5/ERODE.mdx new file mode 100644 index 0000000000..9b30c7cc9f --- /dev/null +++ b/src/content/reference/en/p5/ERODE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ERODE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 589 +itemtype: property +class: p5 +chainable: false +--- + + +# ERODE diff --git a/src/content/reference/en/p5/ESCAPE.mdx b/src/content/reference/en/p5/ESCAPE.mdx new file mode 100644 index 0000000000..8513f45dcd --- /dev/null +++ b/src/content/reference/en/p5/ESCAPE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ESCAPE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 426 +itemtype: property +class: p5 +chainable: false +--- + + +# ESCAPE diff --git a/src/content/reference/en/p5/EXCLUSION.mdx b/src/content/reference/en/p5/EXCLUSION.mdx new file mode 100644 index 0000000000..3b18f48b05 --- /dev/null +++ b/src/content/reference/en/p5/EXCLUSION.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: EXCLUSION +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 509 +itemtype: property +class: p5 +chainable: false +--- + + +# EXCLUSION diff --git a/src/content/reference/en/p5/FALLBACK.mdx b/src/content/reference/en/p5/FALLBACK.mdx new file mode 100644 index 0000000000..ac128d9420 --- /dev/null +++ b/src/content/reference/en/p5/FALLBACK.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: FALLBACK +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 757 +itemtype: property +class: p5 +chainable: false +--- + + +# FALLBACK diff --git a/src/content/reference/en/p5/FLAT.mdx b/src/content/reference/en/p5/FLAT.mdx new file mode 100644 index 0000000000..a41a5b795f --- /dev/null +++ b/src/content/reference/en/p5/FLAT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: FLAT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 713 +itemtype: property +class: p5 +chainable: false +--- + + +# FLAT diff --git a/src/content/reference/en/p5/FLOAT.mdx b/src/content/reference/en/p5/FLOAT.mdx new file mode 100644 index 0000000000..bc41289053 --- /dev/null +++ b/src/content/reference/en/p5/FLOAT.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: float +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a string to its floating point representation. The contents of a + string must resemble a number, or NaN (not a number) will be returned. + For example, float("1234.56") evaluates to 1234.56, but float("giraffe") + will return NaN.

+

When an array of values is passed in, then an array of floats of the same + length is returned.

+line: 10 +params: + - name: str + description: | +

float string to parse

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ let str = '20'; + let diameter = float(str); + ellipse(width / 2, height / 2, diameter, diameter); + describe('20-by-20 white ellipse in the center of the canvas'); +
+
+ print(float('10.31')); // 10.31 + print(float('Infinity')); // Infinity + print(float('-Infinity')); // -Infinity +
+return: + description: floating point representation of string + type: Number +chainable: false +--- + + +# float diff --git a/src/content/reference/en/p5/GRAY.mdx b/src/content/reference/en/p5/GRAY.mdx new file mode 100644 index 0000000000..3f4de1f9d3 --- /dev/null +++ b/src/content/reference/en/p5/GRAY.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: GRAY +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 564 +itemtype: property +class: p5 +chainable: false +--- + + +# GRAY diff --git a/src/content/reference/en/p5/GRID.mdx b/src/content/reference/en/p5/GRID.mdx new file mode 100644 index 0000000000..7d8ad74605 --- /dev/null +++ b/src/content/reference/en/p5/GRID.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: GRID +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 740 +itemtype: property +class: p5 +chainable: false +--- + + +# GRID diff --git a/src/content/reference/en/p5/HALF_FLOAT.mdx b/src/content/reference/en/p5/HALF_FLOAT.mdx new file mode 100644 index 0000000000..3bd653a82b --- /dev/null +++ b/src/content/reference/en/p5/HALF_FLOAT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HALF_FLOAT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 793 +itemtype: property +class: p5 +chainable: false +--- + + +# HALF\_FLOAT diff --git a/src/content/reference/en/p5/HALF_PI.mdx b/src/content/reference/en/p5/HALF_PI.mdx new file mode 100644 index 0000000000..43ef5b9bed --- /dev/null +++ b/src/content/reference/en/p5/HALF_PI.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HALF_PI +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

HALF_PI is a mathematical constant with the value + + 1.57079632679489661923. It is half the ratio of the + + circumference of a circle to its diameter. It is useful in + + combination with the trigonometric functions sin() and + cos().

+line: 88 +itemtype: property +class: p5 +example: + - |- + +
+ arc(50, 50, 80, 80, 0, HALF_PI); +
+alt: 80×80 white quarter-circle with curve toward bottom right of canvas. +chainable: false +--- + + +# HALF\_PI diff --git a/src/content/reference/en/p5/HAND.mdx b/src/content/reference/en/p5/HAND.mdx new file mode 100644 index 0000000000..e4a5105f66 --- /dev/null +++ b/src/content/reference/en/p5/HAND.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HAND +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 65 +itemtype: property +class: p5 +chainable: false +--- + + +# HAND diff --git a/src/content/reference/en/p5/HARD_LIGHT.mdx b/src/content/reference/en/p5/HARD_LIGHT.mdx new file mode 100644 index 0000000000..e961cefdec --- /dev/null +++ b/src/content/reference/en/p5/HARD_LIGHT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HARD_LIGHT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 535 +itemtype: property +class: p5 +chainable: false +--- + + +# HARD\_LIGHT diff --git a/src/content/reference/en/p5/HSB.mdx b/src/content/reference/en/p5/HSB.mdx new file mode 100644 index 0000000000..a3587e2cc9 --- /dev/null +++ b/src/content/reference/en/p5/HSB.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HSB +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

HSB (hue, saturation, brightness) is a type of color model. + + You can learn more about it at + + HSB.

+line: 369 +itemtype: property +class: p5 +chainable: false +--- + + +# HSB diff --git a/src/content/reference/en/p5/HSL.mdx b/src/content/reference/en/p5/HSL.mdx new file mode 100644 index 0000000000..93e7e243bd --- /dev/null +++ b/src/content/reference/en/p5/HSL.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: HSL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 378 +itemtype: property +class: p5 +chainable: false +--- + + +# HSL diff --git a/src/content/reference/en/p5/IMAGE.mdx b/src/content/reference/en/p5/IMAGE.mdx new file mode 100644 index 0000000000..71129ea15e --- /dev/null +++ b/src/content/reference/en/p5/IMAGE.mdx @@ -0,0 +1,191 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: image +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: > +

Draws a source image to the canvas.

+ +

The first parameter, img, is the source image to be drawn. The + second and + + third parameters, dx and dy, set the coordinates of + the destination + + image's top left corner. See imageMode() for + + other ways to position images.

+ +

Here's a diagram that explains how optional parameters work in + image():

+ +

+ +

The fourth and fifth parameters, dw and dh, are + optional. They set the + + the width and height to draw the destination image. By default, + image() + + draws the full source image at its original size.

+ +

The sixth and seventh parameters, sx and sy, are + also optional. + + These coordinates define the top left corner of a subsection to draw from + + the source image.

+ +

The eighth and ninth parameters, sw and sh, are + also optional. + + They define the width and height of a subsection to draw from the source + + image. By default, image() draws the full subsection that begins + at + + (sx, sy) and extends to the edges of the source + image.

+ +

The ninth parameter, fit, is also optional. It enables a + subsection of + + the source image to be drawn without affecting its aspect ratio. If + + CONTAIN is passed, the full subsection will appear within the + destination + + rectangle. If COVER is passed, the subsection will completely + cover the + + destination rectangle. This may have the effect of zooming into the + + subsection.

+ +

The tenth and eleventh paremeters, xAlign and + yAlign, are also + + optional. They determine how to align the fitted subsection. + xAlign can + + be set to either LEFT, RIGHT, or + CENTER. yAlign can be set to + + either TOP, BOTTOM, or CENTER. By + default, both xAlign and yAlign + + are set to CENTER.

+line: 832 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + background(50); + image(img, 0, 0); + + describe('An image of the underside of a white umbrella with a gridded ceiling above.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + background(50); + image(img, 10, 10); + + describe('An image of the underside of a white umbrella with a gridded ceiling above. The image has dark gray borders on its left and top.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + background(50); + image(img, 0, 0, 50, 50); + + describe('An image of the underside of a white umbrella with a gridded ceiling above. The image is drawn in the top left corner of a dark gray square.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + background(50); + image(img, 25, 25, 50, 50, 25, 25, 50, 50); + + describe('An image of a gridded ceiling drawn in the center of a dark gray square.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/moonwalk.jpg'); + } + + function setup() { + background(50); + image(img, 0, 0, width, height, 0, 0, img.width, img.height, CONTAIN); + + describe('An image of an astronaut on the moon. The top and bottom borders of the image are dark gray.'); + } + +
+ +
+ + let img; + + function preload() { + // Image is 50 x 50 pixels. + img = loadImage('assets/laDefense50.png'); + } + + function setup() { + background(50); + image(img, 0, 0, width, height, 0, 0, img.width, img.height, COVER); + + describe('A pixelated image of the underside of a white umbrella with a gridded ceiling above.'); + } + +
+chainable: false +--- + + +# image diff --git a/src/content/reference/en/p5/IMMEDIATE.mdx b/src/content/reference/en/p5/IMMEDIATE.mdx new file mode 100644 index 0000000000..ec6a720792 --- /dev/null +++ b/src/content/reference/en/p5/IMMEDIATE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: IMMEDIATE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 675 +itemtype: property +class: p5 +chainable: false +--- + + +# IMMEDIATE diff --git a/src/content/reference/en/p5/INVERT.mdx b/src/content/reference/en/p5/INVERT.mdx new file mode 100644 index 0000000000..ca52ba1809 --- /dev/null +++ b/src/content/reference/en/p5/INVERT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: INVERT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 574 +itemtype: property +class: p5 +chainable: false +--- + + +# INVERT diff --git a/src/content/reference/en/p5/ITALIC.mdx b/src/content/reference/en/p5/ITALIC.mdx new file mode 100644 index 0000000000..71b6922549 --- /dev/null +++ b/src/content/reference/en/p5/ITALIC.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ITALIC +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 606 +itemtype: property +class: p5 +chainable: false +--- + + +# ITALIC diff --git a/src/content/reference/en/p5/LABEL.mdx b/src/content/reference/en/p5/LABEL.mdx new file mode 100644 index 0000000000..72c6139575 --- /dev/null +++ b/src/content/reference/en/p5/LABEL.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LABEL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 752 +itemtype: property +class: p5 +chainable: false +--- + + +# LABEL diff --git a/src/content/reference/en/p5/LANDSCAPE.mdx b/src/content/reference/en/p5/LANDSCAPE.mdx new file mode 100644 index 0000000000..43f15d7bee --- /dev/null +++ b/src/content/reference/en/p5/LANDSCAPE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LANDSCAPE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 725 +itemtype: property +class: p5 +chainable: false +--- + + +# LANDSCAPE diff --git a/src/content/reference/en/p5/LEFT.mdx b/src/content/reference/en/p5/LEFT.mdx new file mode 100644 index 0000000000..907f27f8e3 --- /dev/null +++ b/src/content/reference/en/p5/LEFT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LEFT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 230 +itemtype: property +class: p5 +chainable: false +--- + + +# LEFT diff --git a/src/content/reference/en/p5/LEFT_ARROW.mdx b/src/content/reference/en/p5/LEFT_ARROW.mdx new file mode 100644 index 0000000000..6836bf9813 --- /dev/null +++ b/src/content/reference/en/p5/LEFT_ARROW.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LEFT_ARROW +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 431 +itemtype: property +class: p5 +chainable: false +--- + + +# LEFT\_ARROW diff --git a/src/content/reference/en/p5/LIGHTEST.mdx b/src/content/reference/en/p5/LIGHTEST.mdx new file mode 100644 index 0000000000..25fecf1eb7 --- /dev/null +++ b/src/content/reference/en/p5/LIGHTEST.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LIGHTEST +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 493 +itemtype: property +class: p5 +chainable: false +--- + + +# LIGHTEST diff --git a/src/content/reference/en/p5/LINEAR.mdx b/src/content/reference/en/p5/LINEAR.mdx new file mode 100644 index 0000000000..6d2dad3296 --- /dev/null +++ b/src/content/reference/en/p5/LINEAR.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LINEAR +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 638 +itemtype: property +class: p5 +chainable: false +--- + + +# LINEAR diff --git a/src/content/reference/en/p5/LINES.mdx b/src/content/reference/en/p5/LINES.mdx new file mode 100644 index 0000000000..a8429ec5fe --- /dev/null +++ b/src/content/reference/en/p5/LINES.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LINES +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 262 +itemtype: property +class: p5 +chainable: false +--- + + +# LINES diff --git a/src/content/reference/en/p5/LINE_LOOP.mdx b/src/content/reference/en/p5/LINE_LOOP.mdx new file mode 100644 index 0000000000..3206e3739b --- /dev/null +++ b/src/content/reference/en/p5/LINE_LOOP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LINE_LOOP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 274 +itemtype: property +class: p5 +chainable: false +--- + + +# LINE\_LOOP diff --git a/src/content/reference/en/p5/LINE_STRIP.mdx b/src/content/reference/en/p5/LINE_STRIP.mdx new file mode 100644 index 0000000000..f9978e285d --- /dev/null +++ b/src/content/reference/en/p5/LINE_STRIP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: LINE_STRIP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 268 +itemtype: property +class: p5 +chainable: false +--- + + +# LINE\_STRIP diff --git a/src/content/reference/en/p5/MIRROR.mdx b/src/content/reference/en/p5/MIRROR.mdx new file mode 100644 index 0000000000..f4a5bc0007 --- /dev/null +++ b/src/content/reference/en/p5/MIRROR.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: MIRROR +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 706 +itemtype: property +class: p5 +chainable: false +--- + + +# MIRROR diff --git a/src/content/reference/en/p5/MITER.mdx b/src/content/reference/en/p5/MITER.mdx new file mode 100644 index 0000000000..54a7485e9b --- /dev/null +++ b/src/content/reference/en/p5/MITER.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: MITER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 357 +itemtype: property +class: p5 +chainable: false +--- + + +# MITER diff --git a/src/content/reference/en/p5/MOVE.mdx b/src/content/reference/en/p5/MOVE.mdx new file mode 100644 index 0000000000..7f85c1cea7 --- /dev/null +++ b/src/content/reference/en/p5/MOVE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: MOVE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 70 +itemtype: property +class: p5 +chainable: false +--- + + +# MOVE diff --git a/src/content/reference/en/p5/MULTIPLY.mdx b/src/content/reference/en/p5/MULTIPLY.mdx new file mode 100644 index 0000000000..99acf92798 --- /dev/null +++ b/src/content/reference/en/p5/MULTIPLY.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: MULTIPLY +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 514 +itemtype: property +class: p5 +chainable: false +--- + + +# MULTIPLY diff --git a/src/content/reference/en/p5/NEAREST.mdx b/src/content/reference/en/p5/NEAREST.mdx new file mode 100644 index 0000000000..00674c1d02 --- /dev/null +++ b/src/content/reference/en/p5/NEAREST.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: NEAREST +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 691 +itemtype: property +class: p5 +chainable: false +--- + + +# NEAREST diff --git a/src/content/reference/en/p5/OPAQUE.mdx b/src/content/reference/en/p5/OPAQUE.mdx new file mode 100644 index 0000000000..f2cb81c6fe --- /dev/null +++ b/src/content/reference/en/p5/OPAQUE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: OPAQUE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 569 +itemtype: property +class: p5 +chainable: false +--- + + +# OPAQUE diff --git a/src/content/reference/en/p5/OPEN.mdx b/src/content/reference/en/p5/OPEN.mdx new file mode 100644 index 0000000000..227ccd04cb --- /dev/null +++ b/src/content/reference/en/p5/OPEN.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: OPEN +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 320 +itemtype: property +class: p5 +chainable: false +--- + + +# OPEN diff --git a/src/content/reference/en/p5/OPTION.mdx b/src/content/reference/en/p5/OPTION.mdx new file mode 100644 index 0000000000..04be17b717 --- /dev/null +++ b/src/content/reference/en/p5/OPTION.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: OPTION +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 436 +itemtype: property +class: p5 +chainable: false +--- + + +# OPTION diff --git a/src/content/reference/en/p5/OVERLAY.mdx b/src/content/reference/en/p5/OVERLAY.mdx new file mode 100644 index 0000000000..5d604f36ec --- /dev/null +++ b/src/content/reference/en/p5/OVERLAY.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: OVERLAY +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 530 +itemtype: property +class: p5 +chainable: false +--- + + +# OVERLAY diff --git a/src/content/reference/en/p5/P2D.mdx b/src/content/reference/en/p5/P2D.mdx new file mode 100644 index 0000000000..2427821178 --- /dev/null +++ b/src/content/reference/en/p5/P2D.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: P2D +module: Constants +submodule: Constants +file: src/core/constants.js +description: | +

The default, two-dimensional renderer.

+line: 18 +itemtype: property +class: p5 +chainable: false +--- + + +# P2D diff --git a/src/content/reference/en/p5/PI.mdx b/src/content/reference/en/p5/PI.mdx new file mode 100644 index 0000000000..673641a49c --- /dev/null +++ b/src/content/reference/en/p5/PI.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: PI +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

PI is a mathematical constant with the value + + 3.14159265358979323846. It is the ratio of the circumference + + of a circle to its diameter. It is useful in combination with + + the trigonometric functions sin() and cos().

+line: 106 +itemtype: property +class: p5 +example: + - |- + +
+ arc(50, 50, 80, 80, 0, PI); +
+alt: white half-circle with curve toward bottom of canvas. +chainable: false +--- + + +# PI diff --git a/src/content/reference/en/p5/PIE.mdx b/src/content/reference/en/p5/PIE.mdx new file mode 100644 index 0000000000..11a734f708 --- /dev/null +++ b/src/content/reference/en/p5/PIE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: PIE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 330 +itemtype: property +class: p5 +chainable: false +--- + + +# PIE diff --git a/src/content/reference/en/p5/POINTS.mdx b/src/content/reference/en/p5/POINTS.mdx new file mode 100644 index 0000000000..7dee3b18ea --- /dev/null +++ b/src/content/reference/en/p5/POINTS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: POINTS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 256 +itemtype: property +class: p5 +chainable: false +--- + + +# POINTS diff --git a/src/content/reference/en/p5/PORTRAIT.mdx b/src/content/reference/en/p5/PORTRAIT.mdx new file mode 100644 index 0000000000..9148ea0014 --- /dev/null +++ b/src/content/reference/en/p5/PORTRAIT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: PORTRAIT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 730 +itemtype: property +class: p5 +chainable: false +--- + + +# PORTRAIT diff --git a/src/content/reference/en/p5/POSTERIZE.mdx b/src/content/reference/en/p5/POSTERIZE.mdx new file mode 100644 index 0000000000..78e4468229 --- /dev/null +++ b/src/content/reference/en/p5/POSTERIZE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: POSTERIZE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 579 +itemtype: property +class: p5 +chainable: false +--- + + +# POSTERIZE diff --git a/src/content/reference/en/p5/PROJECT.mdx b/src/content/reference/en/p5/PROJECT.mdx new file mode 100644 index 0000000000..3f98af4ee2 --- /dev/null +++ b/src/content/reference/en/p5/PROJECT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: PROJECT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 335 +itemtype: property +class: p5 +chainable: false +--- + + +# PROJECT diff --git a/src/content/reference/en/p5/QUADRATIC.mdx b/src/content/reference/en/p5/QUADRATIC.mdx new file mode 100644 index 0000000000..6ff6f42a45 --- /dev/null +++ b/src/content/reference/en/p5/QUADRATIC.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: QUADRATIC +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 643 +itemtype: property +class: p5 +chainable: false +--- + + +# QUADRATIC diff --git a/src/content/reference/en/p5/QUADS.mdx b/src/content/reference/en/p5/QUADS.mdx new file mode 100644 index 0000000000..74675bcadf --- /dev/null +++ b/src/content/reference/en/p5/QUADS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: QUADS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 298 +itemtype: property +class: p5 +chainable: false +--- + + +# QUADS diff --git a/src/content/reference/en/p5/QUAD_STRIP.mdx b/src/content/reference/en/p5/QUAD_STRIP.mdx new file mode 100644 index 0000000000..e24b570362 --- /dev/null +++ b/src/content/reference/en/p5/QUAD_STRIP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: QUAD_STRIP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 303 +itemtype: property +class: p5 +chainable: false +--- + + +# QUAD\_STRIP diff --git a/src/content/reference/en/p5/QUARTER_PI.mdx b/src/content/reference/en/p5/QUARTER_PI.mdx new file mode 100644 index 0000000000..5cf9eaacf7 --- /dev/null +++ b/src/content/reference/en/p5/QUARTER_PI.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: QUARTER_PI +module: Constants +submodule: Constants +file: src/core/constants.js +description: | +

QUARTER_PI is a mathematical constant with the value 0.7853982. + It is one quarter the ratio of the circumference of a circle to + its diameter. It is useful in combination with the trigonometric + functions sin() and cos().

+line: 124 +itemtype: property +class: p5 +example: + - |- + +
+ arc(50, 50, 80, 80, 0, QUARTER_PI); +
+alt: white eighth-circle rotated about 40 degrees with curve bottom right canvas. +chainable: false +--- + + +# QUARTER\_PI diff --git a/src/content/reference/en/p5/RADIANS.mdx b/src/content/reference/en/p5/RADIANS.mdx new file mode 100644 index 0000000000..6cebd07dd3 --- /dev/null +++ b/src/content/reference/en/p5/RADIANS.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: radians +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: | +

Converts an angle measurement in degrees to its corresponding value in + radians. Degrees and radians are two ways of measuring the same thing. + There are 360 degrees in a circle and 2 × π (about 6.28) + radians in a circle. For example, 90° = π ÷ 2 (about 1.57) + radians. This function doesn't take into account the current + angleMode().

+line: 347 +params: + - name: degrees + description: | +

degree value to convert to radians.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let deg = 45; + let rad = radians(deg); + text(`${deg}˚ = ${round(rad, 3)} rad`, 10, 50); + + describe('The text "45˚ = 0.785 rad".'); + +
+return: + description: converted angle. + type: Number +chainable: false +--- + + +# radians diff --git a/src/content/reference/en/p5/RADIUS.mdx b/src/content/reference/en/p5/RADIUS.mdx new file mode 100644 index 0000000000..8b14f9996c --- /dev/null +++ b/src/content/reference/en/p5/RADIUS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: RADIUS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 220 +itemtype: property +class: p5 +chainable: false +--- + + +# RADIUS diff --git a/src/content/reference/en/p5/REMOVE.mdx b/src/content/reference/en/p5/REMOVE.mdx new file mode 100644 index 0000000000..f0cb01c44b --- /dev/null +++ b/src/content/reference/en/p5/REMOVE.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: remove +module: Structure +submodule: Structure +file: src/core/main.js +description: | +

Removes the entire p5 sketch. This will remove the canvas and any + elements created by p5.js. It will also stop the draw loop and unbind + any properties or methods from the window global scope. It will + leave a variable p5 in case you wanted to create a new p5 sketch. + If you like, you can set p5 = null to erase it. While all functions and + variables and objects created by the p5 library will be removed, any + other global variables created by your code will remain.

+line: 449 +itemtype: method +class: p5 +example: + - |- + +
+ function draw() { + ellipse(50, 50, 10, 10); + } + + function mousePressed() { + remove(); // remove whole sketch on mouse press + } +
+alt: nothing displayed +chainable: false +--- + + +# remove diff --git a/src/content/reference/en/p5/REPEAT.mdx b/src/content/reference/en/p5/REPEAT.mdx new file mode 100644 index 0000000000..0244dc0bbe --- /dev/null +++ b/src/content/reference/en/p5/REPEAT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: REPEAT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 696 +itemtype: property +class: p5 +chainable: false +--- + + +# REPEAT diff --git a/src/content/reference/en/p5/REPLACE.mdx b/src/content/reference/en/p5/REPLACE.mdx new file mode 100644 index 0000000000..fb7ff3017d --- /dev/null +++ b/src/content/reference/en/p5/REPLACE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: REPLACE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 524 +itemtype: property +class: p5 +chainable: false +--- + + +# REPLACE diff --git a/src/content/reference/en/p5/RETURN.mdx b/src/content/reference/en/p5/RETURN.mdx new file mode 100644 index 0000000000..b8b0e74a35 --- /dev/null +++ b/src/content/reference/en/p5/RETURN.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: return +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Specifies the value to be returned by a function. + + For more info checkout + + the MDN entry for return.

+line: 267 +itemtype: property +class: p5 +example: + - |- + +
+ + function calculateSquare(x) { + return x * x; + } + const result = calculateSquare(4); // returns 16 + console.log(result); // prints '16' to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# return diff --git a/src/content/reference/en/p5/RGB.mdx b/src/content/reference/en/p5/RGB.mdx new file mode 100644 index 0000000000..8903cdd1ce --- /dev/null +++ b/src/content/reference/en/p5/RGB.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: RGB +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 364 +itemtype: property +class: p5 +chainable: false +--- + + +# RGB diff --git a/src/content/reference/en/p5/RGBA.mdx b/src/content/reference/en/p5/RGBA.mdx new file mode 100644 index 0000000000..86a257d156 --- /dev/null +++ b/src/content/reference/en/p5/RGBA.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: RGBA +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 799 +itemtype: property +class: p5 +chainable: false +--- + + +# RGBA diff --git a/src/content/reference/en/p5/RIGHT.mdx b/src/content/reference/en/p5/RIGHT.mdx new file mode 100644 index 0000000000..59d137e142 --- /dev/null +++ b/src/content/reference/en/p5/RIGHT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: RIGHT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 225 +itemtype: property +class: p5 +chainable: false +--- + + +# RIGHT diff --git a/src/content/reference/en/p5/RIGHT_ARROW.mdx b/src/content/reference/en/p5/RIGHT_ARROW.mdx new file mode 100644 index 0000000000..20ef708eba --- /dev/null +++ b/src/content/reference/en/p5/RIGHT_ARROW.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: RIGHT_ARROW +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 446 +itemtype: property +class: p5 +chainable: false +--- + + +# RIGHT\_ARROW diff --git a/src/content/reference/en/p5/ROUND.mdx b/src/content/reference/en/p5/ROUND.mdx new file mode 100644 index 0000000000..6d8a5ddf09 --- /dev/null +++ b/src/content/reference/en/p5/ROUND.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: round +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the integer closest to the n parameter. For + example, + + round(133.8) returns the value 134.

+line: 635 +params: + - name: 'n' + description: | +

number to round.

+ type: Number + - name: decimals + description: | +

number of decimal places to round to, default is 0.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let x = round(3.7); + text(x, width / 2, height / 2); + + describe('The number 4 written in middle of canvas.'); + +
+ +
+ + let x = round(12.782383, 2); + text(x, width / 2, height / 2); + + describe('The number 12.78 written in middle of canvas.'); + +
+return: + description: rounded number. + type: Integer +chainable: false +--- + + +# round diff --git a/src/content/reference/en/p5/SCREEN.mdx b/src/content/reference/en/p5/SCREEN.mdx new file mode 100644 index 0000000000..6636517340 --- /dev/null +++ b/src/content/reference/en/p5/SCREEN.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SCREEN +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 519 +itemtype: property +class: p5 +chainable: false +--- + + +# SCREEN diff --git a/src/content/reference/en/p5/SHIFT.mdx b/src/content/reference/en/p5/SHIFT.mdx new file mode 100644 index 0000000000..f7052c70c2 --- /dev/null +++ b/src/content/reference/en/p5/SHIFT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SHIFT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 451 +itemtype: property +class: p5 +chainable: false +--- + + +# SHIFT diff --git a/src/content/reference/en/p5/SOFT_LIGHT.mdx b/src/content/reference/en/p5/SOFT_LIGHT.mdx new file mode 100644 index 0000000000..dbe053f8ac --- /dev/null +++ b/src/content/reference/en/p5/SOFT_LIGHT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SOFT_LIGHT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 540 +itemtype: property +class: p5 +chainable: false +--- + + +# SOFT\_LIGHT diff --git a/src/content/reference/en/p5/SUBTRACT.mdx b/src/content/reference/en/p5/SUBTRACT.mdx new file mode 100644 index 0000000000..23ae344efa --- /dev/null +++ b/src/content/reference/en/p5/SUBTRACT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SUBTRACT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 504 +itemtype: property +class: p5 +chainable: false +--- + + +# SUBTRACT diff --git a/src/content/reference/en/p5/TAB.mdx b/src/content/reference/en/p5/TAB.mdx new file mode 100644 index 0000000000..439aa23c32 --- /dev/null +++ b/src/content/reference/en/p5/TAB.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TAB +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 456 +itemtype: property +class: p5 +chainable: false +--- + + +# TAB diff --git a/src/content/reference/en/p5/TAU.mdx b/src/content/reference/en/p5/TAU.mdx new file mode 100644 index 0000000000..d7eeb66ab4 --- /dev/null +++ b/src/content/reference/en/p5/TAU.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TAU +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

TAU is an alias for TWO_PI, a mathematical constant with the + + value 6.28318530717958647693. It is twice the ratio of the + + circumference of a circle to its diameter. It is useful in + + combination with the trigonometric functions sin() and + cos().

+line: 142 +itemtype: property +class: p5 +example: + - |- + +
+ arc(50, 50, 80, 80, 0, TAU); +
+alt: 80×80 white ellipse shape in center of canvas. +chainable: false +--- + + +# TAU diff --git a/src/content/reference/en/p5/TESS.mdx b/src/content/reference/en/p5/TESS.mdx new file mode 100644 index 0000000000..09b726ecb3 --- /dev/null +++ b/src/content/reference/en/p5/TESS.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TESS +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 309 +itemtype: property +class: p5 +chainable: false +--- + + +# TESS diff --git a/src/content/reference/en/p5/TEXT.mdx b/src/content/reference/en/p5/TEXT.mdx new file mode 100644 index 0000000000..3aa32746b1 --- /dev/null +++ b/src/content/reference/en/p5/TEXT.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: text +module: Typography +submodule: Loading & Displaying +file: src/typography/loading_displaying.js +description: > +

Draws text to the canvas.

+ +

The first parameter, str, is the text to be drawn. The second + and third + + parameters, x and y, set the coordinates of the + text's bottom-left + + corner. See textAlign() for other ways to + + align text.

+ +

The fourth and fifth parameters, maxWidth and + maxHeight, are optional. + + They set the dimensions of the invisible rectangle containing the text. By + + default, they set its maximum width and height. See + + rectMode() for other ways to define the + + rectangular text box. Text will wrap to fit within the text box. Text + + outside of the box won't be drawn.

+ +

Text can be styled a few ways. Call the fill() + + function to set the text's fill color. Call + + stroke() and + + strokeWeight() to set the text's outline. + + Call textSize() and + + textFont() to set the text's size and font, + + respectively.

+ +

Note: WEBGL mode only supports fonts loaded with + + loadFont(). Calling + + stroke() has no effect in WEBGL + mode.

+line: 182 +params: + - name: str + description: | +

text to be displayed.

+ type: String|Object|Array|Number|Boolean + - name: x + description: | +

x-coordinate of the text box.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the text box.

+ type: Number + - name: maxWidth + description: | +

maximum width of the text box. See + rectMode() for + other options.

+ type: Number + optional: true + - name: maxHeight + description: | +

maximum height of the text box. See + rectMode() for + other options.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - "\n
\n\nfunction setup() {\n background(200);\n text('hi', 50, 50);\n\n describe('The text \"hi\" written in black in the middle of a gray square.');\n}\n\n
\n\n
\n\nfunction setup() {\n background('skyblue');\n textSize(100);\n text('\U0001F308', 0, 100);\n\n describe('A rainbow in a blue sky.');\n}\n\n
\n\n
\n\nfunction setup() {\n textSize(32);\n fill(255);\n stroke(0);\n strokeWeight(4);\n text('hi', 50, 50);\n\n describe('The text \"hi\" written in white with a black outline.');\n}\n\n
\n\n
\n\nfunction setup() {\n background('black');\n textSize(22);\n fill('yellow');\n text('rainbows', 6, 20);\n fill('cornflowerblue');\n text('rainbows', 6, 45);\n fill('tomato');\n text('rainbows', 6, 70);\n fill('limegreen');\n text('rainbows', 6, 95);\n\n describe('The text \"rainbows\" written on several lines, each in a different color.');\n}\n\n
\n\n
\n\nfunction setup() {\n background(200);\n let s = 'The quick brown fox jumps over the lazy dog.';\n text(s, 10, 10, 70, 80);\n\n describe('The sample text \"The quick brown fox...\" written in black across several lines.');\n}\n\n
\n\n
\n\nfunction setup() {\n background(200);\n rectMode(CENTER);\n let s = 'The quick brown fox jumps over the lazy dog.';\n text(s, 50, 50, 70, 80);\n\n describe('The sample text \"The quick brown fox...\" written in black across several lines.');\n}\n\n
\n\n
\n\nlet font;\n\nfunction preload() {\n font = loadFont('assets/inconsolata.otf');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n textFont(font);\n textSize(32);\n textAlign(CENTER, CENTER);\n}\n\nfunction draw() {\n background(0);\n rotateY(frameCount / 30);\n text('p5*js', 0, 0);\n\n describe('The text \"p5*js\" written in white and spinning in 3D.');\n}\n\n
" +chainable: true +--- + + +# text diff --git a/src/content/reference/en/p5/TEXTURE.mdx b/src/content/reference/en/p5/TEXTURE.mdx new file mode 100644 index 0000000000..41929912b5 --- /dev/null +++ b/src/content/reference/en/p5/TEXTURE.mdx @@ -0,0 +1,144 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: texture +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the texture that will be used to render subsequent shapes.

+ +

A texture is like a "skin" that wraps around a 3D geometry. Currently + + supported textures are images, video, and offscreen renders.

+ +

To texture a geometry created with beginShape(), + + you will need to specify uv coordinates in vertex().

+ +

Note, texture() can only be used in WEBGL mode.

+ +

You can view more materials in this + + example.

+line: 529 +params: + - name: tex + description: | +

image to use as texture

+ type: >- + p5.Image|p5.MediaElement|p5.Graphics|p5.Texture|p5.Framebuffer|p5.FramebufferTexture +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('spinning cube with a texture from an image'); + } + + function draw() { + background(0); + rotateZ(frameCount * 0.01); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + //pass image as texture + texture(img); + box(width / 2); + } + +
+ - |- + +
+ + let pg; + + function setup() { + createCanvas(100, 100, WEBGL); + pg = createGraphics(200, 200); + pg.textSize(75); + describe('plane with a texture from an image created by createGraphics()'); + } + + function draw() { + background(0); + pg.background(255); + pg.text('hello!', 0, 100); + //pass image as texture + texture(pg); + rotateX(0.5); + noStroke(); + plane(50); + } + +
+ - |- + +
+ + let vid; + function preload() { + vid = createVideo('assets/fingers.mov'); + vid.hide(); + } + function setup() { + createCanvas(100, 100, WEBGL); + describe('rectangle with video as texture'); + } + + function draw() { + background(0); + //pass video frame as texture + texture(vid); + rect(-40, -40, 80, 80); + } + + function mousePressed() { + vid.loop(); + } + +
+ - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('quad with a texture, mapped using normalized coordinates'); + } + + function draw() { + background(0); + texture(img); + textureMode(NORMAL); + beginShape(); + vertex(-40, -40, 0, 0); + vertex(40, -40, 1, 0); + vertex(40, 40, 1, 1); + vertex(-40, 40, 0, 1); + endShape(); + } + +
+alt: 'quad with a texture, mapped using normalized coordinates' +chainable: true +--- + + +# texture diff --git a/src/content/reference/en/p5/THRESHOLD.mdx b/src/content/reference/en/p5/THRESHOLD.mdx new file mode 100644 index 0000000000..2addc389fc --- /dev/null +++ b/src/content/reference/en/p5/THRESHOLD.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: THRESHOLD +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 559 +itemtype: property +class: p5 +chainable: false +--- + + +# THRESHOLD diff --git a/src/content/reference/en/p5/TOP.mdx b/src/content/reference/en/p5/TOP.mdx new file mode 100644 index 0000000000..34969b7102 --- /dev/null +++ b/src/content/reference/en/p5/TOP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TOP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 240 +itemtype: property +class: p5 +chainable: false +--- + + +# TOP diff --git a/src/content/reference/en/p5/TRIANGLES.mdx b/src/content/reference/en/p5/TRIANGLES.mdx new file mode 100644 index 0000000000..d15b2ee403 --- /dev/null +++ b/src/content/reference/en/p5/TRIANGLES.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TRIANGLES +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 280 +itemtype: property +class: p5 +chainable: false +--- + + +# TRIANGLES diff --git a/src/content/reference/en/p5/TRIANGLE_FAN.mdx b/src/content/reference/en/p5/TRIANGLE_FAN.mdx new file mode 100644 index 0000000000..42d1ca1bb6 --- /dev/null +++ b/src/content/reference/en/p5/TRIANGLE_FAN.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TRIANGLE_FAN +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 286 +itemtype: property +class: p5 +chainable: false +--- + + +# TRIANGLE\_FAN diff --git a/src/content/reference/en/p5/TRIANGLE_STRIP.mdx b/src/content/reference/en/p5/TRIANGLE_STRIP.mdx new file mode 100644 index 0000000000..747b532aac --- /dev/null +++ b/src/content/reference/en/p5/TRIANGLE_STRIP.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TRIANGLE_STRIP +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 292 +itemtype: property +class: p5 +chainable: false +--- + + +# TRIANGLE\_STRIP diff --git a/src/content/reference/en/p5/TWO_PI.mdx b/src/content/reference/en/p5/TWO_PI.mdx new file mode 100644 index 0000000000..c7b58bd178 --- /dev/null +++ b/src/content/reference/en/p5/TWO_PI.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: TWO_PI +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

TWO_PI is a mathematical constant with the value + + 6.28318530717958647693. It is twice the ratio of the + + circumference of a circle to its diameter. It is useful in + + combination with the trigonometric functions sin() and + cos().

+line: 160 +itemtype: property +class: p5 +example: + - |- + +
+ arc(50, 50, 80, 80, 0, TWO_PI); +
+alt: 80×80 white ellipse shape in center of canvas. +chainable: false +--- + + +# TWO\_PI diff --git a/src/content/reference/en/p5/UNSIGNED_BYTE.mdx b/src/content/reference/en/p5/UNSIGNED_BYTE.mdx new file mode 100644 index 0000000000..00ac7c2241 --- /dev/null +++ b/src/content/reference/en/p5/UNSIGNED_BYTE.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: UNSIGNED_BYTE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 775 +itemtype: property +class: p5 +chainable: false +--- + + +# UNSIGNED\_BYTE diff --git a/src/content/reference/en/p5/UNSIGNED_INT.mdx b/src/content/reference/en/p5/UNSIGNED_INT.mdx new file mode 100644 index 0000000000..1422ace677 --- /dev/null +++ b/src/content/reference/en/p5/UNSIGNED_INT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: UNSIGNED_INT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 781 +itemtype: property +class: p5 +chainable: false +--- + + +# UNSIGNED\_INT diff --git a/src/content/reference/en/p5/UP_ARROW.mdx b/src/content/reference/en/p5/UP_ARROW.mdx new file mode 100644 index 0000000000..98756c6d21 --- /dev/null +++ b/src/content/reference/en/p5/UP_ARROW.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: UP_ARROW +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 461 +itemtype: property +class: p5 +chainable: false +--- + + +# UP\_ARROW diff --git a/src/content/reference/en/p5/VERSION.mdx b/src/content/reference/en/p5/VERSION.mdx new file mode 100644 index 0000000000..57595c17a3 --- /dev/null +++ b/src/content/reference/en/p5/VERSION.mdx @@ -0,0 +1,16 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: VERSION +module: Constants +submodule: Constants +file: src/core/constants.js +description: | +

Version of this p5.js.

+line: 9 +itemtype: property +class: p5 +chainable: false +--- + + +# VERSION diff --git a/src/content/reference/en/p5/WAIT.mdx b/src/content/reference/en/p5/WAIT.mdx new file mode 100644 index 0000000000..1e36b0327a --- /dev/null +++ b/src/content/reference/en/p5/WAIT.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: WAIT +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 80 +itemtype: property +class: p5 +chainable: false +--- + + +# WAIT diff --git a/src/content/reference/en/p5/WEBGL.mdx b/src/content/reference/en/p5/WEBGL.mdx new file mode 100644 index 0000000000..2de294b052 --- /dev/null +++ b/src/content/reference/en/p5/WEBGL.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: WEBGL +module: Constants +submodule: Constants +file: src/core/constants.js +description: > +

One of the two render modes in p5.js, used for computationally intensive + tasks like 3D rendering and shaders.

+ +

WEBGL differs from the default P2D renderer in the following + ways:

+ + + +

To learn more about WEBGL mode, check out all the + interactive WEBGL tutorials in the "Learn" section of this website, or + read the wiki article "Getting + started with WebGL in p5".

+line: 24 +itemtype: property +class: p5 +chainable: false +--- + + +# WEBGL diff --git a/src/content/reference/en/p5/WEBGL2.mdx b/src/content/reference/en/p5/WEBGL2.mdx new file mode 100644 index 0000000000..572c14bde7 --- /dev/null +++ b/src/content/reference/en/p5/WEBGL2.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: WEBGL2 +module: Constants +submodule: Constants +file: src/core/constants.js +description: | +

One of the two possible values of a WebGL canvas (either WEBGL or WEBGL2), + which can be used to determine what capabilities the rendering environment + has.

+line: 45 +itemtype: property +class: p5 +chainable: false +--- + + +# WEBGL2 diff --git a/src/content/reference/en/p5/WORD.mdx b/src/content/reference/en/p5/WORD.mdx new file mode 100644 index 0000000000..37c60fc3f4 --- /dev/null +++ b/src/content/reference/en/p5/WORD.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: WORD +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 626 +itemtype: property +class: p5 +chainable: false +--- + + +# WORD diff --git a/src/content/reference/en/p5/abs.mdx b/src/content/reference/en/p5/abs.mdx new file mode 100644 index 0000000000..59aabc6685 --- /dev/null +++ b/src/content/reference/en/p5/abs.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: abs +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the absolute value of a number. A number's absolute value is its + + distance from zero on the number line. -5 and 5 are both five units away + + from zero, so calling abs(-5) and abs(5) both return + 5. The absolute + + value of a number is always positive.

+line: 10 +params: + - name: 'n' + description: | +

number to compute.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Invert the y-axis. + scale(1, -1); + translate(0, -height); + + let centerX = width / 2; + let x = frameCount; + let y = abs(x - centerX); + point(x, y); + + describe('A series of black dots that form a "V" shape.'); + } + +
+return: + description: absolute value of given number. + type: Number +chainable: false +--- + + +# abs diff --git a/src/content/reference/en/p5/accelerationX.mdx b/src/content/reference/en/p5/accelerationX.mdx new file mode 100644 index 0000000000..8c2cfb8bc5 --- /dev/null +++ b/src/content/reference/en/p5/accelerationX.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: accelerationX +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The system variable accelerationX always contains the acceleration of the + + device along the x axis. Value is represented as meters per second + squared.

+line: 23 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move a touchscreen device to register + // acceleration changes. + function draw() { + background(220, 50); + fill('magenta'); + ellipse(width / 2, height / 2, accelerationX); + describe('Magnitude of device acceleration is displayed as ellipse size.'); + } + +
+chainable: false +--- + + +# accelerationX diff --git a/src/content/reference/en/p5/accelerationY.mdx b/src/content/reference/en/p5/accelerationY.mdx new file mode 100644 index 0000000000..f4dcd76056 --- /dev/null +++ b/src/content/reference/en/p5/accelerationY.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: accelerationY +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The system variable accelerationY always contains the acceleration of the + + device along the y axis. Value is represented as meters per second + squared.

+line: 45 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move a touchscreen device to register + // acceleration changes. + function draw() { + background(220, 50); + fill('magenta'); + ellipse(width / 2, height / 2, accelerationY); + describe('Magnitude of device acceleration is displayed as ellipse size'); + } + +
+chainable: false +--- + + +# accelerationY diff --git a/src/content/reference/en/p5/accelerationZ.mdx b/src/content/reference/en/p5/accelerationZ.mdx new file mode 100644 index 0000000000..f05941fa25 --- /dev/null +++ b/src/content/reference/en/p5/accelerationZ.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: accelerationZ +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The system variable accelerationZ always contains the acceleration of the + + device along the z axis. Value is represented as meters per second + squared.

+line: 67 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move a touchscreen device to register + // acceleration changes. + function draw() { + background(220, 50); + fill('magenta'); + ellipse(width / 2, height / 2, accelerationZ); + describe('Magnitude of device acceleration is displayed as ellipse size'); + } + +
+chainable: false +--- + + +# accelerationZ diff --git a/src/content/reference/en/p5/acos.mdx b/src/content/reference/en/p5/acos.mdx new file mode 100644 index 0000000000..91e7e79204 --- /dev/null +++ b/src/content/reference/en/p5/acos.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: acos +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

The inverse of cos(), returns the arc cosine of a + + value. This function expects arguments in the range -1 to 1. By default, + + acos() returns values in the range 0 to π (about 3.14). If the + + angleMode() is DEGREES, then values + are + + returned in the range 0 to 180.

+line: 18 +params: + - name: value + description: | +

value whose arc cosine is to be returned.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let a = PI; + let c = cos(a); + let ac = acos(c); + text(`${round(a, 3)}`, 35, 25); + text(`${round(c, 3)}`, 35, 50); + text(`${round(ac, 3)}`, 35, 75); + + describe('The numbers 3.142, -1, and 3.142 written on separate rows.'); + +
+ +
+ + let a = PI + QUARTER_PI; + let c = cos(a); + let ac = acos(c); + text(`${round(a, 3)}`, 35, 25); + text(`${round(c, 3)}`, 35, 50); + text(`${round(ac, 3)}`, 35, 75); + + describe('The numbers 3.927, -0.707, and 2.356 written on separate rows.'); + +
+return: + description: arc cosine of the given value. + type: Number +chainable: false +--- + + +# acos diff --git a/src/content/reference/en/p5/alpha.mdx b/src/content/reference/en/p5/alpha.mdx new file mode 100644 index 0000000000..6b5f5468c5 --- /dev/null +++ b/src/content/reference/en/p5/alpha.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: alpha +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the alpha (transparency) value from a + p5.Color object, array of color components, or + CSS color string.

+line: 16 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - >- + +
+ + + + noStroke(); + + const c = color(0, 126, 255, 102); + + fill(c); + + rect(15, 15, 35, 70); + + // Sets 'alphaValue' to 102. + + const alphaValue = alpha(c); + + fill(alphaValue); + + rect(50, 15, 35, 70); + + describe('Two rectangles. The left one is light blue and the right one is + charcoal gray.'); + + + +
+return: + description: the alpha value. + type: Number +chainable: false +--- + + +# alpha diff --git a/src/content/reference/en/p5/ambientLight.mdx b/src/content/reference/en/p5/ambientLight.mdx new file mode 100644 index 0000000000..e627c9d0b1 --- /dev/null +++ b/src/content/reference/en/p5/ambientLight.mdx @@ -0,0 +1,77 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ambientLight +module: 3D +submodule: Lights +file: src/webgl/light.js +description: | +

Creates an ambient light with the given color.

+

Ambient light does not come from a specific direction. + Objects are evenly lit from all sides. Ambient lights are + almost always used in combination with other types of lights.

+

Note: lights need to be called (whether directly or indirectly) + within draw() to remain persistent in a looping program. + Placing them in setup() will cause them to only have an effect + the first time through the loop.

+line: 10 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + describe('sphere with coral color under black light'); + } + function draw() { + background(100); + ambientLight(0); // black light (no light) + ambientMaterial(255, 127, 80); // coral material + sphere(40); + } + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + describe('sphere with coral color under white light'); + } + function draw() { + background(100); + ambientLight(255); // white light + ambientMaterial(255, 127, 80); // coral material + sphere(40); + } + +
+ - |- + +
+ + function setup() { + createCanvas(100,100,WEBGL); + camera(0,-100,300); + } + function draw() { + background(230); + ambientMaterial(237,34,93); //Pink Material + ambientLight(mouseY); + //As you move the mouse up to down it changes from no ambient light to full ambient light. + rotateY(millis()/2000); + box(100); + } + +
+alt: pink ambient material cube under the ambient light +chainable: true +--- + + +# ambientLight diff --git a/src/content/reference/en/p5/ambientMaterial.mdx b/src/content/reference/en/p5/ambientMaterial.mdx new file mode 100644 index 0000000000..3069008c3e --- /dev/null +++ b/src/content/reference/en/p5/ambientMaterial.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ambientMaterial +module: 3D +submodule: Material +file: src/webgl/material.js +description: | +

Sets the ambient color of the material.

+

The ambientMaterial() color represents the components + of the ambientLight() color that the object reflects.

+

Consider an ambientMaterial() with the color yellow (255, 255, 0). + If the ambientLight() emits the color white (255, 255, 255), then the object + will appear yellow as it will reflect the red and green components + of the light. If the ambientLight() emits the color red (255, 0, 0), then + the object will appear red as it will reflect the red component + of the light. If the ambientLight() emits the color blue (0, 0, 255), + then the object will appear black, as there is no component of + the light that it can reflect.

+

You can view more materials in this + example.

+line: 869 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe('sphere reflecting red, blue, and green light'); + } + function draw() { + background(0); + noStroke(); + ambientLight(255); + ambientMaterial(70, 130, 230); + sphere(40); + } + +
+ - |- + +
+ + // ambientLight is both red and blue (magenta), + // so object only reflects it's red and blue components + function setup() { + createCanvas(100, 100, WEBGL); + describe('box reflecting only red and blue light'); + } + function draw() { + background(70); + ambientLight(255, 0, 255); // magenta light + ambientMaterial(255); // white material + box(30); + } + +
+ - |- + +
+ + // ambientLight is green. Since object does not contain + // green, it does not reflect any light + function setup() { + createCanvas(100, 100, WEBGL); + describe('box reflecting no light'); + } + function draw() { + background(70); + ambientLight(0, 255, 0); // green light + ambientMaterial(255, 0, 255); // magenta material + box(30); + } + +
+alt: box reflecting no light +chainable: true +--- + + +# ambientMaterial diff --git a/src/content/reference/en/p5/angleMode.mdx b/src/content/reference/en/p5/angleMode.mdx new file mode 100644 index 0000000000..f8a222001c --- /dev/null +++ b/src/content/reference/en/p5/angleMode.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: angleMode +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

Changes the way trigonometric functions interpret angle values. By default, + + the mode is RADIANS.

+ +

Calling angleMode() with no arguments returns current angle + mode.

+line: 372 +itemtype: method +class: p5 +example: + - > + +
+ + + + let r = 40; + + push(); + + rotate(PI / 6); + + line(0, 0, r, 0); + + text('0.524 rad', r, 0); + + pop(); + + + angleMode(DEGREES); + + push(); + + rotate(60); + + line(0, 0, r, 0); + + text('60˚', r, 0); + + pop(); + + + describe('Two diagonal lines radiating from the top left corner of a square. + The lines are oriented 30 degrees from the edges of the square and 30 + degrees apart from each other.'); + + + +
+chainable: false +--- + + +# angleMode diff --git a/src/content/reference/en/p5/append.mdx b/src/content/reference/en/p5/append.mdx new file mode 100644 index 0000000000..9d21b81ef2 --- /dev/null +++ b/src/content/reference/en/p5/append.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: append +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Adds a value to the end of an array. Extends the length of + the array by one. Maps to Array.push().

+line: 10 +params: + - name: array + description: | +

Array to append

+ type: Array + - name: value + description: | +

to be added to the Array

+ type: Any +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let myArray = ['Mango', 'Apple', 'Papaya']; + print(myArray); // ['Mango', 'Apple', 'Papaya'] + + append(myArray, 'Peach'); + print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach'] + } +
+return: + description: the array that was appended to + type: Array +chainable: false +--- + + +# append diff --git a/src/content/reference/en/p5/applyMatrix.mdx b/src/content/reference/en/p5/applyMatrix.mdx new file mode 100644 index 0000000000..b933656dc2 --- /dev/null +++ b/src/content/reference/en/p5/applyMatrix.mdx @@ -0,0 +1,171 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: applyMatrix +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Multiplies the current matrix by the one specified through the parameters. + + This is a powerful operation that can perform the equivalent of translate, + + scale, shear and rotate all at once. You can learn more about transformation + + matrices on + + Wikipedia.

+ +

The naming of the arguments here follows the naming of the + + WHATWG specification and corresponds to a + + transformation matrix of the + + form:

+ +
+ +

The transformation matrix used when applyMatrix is called

+ +
+ +

The transformation matrix used when applyMatrix is called with 4x4
+  matrix

+line: 11 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + frameRate(10); + rectMode(CENTER); + } + + function draw() { + let step = frameCount % 20; + background(200); + // Equivalent to translate(x, y); + applyMatrix(1, 0, 0, 1, 40 + step, 50); + rect(0, 0, 50, 50); + } + +
+ +
+ + function setup() { + frameRate(10); + rectMode(CENTER); + } + + function draw() { + let step = frameCount % 20; + background(200); + translate(50, 50); + // Equivalent to scale(x, y); + applyMatrix(1 / step, 0, 0, 1 / step, 0, 0); + rect(0, 0, 50, 50); + } + +
+ +
+ + function setup() { + frameRate(10); + rectMode(CENTER); + } + + function draw() { + let step = frameCount % 20; + let angle = map(step, 0, 20, 0, TWO_PI); + let cos_a = cos(angle); + let sin_a = sin(angle); + background(200); + translate(50, 50); + // Equivalent to rotate(angle); + applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0); + rect(0, 0, 50, 50); + } + +
+ +
+ + function setup() { + frameRate(10); + rectMode(CENTER); + } + + function draw() { + let step = frameCount % 20; + let angle = map(step, 0, 20, -PI / 4, PI / 4); + background(200); + translate(50, 50); + // equivalent to shearX(angle); + let shear_factor = 1 / tan(PI / 2 - angle); + applyMatrix(1, 0, shear_factor, 1, 0, 0); + rect(0, 0, 50, 50); + } + +
+ +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noFill(); + } + + function draw() { + background(200); + rotateY(PI / 6); + stroke(153); + box(35); + let rad = millis() / 1000; + // Set rotation angles + let ct = cos(rad); + let st = sin(rad); + // Matrix for rotation around the Y axis + applyMatrix( + ct, 0.0, st, 0.0, + 0.0, 1.0, 0.0, 0.0, + -st, 0.0, ct, 0.0, + 0.0, 0.0, 0.0, 1.0 + ); + stroke(255); + box(50); + } + +
+ +
+ + function draw() { + background(200); + let testMatrix = [1, 0, 0, 1, 0, 0]; + applyMatrix(testMatrix); + rect(0, 0, 50, 50); + } + +
+alt: |- + A rectangle translating to the right + A rectangle shrinking to the center + A rectangle rotating clockwise about the center + A rectangle shearing + A rectangle in the upper left corner +chainable: true +--- + + +# applyMatrix diff --git a/src/content/reference/en/p5/arc.mdx b/src/content/reference/en/p5/arc.mdx new file mode 100644 index 0000000000..7dc6351982 --- /dev/null +++ b/src/content/reference/en/p5/arc.mdx @@ -0,0 +1,154 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: arc +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws an arc to the canvas. Arcs are drawn along the outer edge of an + ellipse + + (oval) defined by the x, y, w, and + h parameters. Use the start and stop + + parameters to specify the angles (in radians) at which to draw the arc. Arcs + are + + always drawn clockwise from start to stop. The + origin of the arc's ellipse may + + be changed with the ellipseMode() function.

+ +

The optional mode parameter determines the arc's fill style. + The fill modes are + + a semi-circle (OPEN), a closed semi-circle (CHORD), + or a closed pie segment (PIE).

+line: 102 +params: + - name: x + description: | +

x-coordinate of the arc's ellipse.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the arc's ellipse.

+ type: Number + - name: w + description: | +

width of the arc's ellipse by default.

+ type: Number + - name: h + description: | +

height of the arc's ellipse by default.

+ type: Number + - name: start + description: | +

angle to start the arc, specified in radians.

+ type: Number + - name: stop + description: | +

angle to stop the arc, specified in radians.

+ type: Number + - name: mode + description: | +

optional parameter to determine the way of drawing + the arc. either CHORD, PIE, or OPEN.

+ type: Constant + optional: true + - name: detail + description: | +

optional parameter for WebGL mode only. This is to + specify the number of vertices that makes up the + perimeter of the arc. Default value is 25. Won't + draw a stroke for a detail of more than 50.

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - > + +
+ + + + arc(50, 55, 50, 50, 0, HALF_PI); + + noFill(); + + arc(50, 55, 60, 60, HALF_PI, PI); + + arc(50, 55, 70, 70, PI, PI + QUARTER_PI); + + arc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI); + + describe( + 'A shattered outline of an ellipse with a quarter of a white circle at the bottom-right.' + ); + + + +
+ + +
+ + + + arc(50, 50, 80, 80, 0, PI + QUARTER_PI); + + describe('A white ellipse with the top-right third missing. The bottom is + outlined in black.'); + + + +
+ + +
+ + + + arc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN); + + describe( + 'A white ellipse missing a section from the top-right. The bottom is outlined in black.' + ); + + + +
+ + +
+ + + + arc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD); + + describe('A white ellipse with a black outline missing a section from the + top-right.'); + + + +
+ + +
+ + + + arc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE); + + describe('A white ellipse with a black outline. The top-right third is + missing.'); + + + +
+chainable: true +--- + + +# arc diff --git a/src/content/reference/en/p5/arrayCopy.mdx b/src/content/reference/en/p5/arrayCopy.mdx new file mode 100644 index 0000000000..e805ec6d13 --- /dev/null +++ b/src/content/reference/en/p5/arrayCopy.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: arrayCopy +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Copies an array (or part of an array) to another array. The src array is + copied to the dst array, beginning at the position specified by + srcPosition and into the position specified by dstPosition. The number of + elements to copy is determined by length. Note that copying values + overwrites existing values in the destination array. To append values + instead of overwriting them, use concat().

+

The simplified version with only two arguments, arrayCopy(src, dst), + copies an entire array to another of the same size. It is equivalent to + arrayCopy(src, 0, dst, 0, src.length).

+

Using this function is far more efficient for copying array data than + iterating through a for() loop and copying each element individually.

+line: 35 +itemtype: method +class: p5 +example: + - |- + +
+ let src = ['A', 'B', 'C']; + let dst = [1, 2, 3]; + let srcPosition = 1; + let dstPosition = 0; + let length = 2; + + print(src); // ['A', 'B', 'C'] + print(dst); // [ 1 , 2 , 3 ] + + arrayCopy(src, srcPosition, dst, dstPosition, length); + print(dst); // ['B', 'C', 3] +
+chainable: false +--- + + +# arrayCopy diff --git a/src/content/reference/en/p5/asin.mdx b/src/content/reference/en/p5/asin.mdx new file mode 100644 index 0000000000..dcac1aaf19 --- /dev/null +++ b/src/content/reference/en/p5/asin.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: asin +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

The inverse of sin(), returns the arc sine of a + + value. This function expects input values in the range of -1 to 1. By + + default, asin() returns values in the range -π ÷ 2 + + (about -1.57) to π ÷ 2 (about 1.57). If the + + angleMode() is DEGREES then values + are + + returned in the range -90 to 90.

+line: 60 +params: + - name: value + description: | +

value whose arc sine is to be returned.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let a = PI / 3; + let s = sin(a); + let as = asin(s); + text(`${round(a, 3)}`, 35, 25); + text(`${round(s, 3)}`, 35, 50); + text(`${round(as, 3)}`, 35, 75); + + describe('The numbers 1.047, 0.866, and 1.047 written on separate rows.'); + +
+ +
+ + let a = PI + PI / 3; + let s = sin(a); + let as = asin(s); + text(`${round(a, 3)}`, 35, 25); + text(`${round(s, 3)}`, 35, 50); + text(`${round(as, 3)}`, 35, 75); + + describe('The numbers 4.189, -0.866, and -1.047 written on separate rows.'); + +
+return: + description: arc sine of the given value. + type: Number +chainable: false +--- + + +# asin diff --git a/src/content/reference/en/p5/atan.mdx b/src/content/reference/en/p5/atan.mdx new file mode 100644 index 0000000000..1d17037faf --- /dev/null +++ b/src/content/reference/en/p5/atan.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: atan +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

The inverse of tan(), returns the arc tangent of a + + value. This function expects input values in the range of -Infinity to + + Infinity. By default, atan() returns values in the range -π ÷ 2 + + (about -1.57) to π ÷ 2 (about 1.57). If the + + angleMode() is DEGREES then values + are + + returned in the range -90 to 90.

+line: 103 +params: + - name: value + description: | +

value whose arc tangent is to be returned.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let a = PI / 3; + let t = tan(a); + let at = atan(t); + text(`${round(a, 3)}`, 35, 25); + text(`${round(t, 3)}`, 35, 50); + text(`${round(at, 3)}`, 35, 75); + + describe('The numbers 1.047, 1.732, and 1.047 written on separate rows.'); + +
+ +
+ + let a = PI + PI / 3; + let t = tan(a); + let at = atan(t); + text(`${round(a, 3)}`, 35, 25); + text(`${round(t, 3)}`, 35, 50); + text(`${round(at, 3)}`, 35, 75); + + describe('The numbers 4.189, 1.732, and 1.047 written on separate rows.'); + +
+return: + description: arc tangent of the given value. + type: Number +chainable: false +--- + + +# atan diff --git a/src/content/reference/en/p5/atan2.mdx b/src/content/reference/en/p5/atan2.mdx new file mode 100644 index 0000000000..1f114a6a21 --- /dev/null +++ b/src/content/reference/en/p5/atan2.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: atan2 +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

Calculates the angle formed by a specified point, the origin, and the + + positive x-axis. By default, atan2() returns values in the range + + -π (about -3.14) to π (3.14). If the + + angleMode() is DEGREES, then values + are + + returned in the range -180 to 180. The atan2() function is most + often + + used for orienting geometry to the mouse's position.

+ +

Note: The y-coordinate of the point is the first parameter and the + + x-coordinate is the second parameter.

+line: 146 +params: + - name: 'y' + description: | +

y-coordinate of the point.

+ type: Number + - name: x + description: | +

x-coordinate of the point.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + translate(width / 2, height / 2); + let x = mouseX - width / 2; + let y = mouseY - height / 2; + let a = atan2(y, x); + rotate(a); + rect(-30, -5, 60, 10); + + describe('A rectangle at the center of the canvas rotates with mouse movements.'); + } + +
+return: + description: arc tangent of the given point. + type: Number +chainable: false +--- + + +# atan2 diff --git a/src/content/reference/en/p5/background.mdx b/src/content/reference/en/p5/background.mdx new file mode 100644 index 0000000000..f20a57bc70 --- /dev/null +++ b/src/content/reference/en/p5/background.mdx @@ -0,0 +1,158 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: background +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Sets the color used for the background of the canvas. By default, the + + background is transparent. This function is typically used within + + draw() to clear the display window at the beginning + + of each frame. It can also be used inside setup() to + + set the background on the first frame of animation.

+ +

The version of background() with one parameter interprets the + value one of four + + ways. If the parameter is a number, it's interpreted as a grayscale value. + + If the parameter is a string, it's interpreted as a CSS color string. RGB, + RGBA, + + HSL, HSLA, hex, and named color strings are supported. If the parameter is a + + p5.Color object, it will be used as the background + color. + + If the parameter is a p5.Image object, it will be + used as + + the background image.

+ +

The version of background() with two parameters interprets the + first one as a + + grayscale value. The second parameter sets the alpha (transparency) value.

+ +

The version of background() with three parameters interprets + them as RGB, HSB, + + or HSL colors, depending on the current colorMode(). + + By default, colors are specified in RGB values. Calling background(255, 204, + 0) + + sets the background a bright yellow color.

+line: 215 +itemtype: method +class: p5 +example: + - | + +
+ + // A grayscale integer value. + background(51); + describe('A canvas with a dark charcoal gray background.'); + +
+ +
+ + // A grayscale integer value and an alpha value. + background(51, 0.4); + describe('A canvas with a transparent gray background.'); + +
+ +
+ + // R, G & B integer values. + background(255, 204, 0); + describe('A canvas with a yellow background.'); + +
+ +
+ + // H, S & B integer values. + colorMode(HSB); + background(255, 204, 100); + describe('A canvas with a royal blue background.'); + +
+ +
+ + // A CSS named color. + background('red'); + describe('A canvas with a red background.'); + +
+ +
+ + // Three-digit hex RGB notation. + background('#fae'); + describe('A canvas with a pink background.'); + +
+ +
+ + // Six-digit hex RGB notation. + background('#222222'); + describe('A canvas with a black background.'); + +
+ +
+ + // Integer RGB notation. + background('rgb(0,255,0)'); + describe('A canvas with a bright green background.'); + +
+ +
+ + // Integer RGBA notation. + background('rgba(0,255,0, 0.25)'); + describe('A canvas with a transparent green background.'); + +
+ +
+ + // Percentage RGB notation. + background('rgb(100%,0%,10%)'); + describe('A canvas with a red background.'); + +
+ +
+ + // Percentage RGBA notation. + background('rgba(100%,0%,100%,0.5)'); + describe('A canvas with a transparent purple background.'); + +
+ +
+ + // A p5.Color object. + let c = color(0, 0, 255); + background(c); + describe('A canvas with a blue background.'); + +
+chainable: true +--- + + +# background diff --git a/src/content/reference/en/p5/beginClip.mdx b/src/content/reference/en/p5/beginClip.mdx new file mode 100644 index 0000000000..9be25b713b --- /dev/null +++ b/src/content/reference/en/p5/beginClip.mdx @@ -0,0 +1,118 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: beginClip +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Start defining a shape that will mask subsequent things drawn to the + canvas. + + Only opaque regions of the mask shape will allow content to be drawn. + + Any shapes drawn between this and endClip() will + + contribute to the mask shape.

+ +

The mask will apply to anything drawn after this call. To draw without a + mask, contain + + the code to apply the mask and to draw the masked content between + + push() and pop().

+ +

Alternatively, rather than drawing the mask between this and + + endClip(), draw the mask in a callback function + + passed to clip().

+ +

Options can include:

+ + +line: 13 +params: + - name: options + description: | +

An object containing clip settings.

+ type: Object + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + noStroke(); + + // Mask in some shapes + push(); + beginClip(); + triangle(15, 37, 30, 13, 43, 37); + circle(45, 45, 7); + endClip(); + + fill('red'); + rect(5, 5, 45, 45); + pop(); + + translate(50, 50); + + // Mask out the same shapes + push(); + beginClip({ invert: true }); + triangle(15, 37, 30, 13, 43, 37); + circle(45, 45, 7); + endClip(); + + fill('red'); + rect(5, 5, 45, 45); + pop(); + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(255); + noStroke(); + + beginClip(); + push(); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + scale(0.5); + torus(30, 15); + pop(); + endClip(); + + beginShape(QUAD_STRIP); + fill(0, 255, 255); + vertex(-width/2, -height/2); + vertex(width/2, -height/2); + fill(100, 0, 100); + vertex(-width/2, height/2); + vertex(width/2, height/2); + endShape(); + } + +
+alt: |- + A silhouette of a rotating torus colored with a gradient from + cyan to purple +chainable: false +--- + + +# beginClip diff --git a/src/content/reference/en/p5/beginContour.mdx b/src/content/reference/en/p5/beginContour.mdx new file mode 100644 index 0000000000..160cb5e0dd --- /dev/null +++ b/src/content/reference/en/p5/beginContour.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: beginContour +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Use the beginContour() and + + endContour() functions to create negative shapes + + within shapes such as the center of the letter 'O'. beginContour() + + begins recording vertices for the shape and endContour() stops recording. + + The vertices that define a negative shape must "wind" in the opposite + direction + + from the exterior shape. First draw vertices for the exterior clockwise order, + then for internal shapes, draw vertices + + shape in counter-clockwise.

+ +

These functions can only be used within a beginShape()/endShape() + pair and + + transformations such as translate(), rotate(), and scale() do not + work + + within a beginContour()/endContour() pair. It is also not possible to use + + other shapes, such as ellipse() or rect() within.

+line: 20 +itemtype: method +class: p5 +example: + - |- + +
+ + translate(50, 50); + stroke(255, 0, 0); + beginShape(); + // Exterior part of shape, clockwise winding + vertex(-40, -40); + vertex(40, -40); + vertex(40, 40); + vertex(-40, 40); + // Interior part of shape, counter-clockwise winding + beginContour(); + vertex(-20, -20); + vertex(-20, 20); + vertex(20, 20); + vertex(20, -20); + endContour(); + endShape(CLOSE); + +
+alt: white rect and smaller grey rect with red outlines in center of canvas. +chainable: true +--- + + +# beginContour diff --git a/src/content/reference/en/p5/beginGeometry.mdx b/src/content/reference/en/p5/beginGeometry.mdx new file mode 100644 index 0000000000..c99ad51116 --- /dev/null +++ b/src/content/reference/en/p5/beginGeometry.mdx @@ -0,0 +1,91 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: beginGeometry +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Starts creating a new p5.Geometry. Subsequent shapes drawn will be added + + to the geometry and then returned when + + endGeometry() is called. One can also use + + buildGeometry() to pass a function that + + draws shapes.

+ +

If you need to draw complex shapes every frame which don't change over + time, + + combining them upfront with beginGeometry() and + endGeometry() and then + + drawing that will run faster than repeatedly drawing the individual + pieces.

+line: 13 +itemtype: method +class: p5 +example: + - |- + +
+ + let shapes; + + function setup() { + createCanvas(100, 100, WEBGL); + makeShapes(); + } + + function makeShapes() { + beginGeometry(); + scale(0.18); + + push(); + translate(100, -50); + scale(0.5); + rotateX(PI/4); + cone(); + pop(); + cone(); + + beginShape(); + vertex(-20, -50); + quadraticVertex( + -40, -70, + 0, -60 + ); + endShape(); + + beginShape(TRIANGLE_STRIP); + for (let y = 20; y <= 60; y += 10) { + for (let x of [20, 60]) { + vertex(x, y); + } + } + endShape(); + + beginShape(); + vertex(-100, -120); + vertex(-120, -110); + vertex(-105, -100); + endShape(); + + shapes = endGeometry(); + } + + function draw() { + background(255); + lights(); + orbitControl(); + model(shapes); + } + +
+alt: 'A series of different flat, curved, and 3D shapes floating in space.' +chainable: false +--- + + +# beginGeometry diff --git a/src/content/reference/en/p5/beginShape.mdx b/src/content/reference/en/p5/beginShape.mdx new file mode 100644 index 0000000000..ff00cea0f2 --- /dev/null +++ b/src/content/reference/en/p5/beginShape.mdx @@ -0,0 +1,244 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: beginShape +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Using the beginShape() and endShape() functions allow creating more + + complex forms. beginShape() begins recording + vertices for a shape and + + endShape() stops recording. The value of the kind + parameter tells it which + + types of shapes to create from the provided vertices. With no mode + + specified, the shape can be any irregular polygon.

+ +

The parameters available for beginShape() + are:

+ +

POINTS + + Draw a series of points

+ +

LINES + + Draw a series of unconnected line segments (individual lines)

+ +

TRIANGLES + + Draw a series of separate triangles

+ +

TRIANGLE_FAN + + Draw a series of connected triangles sharing the first vertex in a fan-like + fashion

+ +

TRIANGLE_STRIP + + Draw a series of connected triangles in strip fashion

+ +

QUADS + + Draw a series of separate quads

+ +

QUAD_STRIP + + Draw quad strip using adjacent edges to form the next quad

+ +

TESS (WEBGL only) + + Handle irregular polygon for filling curve by explicit tessellation

+ +

After calling the beginShape() function, a + series of vertex() commands must follow. To stop + + drawing the shape, call endShape(). Each shape + will be outlined with the + + current stroke color and filled with the fill color.

+ +

Transformations such as translate(), rotate(), and scale() do not + work + + within beginShape(). It is also not possible to + use other shapes, such as + + ellipse() or rect() within + beginShape().

+line: 71 +params: + - name: kind + description: | +

either POINTS, LINES, TRIANGLES, TRIANGLE_FAN + TRIANGLE_STRIP, QUADS, QUAD_STRIP or TESS

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + beginShape(); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(CLOSE); + +
+ +
+ + beginShape(POINTS); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(); + +
+ +
+ + beginShape(LINES); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(); + +
+ +
+ + noFill(); + beginShape(); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(); + +
+ +
+ + noFill(); + beginShape(); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(CLOSE); + +
+ +
+ + beginShape(TRIANGLES); + vertex(30, 75); + vertex(40, 20); + vertex(50, 75); + vertex(60, 20); + vertex(70, 75); + vertex(80, 20); + endShape(); + +
+ +
+ + beginShape(TRIANGLE_STRIP); + vertex(30, 75); + vertex(40, 20); + vertex(50, 75); + vertex(60, 20); + vertex(70, 75); + vertex(80, 20); + vertex(90, 75); + endShape(); + +
+ +
+ + beginShape(TRIANGLE_FAN); + vertex(57.5, 50); + vertex(57.5, 15); + vertex(92, 50); + vertex(57.5, 85); + vertex(22, 50); + vertex(57.5, 15); + endShape(); + +
+ +
+ + beginShape(QUADS); + vertex(30, 20); + vertex(30, 75); + vertex(50, 75); + vertex(50, 20); + vertex(65, 20); + vertex(65, 75); + vertex(85, 75); + vertex(85, 20); + endShape(); + +
+ +
+ + beginShape(QUAD_STRIP); + vertex(30, 20); + vertex(30, 75); + vertex(50, 20); + vertex(50, 75); + vertex(65, 20); + vertex(65, 75); + vertex(85, 20); + vertex(85, 75); + endShape(); + +
+ +
+ + beginShape(TESS); + vertex(20, 20); + vertex(80, 20); + vertex(80, 40); + vertex(40, 40); + vertex(40, 60); + vertex(80, 60); + vertex(80, 80); + vertex(20, 80); + endShape(CLOSE); + +
+alt: |- + white square-shape with black outline in middle-right of canvas. + 4 black points in a square shape in middle-right of canvas. + 2 horizontal black lines. In the top-right and bottom-right of canvas. + 3 line shape with horizontal on top, vertical in middle and horizontal bottom. + square line shape in middle-right of canvas. + 2 white triangle shapes mid-right canvas. left one pointing up and right down. + 5 horizontal interlocking and alternating white triangles in mid-right canvas. + 4 interlocking white triangles in 45 degree rotated square-shape. + 2 white rectangle shapes in mid-right canvas. Both 20×55. + 3 side-by-side white rectangles center rect is smaller in mid-right canvas. + Thick white l-shape with black outline mid-top-left of canvas. +chainable: true +--- + + +# beginShape diff --git a/src/content/reference/en/p5/bezier.mdx b/src/content/reference/en/p5/bezier.mdx new file mode 100644 index 0000000000..4520251be9 --- /dev/null +++ b/src/content/reference/en/p5/bezier.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: BEZIER +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 648 +itemtype: property +class: p5 +chainable: false +--- + + +# BEZIER diff --git a/src/content/reference/en/p5/bezierDetail.mdx b/src/content/reference/en/p5/bezierDetail.mdx new file mode 100644 index 0000000000..a749a9a977 --- /dev/null +++ b/src/content/reference/en/p5/bezierDetail.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bezierDetail +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: > +

Sets the resolution at which Bezier's curve is displayed. The default value + is 20.

+ +

Note, This function is only useful when using the WEBGL renderer + + as the default canvas renderer does not use this information.

+line: 92 +params: + - name: detail + description: | +

resolution of the curves

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noFill(); + bezierDetail(5); + } + + function draw() { + background(200); + bezier( + -40, -40, 0, + 90, -40, 0, + -90, 40, 0, + 40, 40, 0 + ); + } + +
+alt: stretched black s-shape with a low level of bezier detail +chainable: true +--- + + +# bezierDetail diff --git a/src/content/reference/en/p5/bezierPoint.mdx b/src/content/reference/en/p5/bezierPoint.mdx new file mode 100644 index 0000000000..8e13221729 --- /dev/null +++ b/src/content/reference/en/p5/bezierPoint.mdx @@ -0,0 +1,79 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bezierPoint +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: > +

Given the x or y co-ordinate values of control and anchor points of a + bezier + + curve, it evaluates the x or y coordinate of the bezier at position t. The + + parameters a and d are the x or y coordinates of first and last points on the + + curve while b and c are of the control points.The final parameter t is the + + position of the resultant point which is given between 0 and 1. + + This can be done once with the x coordinates and a second time + + with the y coordinates to get the location of a bezier curve at t.

+line: 131 +params: + - name: a + description: | +

coordinate of first point on the curve

+ type: Number + - name: b + description: | +

coordinate of first control point

+ type: Number + - name: c + description: | +

coordinate of second control point

+ type: Number + - name: d + description: | +

coordinate of second point on the curve

+ type: Number + - name: t + description: | +

value between 0 and 1

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + let x1 = 85, + x2 = 10, + x3 = 90, + x4 = 15; + let y1 = 20, + y2 = 10, + y3 = 90, + y4 = 80; + bezier(x1, y1, x2, y2, x3, y3, x4, y4); + fill(255); + let steps = 10; + for (let i = 0; i <= steps; i++) { + let t = i / steps; + let x = bezierPoint(x1, x2, x3, x4, t); + let y = bezierPoint(y1, y2, y3, y4, t); + circle(x, y, 5); + } + +
+alt: 10 points plotted on a given bezier at equal distances. +return: + description: the value of the Bezier at position t + type: Number +chainable: false +--- + + +# bezierPoint diff --git a/src/content/reference/en/p5/bezierTangent.mdx b/src/content/reference/en/p5/bezierTangent.mdx new file mode 100644 index 0000000000..f64af43253 --- /dev/null +++ b/src/content/reference/en/p5/bezierTangent.mdx @@ -0,0 +1,97 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bezierTangent +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: | +

Evaluates the tangent to the Bezier at position t for points a, b, c, d. + The parameters a and d are the first and last points + on the curve, and b and c are the control points. + The final parameter t varies between 0 and 1.

+line: 186 +params: + - name: a + description: | +

coordinate of first point on the curve

+ type: Number + - name: b + description: | +

coordinate of first control point

+ type: Number + - name: c + description: | +

coordinate of second control point

+ type: Number + - name: d + description: | +

coordinate of second point on the curve

+ type: Number + - name: t + description: | +

value between 0 and 1

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + bezier(85, 20, 10, 10, 90, 90, 15, 80); + let steps = 6; + fill(255); + for (let i = 0; i <= steps; i++) { + let t = i / steps; + // Get the location of the point + let x = bezierPoint(85, 10, 90, 15, t); + let y = bezierPoint(20, 10, 90, 80, t); + // Get the tangent points + let tx = bezierTangent(85, 10, 90, 15, t); + let ty = bezierTangent(20, 10, 90, 80, t); + // Calculate an angle from the tangent points + let a = atan2(ty, tx); + a += PI; + stroke(255, 102, 0); + line(x, y, cos(a) * 30 + x, sin(a) * 30 + y); + // The following line of code makes a line + // inverse of the above line + //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y); + stroke(0); + ellipse(x, y, 5, 5); + } + +
+ +
+ + noFill(); + bezier(85, 20, 10, 10, 90, 90, 15, 80); + stroke(255, 102, 0); + let steps = 16; + for (let i = 0; i <= steps; i++) { + let t = i / steps; + let x = bezierPoint(85, 10, 90, 15, t); + let y = bezierPoint(20, 10, 90, 80, t); + let tx = bezierTangent(85, 10, 90, 15, t); + let ty = bezierTangent(20, 10, 90, 80, t); + let a = atan2(ty, tx); + a -= HALF_PI; + line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); + } + +
+alt: >- + s-shaped line with 6 short orange lines showing the tangents at those points. + + s-shaped line with 6 short orange lines showing lines coming out the underside + of the bezier. +return: + description: the tangent at position t + type: Number +chainable: false +--- + + +# bezierTangent diff --git a/src/content/reference/en/p5/bezierVertex.mdx b/src/content/reference/en/p5/bezierVertex.mdx new file mode 100644 index 0000000000..a0c2ba99d3 --- /dev/null +++ b/src/content/reference/en/p5/bezierVertex.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: bezierVertex +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Specifies vertex coordinates for Bezier curves. Each call to + + bezierVertex() defines the position of two control points and + + one anchor point of a Bezier curve, adding a new segment to a + + line or shape. For WebGL mode bezierVertex() can be used in 2D + + as well as 3D mode. 2D mode expects 6 parameters, while 3D mode + + expects 9 parameters (including z coordinates).

+ +

The first time bezierVertex() is used within a beginShape() + + call, it must be prefaced with a call to vertex() to + set the first anchor + + point. This function must be used between beginShape() and endShape() + + and only when there is no MODE or POINTS parameter specified to + + beginShape().

+line: 297 +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + beginShape(); + vertex(30, 20); + bezierVertex(80, 0, 80, 75, 30, 75); + endShape(); + +
+ +
+ + beginShape(); + vertex(30, 20); + bezierVertex(80, 0, 80, 75, 30, 75); + bezierVertex(50, 80, 60, 25, 30, 20); + endShape(); + +
+ +
+ + function setup() { + createCanvas(100, 100, WEBGL); + setAttributes('antialias', true); + } + function draw() { + orbitControl(); + background(50); + strokeWeight(4); + stroke(255); + point(-25, 30); + point(25, 30); + point(25, -30); + point(-25, -30); + + strokeWeight(1); + noFill(); + + beginShape(); + vertex(-25, 30); + bezierVertex(25, 30, 25, -30, -25, -30); + endShape(); + + beginShape(); + vertex(-25, 30, 20); + bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20); + endShape(); + } + +
+alt: >- + crescent-shaped line in middle of canvas. Points facing left. + + white crescent shape in middle of canvas. Points facing left. + + crescent shape in middle of canvas with another crescent shape on positive + z-axis. +chainable: true +--- + + +# bezierVertex diff --git a/src/content/reference/en/p5/blendMode.mdx b/src/content/reference/en/p5/blendMode.mdx new file mode 100644 index 0000000000..12255245b6 --- /dev/null +++ b/src/content/reference/en/p5/blendMode.mdx @@ -0,0 +1,128 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: blendMode +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

Blends the pixels in the display window according to the defined mode. + + There is a choice of the following modes to blend the source pixels (A) + + with the ones of pixels already in the display window (B):

+ + + + +

(2D) indicates that this blend mode only works in the 2D + renderer.
+ + (3D) indicates that this blend mode only works in the WEBGL + renderer.

+line: 451 +params: + - name: mode + description: | +

blend mode to set for canvas. + either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY, + EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, + SOFT_LIGHT, DODGE, BURN, ADD, REMOVE or SUBTRACT

+ type: Constant +itemtype: method +class: p5 +example: + - |- + +
+ + blendMode(LIGHTEST); + strokeWeight(30); + stroke(80, 150, 255); + line(25, 25, 75, 75); + stroke(255, 50, 50); + line(75, 25, 25, 75); + +
+ +
+ + blendMode(MULTIPLY); + strokeWeight(30); + stroke(80, 150, 255); + line(25, 25, 75, 75); + stroke(255, 50, 50); + line(75, 25, 25, 75); + +
+alt: |- + translucent image thick red & blue diagonal rounded lines intersecting center + Thick red & blue diagonal rounded lines intersecting center. dark at overlap +chainable: false +--- + + +# blendMode diff --git a/src/content/reference/en/p5/blue.mdx b/src/content/reference/en/p5/blue.mdx new file mode 100644 index 0000000000..7e39524c6c --- /dev/null +++ b/src/content/reference/en/p5/blue.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: blue +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the blue value from a p5.Color object, + array of color components, or CSS color string.

+line: 46 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - > + +
+ + + + const c = color(175, 100, 220); + + fill(c); + + rect(15, 20, 35, 60); + + // Sets 'blueValue' to 220. + + const blueValue = blue(c); + + fill(0, 0, blueValue); + + rect(50, 20, 35, 60); + + describe('Two rectangles. The left one is light purple and the right one is + royal blue.'); + + + +
+return: + description: the blue value. + type: Number +chainable: false +--- + + +# blue diff --git a/src/content/reference/en/p5/boolean.mdx b/src/content/reference/en/p5/boolean.mdx new file mode 100644 index 0000000000..1377296c24 --- /dev/null +++ b/src/content/reference/en/p5/boolean.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: boolean +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a number or string to its boolean representation. + For a number, any non-zero value (positive or negative) evaluates to true, + while zero evaluates to false. For a string, the value "true" evaluates to + true, while any other value evaluates to false. When an array of number or + string values is passed in, then a array of booleans of the same length is + returned.

+line: 112 +params: + - name: 'n' + description: | +

value to parse

+ type: String|Boolean|Number|Array +itemtype: method +class: p5 +example: + - |- + +
+ print(boolean(0)); // false + print(boolean(1)); // true + print(boolean('true')); // true + print(boolean('abcd')); // false + print(boolean([0, 12, 'true'])); // [false, true, true] +
+return: + description: boolean representation of value + type: Boolean +chainable: false +--- + + +# boolean diff --git a/src/content/reference/en/p5/box.mdx b/src/content/reference/en/p5/box.mdx new file mode 100644 index 0000000000..5257417c7a --- /dev/null +++ b/src/content/reference/en/p5/box.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: box +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: | +

Draw a box with given width, height and depth

+line: 268 +params: + - name: width + description: | +

width of the box

+ type: Number + optional: true + - name: height + description: | +

height of the box

+ type: Number + optional: true + - name: depth + description: | +

depth of the box

+ type: Number + optional: true + - name: detailX + description: | +

Optional number of triangle + subdivisions in x-dimension

+ type: Integer + optional: true + - name: detailY + description: | +

Optional number of triangle + subdivisions in y-dimension

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a spinning box + // with width, height and depth of 50 + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + describe('a white box rotating in 3D space'); + } + + function draw() { + background(200); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + box(50); + } + +
+chainable: true +--- + + +# box diff --git a/src/content/reference/en/p5/brightness.mdx b/src/content/reference/en/p5/brightness.mdx new file mode 100644 index 0000000000..aad00ef1c5 --- /dev/null +++ b/src/content/reference/en/p5/brightness.mdx @@ -0,0 +1,88 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: brightness +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the HSB brightness value from a + p5.Color object, array of color components, or + CSS color string.

+line: 74 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - >- + +
+ + + + noStroke(); + + colorMode(HSB, 255); + + const c = color(0, 126, 255); + + fill(c); + + rect(15, 20, 35, 60); + + // Sets 'brightValue' to 255. + + const brightValue = brightness(c); + + fill(brightValue); + + rect(50, 20, 35, 60); + + describe('Two rectangles. The left one is salmon pink and the right one is + white.'); + + + +
+ + +
+ + + + noStroke(); + + colorMode(HSB, 255); + + const c = color('hsb(60, 100%, 50%)'); + + fill(c); + + rect(15, 20, 35, 60); + + // Sets 'brightValue' to 127.5 (50% of 255) + + const brightValue = brightness(c); + + fill(brightValue); + + rect(50, 20, 35, 60); + + describe('Two rectangles. The left one is olive and the right one is + gray.'); + + + +
+return: + description: the brightness value. + type: Number +chainable: false +--- + + +# brightness diff --git a/src/content/reference/en/p5/buildGeometry.mdx b/src/content/reference/en/p5/buildGeometry.mdx new file mode 100644 index 0000000000..eb91bc2c8a --- /dev/null +++ b/src/content/reference/en/p5/buildGeometry.mdx @@ -0,0 +1,86 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: buildGeometry +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Creates a new p5.Geometry that contains all + + the shapes drawn in a provided callback function. The returned combined shape + + can then be drawn all at once using model().

+ +

If you need to draw complex shapes every frame which don't change over + time, + + combining them with buildGeometry() once and then drawing that + will run + + faster than repeatedly drawing the individual pieces.

+ +

One can also draw shapes directly between + + beginGeometry() and + + endGeometry() instead of using a callback + + function.

+line: 102 +params: + - name: callback + description: | +

A function that draws shapes.

+ type: Function +itemtype: method +class: p5 +example: + - |- + +
+ + let particles; + let button; + + function setup() { + createCanvas(100, 100, WEBGL); + button = createButton('New'); + button.mousePressed(makeParticles); + makeParticles(); + } + + function makeParticles() { + if (particles) freeGeometry(particles); + + particles = buildGeometry(() => { + for (let i = 0; i < 60; i++) { + push(); + translate( + randomGaussian(0, 20), + randomGaussian(0, 20), + randomGaussian(0, 20) + ); + sphere(5); + pop(); + } + }); + } + + function draw() { + background(255); + noStroke(); + lights(); + orbitControl(); + model(particles); + } + +
+alt: A cluster of spheres. +return: + description: The model that was built from the callback function. + type: p5.Geometry +chainable: false +--- + + +# buildGeometry diff --git a/src/content/reference/en/p5/byte.mdx b/src/content/reference/en/p5/byte.mdx new file mode 100644 index 0000000000..46573cab1c --- /dev/null +++ b/src/content/reference/en/p5/byte.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: byte +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: > +

Converts a number, string representation of a number, or boolean to its + byte + + representation. A byte can be only a whole number between -128 and 127, so + + when a value outside of this range is converted, it wraps around to the + + corresponding byte representation. When an array of number, string or boolean + + values is passed in, then an array of bytes the same length is returned.

+line: 144 +itemtype: method +class: p5 +example: + - |- + +
+ print(byte(127)); // 127 + print(byte(128)); // -128 + print(byte(23.4)); // 23 + print(byte('23.4')); // 23 + print(byte('hello')); // NaN + print(byte(true)); // 1 + print(byte([0, 255, '100'])); // [0, -1, 100] +
+return: + description: byte representation of value + type: Number +chainable: false +--- + + +# byte diff --git a/src/content/reference/en/p5/camera.mdx b/src/content/reference/en/p5/camera.mdx new file mode 100644 index 0000000000..22b79b050e --- /dev/null +++ b/src/content/reference/en/p5/camera.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: camera +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

Sets the position of the current camera in a 3D sketch. + + Parameters for this function define the camera's position, + + the center of the sketch (where the camera is pointing), + + and an up direction (the orientation of the camera).

+ +

This function simulates the movements of the camera, allowing objects to be + + viewed from various angles. Remember, it does not move the objects themselves + + but the camera instead. For example when the centerX value is positive, + + and the camera is rotating to the right side of the sketch, + + the object will seem like it's moving to the left.

+ +

See this example + + to view the position of your camera.

+ +

If no parameters are given, the following default is used: + + camera(0, 0, 800, 0, 0, 0, 0, 1, 0)

+isConstructor: true +line: 13 +params: + - name: x + description: | +

camera position value on x axis

+ type: Number + optional: true + - name: 'y' + description: | +

camera position value on y axis

+ type: Number + optional: true + - name: z + description: | +

camera position value on z axis

+ type: Number + optional: true + - name: centerX + description: | +

x coordinate representing center of the sketch

+ type: Number + optional: true + - name: centerY + description: | +

y coordinate representing center of the sketch

+ type: Number + optional: true + - name: centerZ + description: | +

z coordinate representing center of the sketch

+ type: Number + optional: true + - name: upX + description: | +

x component of direction 'up' from camera

+ type: Number + optional: true + - name: upY + description: | +

y component of direction 'up' from camera

+ type: Number + optional: true + - name: upZ + description: | +

z component of direction 'up' from camera

+ type: Number + optional: true +itemtype: method +alt: |- + White square repeatedly grows to fill canvas and then shrinks. + An interactive example of a red cube with 3 sliders for moving it across x, y, + z axis and 3 sliders for shifting its center. +--- + + +# camera diff --git a/src/content/reference/en/p5/ceil.mdx b/src/content/reference/en/p5/ceil.mdx new file mode 100644 index 0000000000..d2e29ca25e --- /dev/null +++ b/src/content/reference/en/p5/ceil.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ceil +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the closest integer value that is greater than or equal to the + + parameter's value. For example, calling ceil(9.03) returns the + value + + 10.

+line: 39 +params: + - name: 'n' + description: | +

number to round up.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + // Set the range for RGB values from 0 to 1. + + colorMode(RGB, 1); + + noStroke(); + + + let r = 0.3; + + fill(r, 0, 0); + + rect(0, 0, width / 2, height); + + + // Round r up to 1. + + r = ceil(r); + + fill(r, 0, 0); + + rect(width / 2, 0, width / 2, height); + + + describe('Two rectangles. The one on the left is dark red and the one on the + right is bright red.'); + + + +
+return: + description: rounded up number. + type: Integer +chainable: false +--- + + +# ceil diff --git a/src/content/reference/en/p5/changed.mdx b/src/content/reference/en/p5/changed.mdx new file mode 100644 index 0000000000..fe61f0038b --- /dev/null +++ b/src/content/reference/en/p5/changed.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: changed +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

myElement.changed() sets a function to call when the value of + the + + p5.Element object changes. Calling + + myElement.changed(false) disables the function.

+line: 309 +params: + - name: fxn + description: | +

function to call when the element changes. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create a dropdown menu and add a few color options. + let drop = createSelect(); + drop.position(0, 0); + drop.option('red'); + drop.option('green'); + drop.option('blue'); + + // When the color option changes, paint the background with + // that color. + drop.changed(() => { + let c = drop.value(); + background(c); + }); + + describe('A gray square with a dropdown menu at the top. The square changes color when an option is selected.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create a checkbox and place it beneath the canvas. + let checkbox = createCheckbox(' circle'); + checkbox.position(0, 100); + + // When the checkbox changes, paint the background gray + // and determine whether to draw a circle. + checkbox.changed(() => { + background(200); + if (checkbox.checked() === true) { + circle(50, 50, 30); + } + }); + + describe('A gray square with a checkbox underneath it that says "circle". A white circle appears when the box is checked and disappears otherwise.'); + } + +
+chainable: true +--- + + +# changed diff --git a/src/content/reference/en/p5/circle.mdx b/src/content/reference/en/p5/circle.mdx new file mode 100644 index 0000000000..d3ce39e4da --- /dev/null +++ b/src/content/reference/en/p5/circle.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: circle +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: | +

Draws a circle to the canvas. A circle is a round shape. Every point on the + edge of a circle is the same distance from its center. By default, the first + two parameters set the location of the center of the circle. The third + parameter sets the shape's width and height (diameter). The origin may be + changed with the ellipseMode() function.

+line: 274 +params: + - name: x + description: | +

x-coordinate of the center of the circle.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the center of the circle.

+ type: Number + - name: d + description: | +

diameter of the circle.

+ type: Number +itemtype: method +class: p5 +example: + - > + +
+ + + + circle(30, 30, 20); + + describe('A white circle with black outline in the middle of a gray + canvas.'); + + + +
+chainable: true +--- + + +# circle diff --git a/src/content/reference/en/p5/class.mdx b/src/content/reference/en/p5/class.mdx new file mode 100644 index 0000000000..4636781caa --- /dev/null +++ b/src/content/reference/en/p5/class.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: class +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Creates and names a class which is a template for + + the creation of objects.

+ +

From the + MDN entry: + + The class declaration creates a new Class with a given name using + + prototype-based inheritance.

+line: 379 +itemtype: property +class: p5 +example: + - >- + +
+ + + + class Rectangle { + constructor(name, height, width) { + this.name = name; + this.height = height; + this.width = width; + } + } + + let square = new Rectangle('square', 1, 1); // creating new instance of + Polygon Class. + + console.log(square.width); // prints '1' to the console + + + +
+alt: This example does not render anything +chainable: false +--- + + +# class diff --git a/src/content/reference/en/p5/clear.mdx b/src/content/reference/en/p5/clear.mdx new file mode 100644 index 0000000000..e9f32dea41 --- /dev/null +++ b/src/content/reference/en/p5/clear.mdx @@ -0,0 +1,96 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clear +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Clears the pixels on the canvas. This function makes every pixel 100% + + transparent. Calling clear() doesn't clear objects created by + createX() + + functions such as createGraphics(), + + createVideo(), and + + createImg(). These objects will remain + + unchanged after calling clear() and can be redrawn.

+ +

In WebGL mode, this function can clear the screen to a specific color. It + + interprets four numeric parameters as normalized RGBA color values. It also + + clears the depth buffer. If you are not using the WebGL renderer, these + + parameters will have no effect.

+line: 390 +params: + - name: r + description: | +

normalized red value.

+ type: Number + optional: true + - name: g + description: | +

normalized green value.

+ type: Number + optional: true + - name: b + description: | +

normalized blue value.

+ type: Number + optional: true + - name: a + description: | +

normalized alpha value.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + circle(mouseX, mouseY, 20); + describe('A white circle is drawn at the mouse x- and y-coordinates.'); + } + + function mousePressed() { + clear(); + background(128); + describe('The canvas is cleared when the mouse is clicked.'); + } + +
+ +
+ + let pg; + + function setup() { + createCanvas(100, 100); + background(200); + + pg = createGraphics(60, 60); + pg.background(200); + pg.noStroke(); + pg.circle(pg.width / 2, pg.height / 2, 15); + image(pg, 20, 20); + describe('A white circle drawn on a gray square. The square gets smaller when the mouse is pressed.'); + } + + function mousePressed() { + clear(); + image(pg, 20, 20); + } + +
+chainable: true +--- + + +# clear diff --git a/src/content/reference/en/p5/clearDepth.mdx b/src/content/reference/en/p5/clearDepth.mdx new file mode 100644 index 0000000000..aa6e7e9601 --- /dev/null +++ b/src/content/reference/en/p5/clearDepth.mdx @@ -0,0 +1,92 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearDepth +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

This makes the canvas forget how far from the camera everything that has + + been drawn was. Use this if you want to make sure the next thing you draw + + will not draw behind anything that is already on the canvas.

+ +

This is useful for things like feedback effects, where you want the + previous + + frame to act like a background for the next frame, and not like a plane in + + 3D space in the scene.

+ +

This method is only available in WebGL mode. Since 2D mode does not have + + 3D depth, anything you draw will always go on top of the previous content on + + the canvas anyway.

+line: 381 +params: + - name: depth + description: > +

The value, between 0 and 1, to reset the depth to, where + + 0 corresponds to a value as close as possible to the camera before getting + + clipped, and 1 corresponds to a value as far away from the camera as + possible. + + The default value is 1.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let prev, next; + function setup() { + createCanvas(100, 100, WEBGL); + prev = createFramebuffer({ format: FLOAT }); + next = createFramebuffer({ format: FLOAT }); + noStroke(); + } + + function draw() { + // Swap prev and next so that we can use the previous + // frame as a texture when drawing the current frame + [prev, next] = [next, prev]; + + // Draw to the framebuffer + next.begin(); + background(255); + + push(); + tint(255, 253); + image(prev, -width/2, -height/2); + // Make sure the image plane doesn't block you from seeing any part + // of the scene + clearDepth(); + pop(); + + push(); + normalMaterial(); + translate(25*sin(frameCount * 0.014), 25*sin(frameCount * 0.02), 0); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + box(12); + pop(); + next.end(); + + image(next, -width/2, -height/2); + } + +
+alt: |- + A red, green, and blue box (using normalMaterial) moves and rotates around + the canvas, leaving a trail behind it that slowly grows and fades away. +chainable: false +--- + + +# clearDepth diff --git a/src/content/reference/en/p5/clearStorage.mdx b/src/content/reference/en/p5/clearStorage.mdx new file mode 100644 index 0000000000..cc94dfe23e --- /dev/null +++ b/src/content/reference/en/p5/clearStorage.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clearStorage +module: Data +submodule: LocalStorage +file: src/data/local_storage.js +description: | +

Clears all local storage items set with storeItem() + for the current domain.

+line: 173 +itemtype: method +class: p5 +example: + - |2- + +
+ + function setup() { + let myNum = 10; + let myBool = false; + storeItem('myNum', myNum); + storeItem('myBool', myBool); + print(getItem('myNum')); // logs 10 to the console + print(getItem('myBool')); // logs false to the console + clearStorage(); + print(getItem('myNum')); // logs null to the console + print(getItem('myBool')); // logs null to the console + } +
+chainable: false +--- + + +# clearStorage diff --git a/src/content/reference/en/p5/clip.mdx b/src/content/reference/en/p5/clip.mdx new file mode 100644 index 0000000000..4bbf17f0b9 --- /dev/null +++ b/src/content/reference/en/p5/clip.mdx @@ -0,0 +1,117 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: clip +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Use the shape drawn by a callback function to mask subsequent things drawn + to the canvas. + + Only opaque regions of the mask shape will allow content to be drawn.

+ +

The mask will apply to anything drawn after this call. To draw without a + mask, contain + + the code to apply the mask and to draw the masked content between + + push() and pop().

+ +

Alternatively, rather than drawing the mask shape in a function, draw the + + shape between beginClip() and endClip().

+ +

Options can include:

+ + +line: 120 +params: + - name: callback + description: | +

A function that draws the mask shape.

+ type: Function + - name: options + description: | +

An object containing clip settings.

+ type: Object + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + noStroke(); + + // Mask in some shapes + push(); + clip(() => { + triangle(15, 37, 30, 13, 43, 37); + circle(45, 45, 7); + }); + + fill('red'); + rect(5, 5, 45, 45); + pop(); + + translate(50, 50); + + // Mask out the same shapes + push(); + clip(() => { + triangle(15, 37, 30, 13, 43, 37); + circle(45, 45, 7); + }, { invert: true }); + + fill('red'); + rect(5, 5, 45, 45); + pop(); + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(255); + noStroke(); + + clip(() => { + push(); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + scale(0.5); + torus(30, 15); + pop(); + }); + + beginShape(QUAD_STRIP); + fill(0, 255, 255); + vertex(-width/2, -height/2); + vertex(width/2, -height/2); + fill(100, 0, 100); + vertex(-width/2, height/2); + vertex(width/2, height/2); + endShape(); + } + +
+alt: |- + A silhouette of a rotating torus colored with a gradient from + cyan to purple +chainable: false +--- + + +# clip diff --git a/src/content/reference/en/p5/color.mdx b/src/content/reference/en/p5/color.mdx new file mode 100644 index 0000000000..dffb94530e --- /dev/null +++ b/src/content/reference/en/p5/color.mdx @@ -0,0 +1,275 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: color +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: > +

Creates a p5.Color object. By default, the + + parameters are interpreted as RGB values. Calling color(255, 204, + 0) will + + return a bright yellow color. The way these parameters are interpreted may + + be changed with the colorMode() function.

+ +

The version of color() with one parameter interprets the value + one of two + + ways. If the parameter is a number, it's interpreted as a grayscale value. + + If the parameter is a string, it's interpreted as a CSS color string.

+ +

The version of color() with two parameters interprets the + first one as a + + grayscale value. The second parameter sets the alpha (transparency) value.

+ +

The version of color() with three parameters interprets them + as RGB, HSB, + + or HSL colors, depending on the current colorMode().

+ +

The version of color() with four parameters interprets them as + RGBA, HSBA, + + or HSLA colors, depending on the current colorMode(). The last + parameter + + sets the alpha (transparency) value.

+line: 120 +itemtype: method +class: p5 +example: + - >- + +
+ + + + const c = color(255, 204, 0); + + fill(c); + + noStroke(); + + rect(30, 20, 55, 55); + + describe('A yellow rectangle on a gray canvas.'); + + + +
+ + +
+ + + + // RGB values. + + let c = color(255, 204, 0); + + fill(c); + + noStroke(); + + circle(25, 25, 80); + + // A grayscale value. + + c = color(65); + + fill(c); + + circle(75, 75, 80); + + describe( + 'Two ellipses. The circle in the top-left corner is yellow and the one at the bottom-right is gray.' + ); + + + +
+ + +
+ + + + // A CSS named color. + + const c = color('magenta'); + + fill(c); + + noStroke(); + + square(20, 20, 60); + + describe('A magenta square on a gray canvas.'); + + + +
+ + +
+ + + + // CSS hex color codes. + + noStroke(); + + let c = color('#0f0'); + + fill(c); + + rect(0, 10, 45, 80); + + c = color('#00ff00'); + + fill(c); + + rect(55, 10, 45, 80); + + describe('Two bright green rectangles on a gray canvas.'); + + + +
+ + +
+ + + + // RGB and RGBA color strings. + + noStroke(); + + let c = color('rgb(0,0,255)'); + + fill(c); + + square(10, 10, 35); + + c = color('rgb(0%, 0%, 100%)'); + + fill(c); + + square(55, 10, 35); + + c = color('rgba(0, 0, 255, 1)'); + + fill(c); + + square(10, 55, 35); + + c = color('rgba(0%, 0%, 100%, 1)'); + + fill(c); + + square(55, 55, 35); + + describe('Four blue squares in corners of a gray canvas.'); + + + +
+ + +
+ + + + // HSL and HSLA color strings. + + let c = color('hsl(160, 100%, 50%)'); + + noStroke(); + + fill(c); + + rect(0, 10, 45, 80); + + c = color('hsla(160, 100%, 50%, 0.5)'); + + fill(c); + + rect(55, 10, 45, 80); + + describe('Two sea green rectangles. A darker rectangle on the left and a + brighter one on the right.'); + + + +
+ + +
+ + + + // HSB and HSBA color strings. + + let c = color('hsb(160, 100%, 50%)'); + + noStroke(); + + fill(c); + + rect(0, 10, 45, 80); + + c = color('hsba(160, 100%, 50%, 0.5)'); + + fill(c); + + rect(55, 10, 45, 80); + + describe('Two green rectangles. A darker rectangle on the left and a + brighter one on the right.'); + + + +
+ + +
+ + + + // Changing color modes. + + noStroke(); + + let c = color(50, 55, 100); + + fill(c); + + rect(0, 10, 45, 80); + + colorMode(HSB, 100); + + c = color(50, 55, 100); + + fill(c); + + rect(55, 10, 45, 80); + + describe('Two blue rectangles. A darker rectangle on the left and a brighter + one on the right.'); + + + +
+return: + description: resulting color. + type: p5.Color +chainable: false +--- + + +# color diff --git a/src/content/reference/en/p5/colorMode.mdx b/src/content/reference/en/p5/colorMode.mdx new file mode 100644 index 0000000000..11bbc61933 --- /dev/null +++ b/src/content/reference/en/p5/colorMode.mdx @@ -0,0 +1,149 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: colorMode +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Changes the way p5.js interprets color data. By default, the numeric + + parameters for fill(), + + stroke(), + + background(), and + + color() are defined by values between 0 and 255 + + using the RGB color model. This is equivalent to calling + + colorMode(RGB, 255). Pure red is color(255, 0, 0) in + this model.

+ +

Calling colorMode(RGB, 100) sets colors to be interpreted as + RGB color + + values between 0 and 100. Pure red is color(100, 0, 0) in this + model.

+ +

Calling colorMode(HSB) or colorMode(HSL) changes + to HSB or HSL system + + instead of RGB.

+ +

p5.Color objects remember the mode that they were + + created in. Changing modes doesn't affect their appearance.

+line: 459 +itemtype: method +class: p5 +example: + - > + +
+ + + + noStroke(); + + colorMode(RGB, 100); + + for (let i = 0; i < 100; i += 1) { + for (let j = 0; j < 100; j += 1) { + stroke(i, j, 0); + point(i, j); + } + } + + describe( + 'A diagonal green to red gradient from bottom-left to top-right with shading transitioning to black at top-left corner.' + ); + + + +
+ + +
+ + + + noStroke(); + + colorMode(HSB, 100); + + for (let i = 0; i < 100; i++) { + for (let j = 0; j < 100; j++) { + stroke(i, j, 100); + point(i, j); + } + } + + describe('A rainbow gradient from left-to-right. Brightness transitions to + white at the top.'); + + + +
+ + +
+ + + + colorMode(RGB, 255); + + let myColor = color(180, 175, 230); + + background(myColor); + + colorMode(RGB, 1); + + let redValue = red(myColor); + + let greenValue = green(myColor); + + let blueValue = blue(myColor); + + text(`Red: ${redValue}`, 10, 10, 80, 80); + + text(`Green: ${greenValue}`, 10, 40, 80, 80); + + text(`Blue: ${blueValue}`, 10, 70, 80, 80); + + describe('A purple canvas with the red, green, and blue decimal values of + the color written on it.'); + + + +
+ + +
+ + + + noFill(); + + colorMode(RGB, 255, 255, 255, 1); + + background(255); + + strokeWeight(4); + + stroke(255, 0, 10, 0.3); + + circle(40, 40, 50); + + circle(50, 60, 50); + + describe('Two overlapping translucent pink circle outlines.'); + + + +
+chainable: true +--- + + +# colorMode diff --git a/src/content/reference/en/p5/concat.mdx b/src/content/reference/en/p5/concat.mdx new file mode 100644 index 0000000000..0e72f59e0a --- /dev/null +++ b/src/content/reference/en/p5/concat.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: concat +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Concatenates two arrays, maps to Array.concat(). Does not modify the + input arrays.

+line: 112 +params: + - name: a + description: | +

first Array to concatenate

+ type: Array + - name: b + description: | +

second Array to concatenate

+ type: Array +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let arr1 = ['A', 'B', 'C']; + let arr2 = [1, 2, 3]; + + print(arr1); // ['A','B','C'] + print(arr2); // [1,2,3] + + let arr3 = concat(arr1, arr2); + + print(arr1); // ['A','B','C'] + print(arr2); // [1, 2, 3] + print(arr3); // ['A','B','C', 1, 2, 3] + } +
+return: + description: concatenated array + type: Array +chainable: false +--- + + +# concat diff --git a/src/content/reference/en/p5/cone.mdx b/src/content/reference/en/p5/cone.mdx new file mode 100644 index 0000000000..d1664179a3 --- /dev/null +++ b/src/content/reference/en/p5/cone.mdx @@ -0,0 +1,121 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: cone +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Draw a cone with given radius and height

+ +

DetailX and detailY determine the number of subdivisions in the x-dimension + and + + the y-dimension of a cone. More subdivisions make the cone seem smoother. The + + recommended maximum value for detailX is 24. Using a value greater than 24 + + may cause a warning or slow down the browser.

+line: 742 +params: + - name: radius + description: | +

radius of the bottom surface

+ type: Number + optional: true + - name: height + description: | +

height of the cone

+ type: Number + optional: true + - name: detailX + description: | +

number of segments, + the more segments the smoother geometry + default is 24

+ type: Integer + optional: true + - name: detailY + description: | +

number of segments, + the more segments the smoother geometry + default is 1

+ type: Integer + optional: true + - name: cap + description: | +

whether to draw the base of the cone

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a spinning cone + // with radius 40 and height 70 + function setup() { + createCanvas(100, 100, WEBGL); + describe('a rotating white cone'); + } + + function draw() { + background(200); + rotateX(frameCount * 0.01); + rotateZ(frameCount * 0.01); + cone(40, 70); + } + +
+ - |- + +
+ + // slide to see how detailx works + let detailX; + function setup() { + createCanvas(100, 100, WEBGL); + detailX = createSlider(3, 16, 3); + detailX.position(10, height + 5); + detailX.style('width', '80px'); + describe( + 'a rotating white cone with limited X detail, with a slider that adjusts detailX' + ); + } + + function draw() { + background(205, 102, 94); + rotateY(millis() / 1000); + cone(30, 65, detailX.value(), 16); + } + +
+ - |- + +
+ + // slide to see how detailY works + let detailY; + function setup() { + createCanvas(100, 100, WEBGL); + detailY = createSlider(3, 16, 3); + detailY.position(10, height + 5); + detailY.style('width', '80px'); + describe( + 'a rotating white cone with limited Y detail, with a slider that adjusts detailY' + ); + } + + function draw() { + background(205, 102, 94); + rotateY(millis() / 1000); + cone(30, 65, 16, detailY.value()); + } + +
+chainable: true +--- + + +# cone diff --git a/src/content/reference/en/p5/const.mdx b/src/content/reference/en/p5/const.mdx new file mode 100644 index 0000000000..210de7acec --- /dev/null +++ b/src/content/reference/en/p5/const.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: const +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Creates and names a new constant. Like a variable created with let, + + a constant that is created with const is a container + for a value, + + however constants cannot be reassigned once they are declared. Although it is + + noteworthy that for non-primitive data types like objects & arrays, their + + elements can still be changeable. So if a variable is assigned an array, you + + can still add or remove elements from the array but cannot reassign another + + array to it. Also unlike let, you cannot declare variables + without value + + using const.

+ +

Constants have block-scope. This means that the constant only exists within + + the + + block that it is created within. A constant cannot be redeclared within a + scope in which it + + already exists.

+ +

From the + MDN entry: + + Declares a read-only named constant. + + Constants are block-scoped, much like variables defined using the 'let' + statement. + + The value of a constant can't be changed through reassignment, and it can't be + redeclared.

+line: 34 +itemtype: property +class: p5 +example: + - |- + +
+ + // define myFavNumber as a constant and give it the value 7 + const myFavNumber = 7; + console.log('my favorite number is: ' + myFavNumber); + +
+ +
+ + const bigCats = ['lion', 'tiger', 'panther']; + bigCats.push('leopard'); + console.log(bigCats); + // bigCats = ['cat']; // throws error as re-assigning not allowed for const + +
+ +
+ + const wordFrequency = {}; + wordFrequency['hello'] = 2; + wordFrequency['bye'] = 1; + console.log(wordFrequency); + // wordFrequency = { 'a': 2, 'b': 3}; // throws error here + +
+alt: These examples do not render anything +chainable: false +--- + + +# const diff --git a/src/content/reference/en/p5/constrain.mdx b/src/content/reference/en/p5/constrain.mdx new file mode 100644 index 0000000000..1c9b082a9e --- /dev/null +++ b/src/content/reference/en/p5/constrain.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: constrain +module: Math +submodule: Calculation +file: src/math/calculation.js +description: | +

Constrains a number between a minimum and maximum value.

+line: 69 +params: + - name: 'n' + description: | +

number to constrain.

+ type: Number + - name: low + description: | +

minimum limit.

+ type: Number + - name: high + description: | +

maximum limit.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + let x = constrain(mouseX, 33, 67); + let y = 50; + + strokeWeight(5); + point(x, y); + + describe('A black dot drawn on a gray square follows the mouse from left to right. Its movement is constrained to the middle third of the square.'); + } + +
+ +
+ + function draw() { + background(200); + + // Set boundaries and draw them. + let leftWall = width * 0.25; + let rightWall = width * 0.75; + line(leftWall, 0, leftWall, height); + line(rightWall, 0, rightWall, height); + + // Draw a circle that follows the mouse freely. + fill(255); + circle(mouseX, height / 3, 9); + + // Draw a circle that's constrained. + let xc = constrain(mouseX, leftWall, rightWall); + fill(0); + circle(xc, 2 * height / 3, 9); + + describe('Two vertical lines. Two circles move horizontally with the mouse. One circle stops at the vertical lines.'); + } + +
+return: + description: constrained number. + type: Number +chainable: false +--- + + +# constrain diff --git a/src/content/reference/en/p5/copy.mdx b/src/content/reference/en/p5/copy.mdx new file mode 100644 index 0000000000..e5a0e610d9 --- /dev/null +++ b/src/content/reference/en/p5/copy.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: copy +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Copies pixels from a source image to a region of the canvas. The source + + image can be the canvas itself or a p5.Image + + object. copy() will scale pixels from the source region if it + isn't the + + same size as the destination region.

+line: 207 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + background(img); + copy(img, 7, 22, 10, 10, 35, 25, 50, 50); + // Show copied region. + stroke(255); + noFill(); + square(7, 22, 10); + + describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.'); + } + +
+chainable: false +--- + + +# copy diff --git a/src/content/reference/en/p5/cos.mdx b/src/content/reference/en/p5/cos.mdx new file mode 100644 index 0000000000..6b4cdd12e9 --- /dev/null +++ b/src/content/reference/en/p5/cos.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: cos +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

Calculates the cosine of an angle. cos() is useful for many + geometric + + tasks in creative coding. The values returned oscillate between -1 and 1 + + as the input angle increases. cos() takes into account the + current + + angleMode.

+line: 183 +params: + - name: angle + description: | +

the angle.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + let t = frameCount; + let x = 30 * cos(t * 0.05) + 50; + let y = 50; + line(50, y, x, y); + circle(x, y, 20); + + describe('A white ball on a string oscillates left and right.'); + } + +
+ +
+ + function draw() { + let x = frameCount; + let y = 30 * cos(x * 0.1) + 50; + point(x, y); + + describe('A series of black dots form a wave pattern.'); + } + +
+ +
+ + function draw() { + let t = frameCount; + let x = 30 * cos(t * 0.1) + 50; + let y = 10 * sin(t * 0.2) + 50; + point(x, y); + + describe('A series of black dots form an infinity symbol.'); + } + +
+return: + description: cosine of the angle. + type: Number +chainable: false +--- + + +# cos diff --git a/src/content/reference/en/p5/createA.mdx b/src/content/reference/en/p5/createA.mdx new file mode 100644 index 0000000000..e67674724d --- /dev/null +++ b/src/content/reference/en/p5/createA.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createA +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates an <a></a> element that links to another + web page.

+ +

The first parmeter, href, is a string that sets the URL of the + linked + + page.

+ +

The second parameter, html, is a string that sets the inner + HTML of the + + link. It's common to use text, images, or buttons as links.

+ +

The third parameter, target, is optional. It's a string that + tells the + + web browser where to open the link. By default, links open in the current + + browser tab. Passing '_blank' will cause the link to open in a + new + + browser tab. MDN describes a few + + other options.

+line: 655 +params: + - name: href + description: | +

URL of linked page.

+ type: String + - name: html + description: | +

inner HTML of link element to display.

+ type: String + - name: target + description: | +

target where the new link should open, + either '_blank', '_self', '_parent', or '_top'.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create an anchor element that links to p5js.org. + let a = createA('http://p5js.org/', 'p5*js'); + a.position(25, 35); + + describe('The text "p5*js" written at the center of a gray square.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create an anchor element that links to p5js.org. + // Open the link in a new tab. + let a = createA('http://p5js.org/', 'p5*js', '_blank'); + a.position(25, 35); + + describe('The text "p5*js" written at the center of a gray square.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createA diff --git a/src/content/reference/en/p5/createAudio.mdx b/src/content/reference/en/p5/createAudio.mdx new file mode 100644 index 0000000000..4917a4d953 --- /dev/null +++ b/src/content/reference/en/p5/createAudio.mdx @@ -0,0 +1,77 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createAudio +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a hidden <audio> element for simple audio + playback. + + Returns a new p5.MediaElement object.

+ +

The first parameter, src, is the path the video. If a single + string is + + passed, as in 'assets/video.mp4', a single video is loaded. An + array + + of strings can be used to load the same video in different formats. For + + example, ['assets/video.mp4', 'assets/video.ogv', + 'assets/video.webm']. + + This is useful for ensuring that the video can play across different + + browsers with different capabilities. See + + MDN + + for more information about supported formats.

+ +

The second parameter, callback, is optional. It's a function + to call once + + the audio is ready to play.

+line: 2043 +params: + - name: src + description: | +

path to an audio file, or an array of paths + for supporting different browsers.

+ type: 'String|String[]' + optional: true + - name: callback + description: | +

function to call once the audio is ready to play.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + 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.'); + } + +
+return: + description: new p5.MediaElement object. + type: p5.MediaElement +chainable: false +--- + + +# createAudio diff --git a/src/content/reference/en/p5/createButton.mdx b/src/content/reference/en/p5/createButton.mdx new file mode 100644 index 0000000000..00fd90b31f --- /dev/null +++ b/src/content/reference/en/p5/createButton.mdx @@ -0,0 +1,95 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createButton +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <button></button> element.

+ +

The first parameter, label, is a string that sets the label + displayed on + + the button.

+ +

The second parameter, value, is optional. It's a string that + sets the + + button's value. See + + MDN + + for more details.

+line: 842 +params: + - name: label + description: | +

label displayed on the button.

+ type: String + - name: value + description: | +

value of the button.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create a button and place it beneath the canvas. + let button = createButton('click me'); + button.position(0, 100); + + // Use the button to change the background color. + button.mousePressed(() => { + let g = random(255); + background(g); + }); + + describe('A gray square with a button that says "click me" beneath it. The square changes color when the button is clicked.'); + } + +
+ +
+ + let button; + + function setup() { + // Create a button and set its value to 0. + // Place the button beneath the canvas. + button = createButton('click me', 'red'); + button.position(0, 100); + + // Change the button's value when the mouse + // is pressed. + button.mousePressed(() => { + let c = random(['red', 'green', 'blue', 'yellow']); + button.value(c); + }); + + describe('A red square with a button that says "click me" beneath it. The square changes color when the button is clicked.'); + } + + function draw() { + // Use the button's value to set the background color. + let c = button.value(); + background(c); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createButton diff --git a/src/content/reference/en/p5/createCamera.mdx b/src/content/reference/en/p5/createCamera.mdx new file mode 100644 index 0000000000..efea130b87 --- /dev/null +++ b/src/content/reference/en/p5/createCamera.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createCamera +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

Creates a new p5.Camera object and sets it + + as the current (active) camera.

+ +

The new camera is initialized with a default position + + (see camera()) + + and a default perspective projection + + (see perspective()). + + Its properties can be controlled with the p5.Camera + + methods.

+ +

Note: Every 3D sketch starts with a default camera initialized. + + This camera can be controlled with the global methods + + camera(), + + perspective(), ortho(), + + and frustum() if it is the only camera + + in the scene.

+line: 331 +itemtype: method +class: p5 +example: + - |- + +
+ // Creates a camera object and animates it around a box. + let camera; + function setup() { + createCanvas(100, 100, WEBGL); + background(0); + camera = createCamera(); + camera.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + camera.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + describe('An example that creates a camera and moves it around the box.'); + } + + function draw() { + background(0); + // The camera will automatically + // rotate to look at [0, 0, 0]. + camera.lookAt(0, 0, 0); + + // The camera will move on the + // x axis. + camera.setPosition(sin(frameCount / 60) * 200, 0, 100); + box(20); + + // A 'ground' box to give the viewer + // a better idea of where the camera + // is looking. + translate(0, 50, 0); + rotateX(HALF_PI); + box(150, 150, 20); + } +
+alt: An example that creates a camera and moves it around the box. +return: + description: The newly created camera object. + type: p5.Camera +chainable: false +--- + + +# createCamera diff --git a/src/content/reference/en/p5/createCanvas.mdx b/src/content/reference/en/p5/createCanvas.mdx new file mode 100644 index 0000000000..b4e891bb6e --- /dev/null +++ b/src/content/reference/en/p5/createCanvas.mdx @@ -0,0 +1,84 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createCanvas +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

Creates a canvas element in the document and sets its dimensions + + in pixels. This method should be called only once at the start of setup(). + + Calling createCanvas more than once in a + + sketch will result in very unpredictable behavior. If you want more than + + one drawing canvas you could use createGraphics() + + (hidden by default but it can be shown).

+ +

Important note: in 2D mode (i.e. when p5.Renderer is not set) + the origin (0,0) + + is positioned at the top left of the screen. In 3D mode (i.e. when + p5.Renderer + + is set to WEBGL), the origin is positioned at the center of the + canvas. + + See this issue + for more information.

+ +

A WebGL canvas will use a WebGL2 context if it is supported by the browser. + + Check the webglVersion property to check what + + version is being used, or call setAttributes({ + version: 1 }) + + to create a WebGL1 context.

+ +

The system variables width and height are set by the parameters passed to + this + + function. If createCanvas() is not used, the + + window will be given a default size of 100×100 pixels.

+ +

Optionally, an existing canvas can be passed using a selector, ie. + document.getElementById(''). + + If specified, avoid using setAttributes() afterwards, as this + will remove and recreate the existing canvas.

+ +

For more ways to position the canvas, see the + + + + positioning the canvas wiki page.

+line: 15 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 50); + background(153); + line(0, 0, width, height); + } + +
+alt: Black line extending from top-left of canvas to bottom right. +return: + description: pointer to p5.Renderer holding canvas + type: p5.Renderer +chainable: false +--- + + +# createCanvas diff --git a/src/content/reference/en/p5/createCapture.mdx b/src/content/reference/en/p5/createCapture.mdx new file mode 100644 index 0000000000..a5499b147e --- /dev/null +++ b/src/content/reference/en/p5/createCapture.mdx @@ -0,0 +1,146 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createCapture +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <video> element that "captures" the + audio/video stream from + + the webcam and microphone. Returns a new + + p5.Element object.

+ +

Videos are shown by default. They can be hidden by calling + capture.hide() + + and drawn to the canvas using image().

+ +

The first parameter, type, is optional. It sets the type of + capture to + + use. By default, createCapture() captures both audio and video. + If VIDEO + + is passed, as in createCapture(VIDEO), only video will be + captured. + + If AUDIO is passed, as in createCapture(AUDIO), only + audio will be + + captured. A constraints object can also be passed to customize the stream. + + See the + + W3C documentation for possible properties. Different browsers support + different + + properties.

+ +

The second parameter, callback, is optional. It's a function + to call once + + the capture is ready for use. The callback function should have one + + parameter, stream, that's a + + MediaStream object.

+ +

Note: createCapture() only works when running a sketch locally + or using HTTPS. Learn more + + here + + and here.

+line: 2121 +params: + - name: type + description: | +

type of capture, either AUDIO or VIDEO, + or a constraints object. Both video and audio + audio streams are captured by default.

+ type: String|Constant|Object + optional: true + - name: callback + description: | +

function to call once the stream + has loaded.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + noCanvas(); + createCapture(VIDEO); + + describe('A video stream from the webcam.'); + } + +
+ +
+ + let capture; + + function setup() { + // 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); + } + +
+ +
+ + 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.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createCapture diff --git a/src/content/reference/en/p5/createCheckbox.mdx b/src/content/reference/en/p5/createCheckbox.mdx new file mode 100644 index 0000000000..f83d9fb16d --- /dev/null +++ b/src/content/reference/en/p5/createCheckbox.mdx @@ -0,0 +1,123 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createCheckbox +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a checkbox <input></input> element. + Checkboxes extend + + the p5.Element class with a checked() + method. + + Calling myBox.checked() returns true if it the box + is checked and + + false otherwise.

+ +

The first parameter, label, is optional. It's a string that + sets the label + + to display next to the checkbox.

+ +

The second parameter, value, is also optional. It's a boolean + that sets the + + checkbox's value.

+line: 914 +params: + - name: label + description: | +

label displayed after the checkbox.

+ type: String + optional: true + - name: value + description: > +

value of the checkbox. Checked is true and unchecked is + false.

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let checkbox; + + function setup() { + // 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); + } + } + +
+ +
+ + let checkbox; + + function setup() { + // 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); + } + } + +
+ +
+ + let checkbox; + + function setup() { + // 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); + } + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createCheckbox diff --git a/src/content/reference/en/p5/createColorPicker.mdx b/src/content/reference/en/p5/createColorPicker.mdx new file mode 100644 index 0000000000..ba3a1fcbce --- /dev/null +++ b/src/content/reference/en/p5/createColorPicker.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createColorPicker +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a color picker element.

+ +

The parameter, value, is optional. If a color string or + + p5.Color object is passed, it will set the default + + color.

+ +

Color pickers extend the p5.Element class with a + + couple of helpful methods for managing colors:

+ + +line: 1614 +params: + - name: value + description: > +

default color as a CSS color string.

+ type: String|p5.Color + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let myPicker; + + function setup() { + myPicker = createColorPicker('deeppink'); + myPicker.position(0, 100); + + describe('A pink square with a color picker beneath it. The square changes color when the user picks a new color.'); + } + + function draw() { + // Use the color picker to paint the background. + let c = myPicker.color(); + background(c); + } + +
+ +
+ + let myPicker; + + function setup() { + myPicker = createColorPicker('deeppink'); + myPicker.position(0, 100); + + describe('A number with the format "#rrggbb" is displayed on a pink canvas. The background color and number change when the user picks a new color.'); + } + + function draw() { + // Use the color picker to paint the background. + let c = myPicker.value(); + background(c); + + // Display the current color as a hex string. + text(c, 25, 55); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createColorPicker diff --git a/src/content/reference/en/p5/createConvolver.mdx b/src/content/reference/en/p5/createConvolver.mdx new file mode 100644 index 0000000000..01ca48e073 --- /dev/null +++ b/src/content/reference/en/p5/createConvolver.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createConvolver +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Create a p5.Convolver. Accepts a path to a soundfile + that will be used to generate an impulse response.

+line: 8885 +params: + - name: path + description: | +

path to a sound file

+ type: String + - name: callback + description: | +

function to call if loading is successful. + The object will be passed in as the argument + to the callback function.

+ type: Function + optional: true + - name: errorCallback + description: | +

function to call if loading is not successful. + A custom error will be passed in as the argument + to the callback function.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ let cVerb, sound; + function preload() { + // We have both MP3 and OGG versions of all sound assets + soundFormats('ogg', 'mp3'); + + // Try replacing 'bx-spring' with other soundfiles like + // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox' + cVerb = createConvolver('assets/bx-spring.mp3'); + + // Try replacing 'Damscray_DancingTiger' with + // 'beat', 'doorbell', lucky_dragons_-_power_melody' + sound = loadSound('assets/Damscray_DancingTiger.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(playSound); + background(220); + text('tap to play', 20, 20); + + // disconnect from main output... + sound.disconnect(); + + // ...and process with cVerb + // so that we only hear the convolution + cVerb.process(sound); + } + + function playSound() { + sound.play(); + } +
+return: + description: '' + type: p5.Convolver +chainable: false +--- + + +# createConvolver diff --git a/src/content/reference/en/p5/createDiv.mdx b/src/content/reference/en/p5/createDiv.mdx new file mode 100644 index 0000000000..e407f5adbb --- /dev/null +++ b/src/content/reference/en/p5/createDiv.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createDiv +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <div></div> element. It's commonly used + as a + + container for other elements.

+ +

The parameter html is optional. It accepts a string that sets + the + + inner HTML of the new <div></div>.

+line: 444 +params: + - name: html + description: > +

inner HTML for the new <div></div> + element.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + let div = createDiv('p5*js'); + div.position(25, 35); + + describe('A gray square with the text "p5*js" written in its center.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create an h3 element within the div. + let div = createDiv('

p5*js

'); + div.position(20, 5); + + describe('A gray square with the text "p5*js" written in its center.'); + } +
+
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createDiv diff --git a/src/content/reference/en/p5/createElement.mdx b/src/content/reference/en/p5/createElement.mdx new file mode 100644 index 0000000000..05fbf91b49 --- /dev/null +++ b/src/content/reference/en/p5/createElement.mdx @@ -0,0 +1,71 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createElement +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a new p5.Element object.

+ +

The first parameter, tag, is a string an HTML tag such as + 'h5'.

+ +

The second parameter, content, is optional. It's a string that + sets the + + HTML content to insert into the new element. New elements have no content + + by default.

+line: 2267 +params: + - name: tag + description: | +

tag for the new element.

+ type: String + - name: content + description: | +

HTML content to insert into the element.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create an h5 element with nothing in it. + createElement('h5'); + + describe('A gray square.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create an h5 element with the content + // "p5*js". + let h5 = createElement('h5', 'p5*js'); + // Set the element's style and position. + h5.style('color', 'deeppink'); + h5.position(30, 15); + + describe('The text "p5*js" written in pink in the middle of a gray square.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createElement diff --git a/src/content/reference/en/p5/createFileInput.mdx b/src/content/reference/en/p5/createFileInput.mdx new file mode 100644 index 0000000000..a09cf67f34 --- /dev/null +++ b/src/content/reference/en/p5/createFileInput.mdx @@ -0,0 +1,127 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createFileInput +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates an <input></input> element of type + 'file'. + + This allows users to select local files for use in a sketch.

+ +

The first parameter, callback, is a function that's called + when the file + + loads. The callback function should have one parameter, file, + that's a + + p5.File object.

+ +

The second parameter, multiple, is optional. It's a boolean + value that + + allows loading multiple files if set to true. If + true, callback + + will be called once per file.

+line: 1785 +params: + - name: callback + description: | +

function to call once the file loads.

+ type: Function + - name: multiple + description: | +

allow multiple files to be selected.

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Use the file input to select an image to + // load and display. + let input; + let img; + + function setup() { + // Create a file input and place it beneath + // the canvas. + input = createFileInput(handleImage); + input.position(0, 100); + + describe('A gray square with a file input beneath it. If the user selects an image file to load, it is displayed on the square.'); + } + + function draw() { + background(200); + + // Draw the image if loaded. + if (img) { + image(img, 0, 0, width, height); + } + } + + // Create an image if the file is an image. + function handleImage(file) { + if (file.type === 'image') { + img = createImg(file.data, ''); + img.hide(); + } else { + img = null; + } + } + +
+ +
+ + // Use the file input to select multiple images + // to load and display. + let input; + let images = []; + + function setup() { + // Create a file input and place it beneath + // the canvas. Allow it to load multiple files. + input = createFileInput(handleImage, true); + input.position(0, 100); + } + + function draw() { + background(200); + + // Draw the images if loaded. Each image + // is drawn 20 pixels lower than the + // previous image. + images.forEach((img, index) => { + let y = index * 20; + image(img, 0, y, width, height); + }); + + describe('A gray square with a file input beneath it. If the user selects multiple image files to load, they are displayed on the square.'); + } + + // Create an image if the file is an image, + // then add it to the images array. + function handleImage(file) { + if (file.type === 'image') { + let img = createImg(file.data, ''); + img.hide(); + images.push(img); + } + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createFileInput diff --git a/src/content/reference/en/p5/createFilterShader.mdx b/src/content/reference/en/p5/createFilterShader.mdx new file mode 100644 index 0000000000..dfb6ac861c --- /dev/null +++ b/src/content/reference/en/p5/createFilterShader.mdx @@ -0,0 +1,119 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createFilterShader +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Creates a new p5.Shader using only a fragment + shader, as a convenience method for creating image effects. + + It's like createShader() but with a default + vertex shader included.

+ +

createFilterShader() is intended to be + used along with filter() for filtering the contents of + a canvas. + + A filter shader will not be applied to any geometries.

+ +

The fragment shader receives some uniforms:

+ + + +

For more info about filters and shaders, see Adam Ferriss' repo of shader + examples + + or the introduction + to shaders page.

+line: 202 +params: + - name: fragSrc + description: | +

source code for the fragment shader

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + let fragSrc = `precision highp float; + void main() { + gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); + }`; + + createCanvas(100, 100, WEBGL); + let s = createFilterShader(fragSrc); + filter(s); + describe('a yellow canvas'); + } + +
+ +
+ + let img, s; + function preload() { + img = loadImage('assets/bricks.jpg'); + } + function setup() { + let fragSrc = `precision highp float; + + // x,y coordinates, given from the vertex shader + varying vec2 vTexCoord; + + // the canvas contents, given from filter() + uniform sampler2D tex0; + // other useful information from the canvas + uniform vec2 texelSize; + uniform vec2 canvasSize; + // a custom variable from this sketch + uniform float darkness; + + void main() { + // get the color at current pixel + vec4 color = texture2D(tex0, vTexCoord); + // set the output color + color.b = 1.0; + color *= darkness; + gl_FragColor = vec4(color.rgb, 1.0); + }`; + + createCanvas(100, 100, WEBGL); + s = createFilterShader(fragSrc); + } + function draw() { + image(img, -50, -50); + s.setUniform('darkness', 0.5); + filter(s); + describe('a image of bricks tinted dark blue'); + } + +
+return: + description: |- + a shader object created from the provided + fragment shader. + type: p5.Shader +chainable: false +--- + + +# createFilterShader diff --git a/src/content/reference/en/p5/createFramebuffer.mdx b/src/content/reference/en/p5/createFramebuffer.mdx new file mode 100644 index 0000000000..d0336e412a --- /dev/null +++ b/src/content/reference/en/p5/createFramebuffer.mdx @@ -0,0 +1,131 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createFramebuffer +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

Creates and returns a new p5.Framebuffer, a + + high-performance WebGL object that you can draw to and then use as a + texture.

+ +

Options can include:

+ + + +

If width, height, or density are + specified, then the framebuffer will + + keep that size until manually changed. Otherwise, it will be autosized, and + + it will update to match the main canvas's size and density when the main + + canvas changes.

+line: 306 +params: + - name: options + description: | +

An optional object with configuration

+ type: Object + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let prev, next; + function setup() { + createCanvas(100, 100, WEBGL); + prev = createFramebuffer({ format: FLOAT }); + next = createFramebuffer({ format: FLOAT }); + noStroke(); + } + + function draw() { + // Swap prev and next so that we can use the previous + // frame as a texture when drawing the current frame + [prev, next] = [next, prev]; + + // Draw to the framebuffer + next.begin(); + background(255); + + push(); + tint(255, 253); + image(prev, -width/2, -height/2); + // Make sure the image plane doesn't block you from seeing any part + // of the scene + clearDepth(); + pop(); + + push(); + normalMaterial(); + translate(25*sin(frameCount * 0.014), 25*sin(frameCount * 0.02), 0); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + box(12); + pop(); + next.end(); + + image(next, -width/2, -height/2); + } + +
+alt: |- + A red, green, and blue box (using normalMaterial) moves and rotates around + the canvas, leaving a trail behind it that slowly grows and fades away. +return: + description: '' + type: p5.Framebuffer +chainable: false +--- + + +# createFramebuffer diff --git a/src/content/reference/en/p5/createGraphics.mdx b/src/content/reference/en/p5/createGraphics.mdx new file mode 100644 index 0000000000..6b21dd523d --- /dev/null +++ b/src/content/reference/en/p5/createGraphics.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createGraphics +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

Creates and returns a new p5.Graphics object. Use this class if you need + + to draw into an off-screen graphics buffer. The two parameters define the + + width and height in pixels.

+ +

A WebGL p5.Graphics will use a WebGL2 context if it is supported by the + browser. + + Check the pg.webglVersion property of the + renderer + + to check what version is being used, or call pg.setAttributes({ version: 1 }) + + to create a WebGL1 context.

+ +

Optionally, an existing canvas can be passed using a selector, ie. + document.getElementById(''). + + By default this canvas will be hidden (offscreen buffer), to make visible, set + element's style to display:block;

+line: 243 +itemtype: method +class: p5 +example: + - |- + +
+ + let pg; + function setup() { + createCanvas(100, 100); + pg = createGraphics(100, 100); + } + + function draw() { + background(200); + pg.background(100); + pg.noStroke(); + pg.ellipse(pg.width / 2, pg.height / 2, 50, 50); + image(pg, 50, 50); + image(pg, 0, 0, 50, 50); + } + +
+alt: 4 grey squares alternating light and dark grey. White quarter circle mid-left. +return: + description: offscreen graphics buffer + type: p5.Graphics +chainable: false +--- + + +# createGraphics diff --git a/src/content/reference/en/p5/createImage.mdx b/src/content/reference/en/p5/createImage.mdx new file mode 100644 index 0000000000..aa721cc8f4 --- /dev/null +++ b/src/content/reference/en/p5/createImage.mdx @@ -0,0 +1,142 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createImage +module: Image +submodule: Image +file: src/image/image.js +description: > +

Creates a new p5.Image object. The new image is + + transparent by default.

+ +

createImage() uses the width and + height paremeters to set the new + + p5.Image object's dimensions in pixels. The new + + p5.Image can be modified by updating its + + pixels array or by calling its + + get() and + + set() methods. The + + loadPixels() method must be called + + before reading or modifying pixel values. The + + updatePixels() method must be called + + for updates to take effect.

+line: 15 +params: + - name: width + description: | +

width in pixels.

+ type: Integer + - name: height + description: | +

height in pixels.

+ type: Integer +itemtype: method +class: p5 +example: + - >- + +
+ + + + let img = createImage(66, 66); + + img.loadPixels(); + + for (let x = 0; x < img.width; x += 1) { + for (let y = 0; y < img.height; y += 1) { + img.set(x, y, 0); + } + } + + img.updatePixels(); + + image(img, 17, 17); + + + describe('A black square drawn in the middle of a gray square.'); + + + +
+ + +
+ + + + let img = createImage(66, 66); + + img.loadPixels(); + + for (let x = 0; x < img.width; x += 1) { + for (let y = 0; y < img.height; y += 1) { + let a = map(x, 0, img.width, 0, 255); + let c = color(0, a); + img.set(x, y, c); + } + } + + img.updatePixels(); + + image(img, 17, 17); + + + describe('A square with a horizontal color gradient that transitions from + gray to black.'); + + + +
+ + +
+ + + + let img = createImage(66, 66); + + img.loadPixels(); + + let d = pixelDensity(); + + let halfImage = 4 * (d * img.width) * (d * img.height / 2); + + for (let i = 0; i < halfImage; i += 4) { + // Red. + img.pixels[i] = 0; + // Green. + img.pixels[i + 1] = 0; + // Blue. + img.pixels[i + 2] = 0; + // Alpha. + img.pixels[i + 3] = 255; + } + + img.updatePixels(); + + image(img, 17, 17); + + + describe('A black square drawn in the middle of a gray square.'); + + + +
+return: + description: new p5.Image object. + type: p5.Image +chainable: false +--- + + +# createImage diff --git a/src/content/reference/en/p5/createImg.mdx b/src/content/reference/en/p5/createImg.mdx new file mode 100644 index 0000000000..9923f6cdd1 --- /dev/null +++ b/src/content/reference/en/p5/createImg.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createImg +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates an <img> element that can appear outside of the + canvas.

+ +

The first parameter, src, is a string with the path to the + image file. + + src should be a relative path, as in + 'assets/image.png', or a URL, as + + in 'https://example.com/image.png'.

+ +

The second parameter, alt, is a string with the + + alternate text + + for the image. An empty string '' can be used for images that + aren't displayed.

+ +

The third parameter, crossOrigin, is optional. It's a string + that sets the + + crossOrigin property + + of the image. Use 'anonymous' or 'use-credentials' + to fetch the image + + with cross-origin access.

+ +

The fourth parameter, callback, is also optional. It sets a + function to + + call after the image loads. The new image is passed to the callback + + function as a p5.Element object.

+line: 583 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + let img = createImg( + 'https://p5js.org/assets/img/asterisk-01.png', + 'The p5.js magenta asterisk.' + ); + img.position(0, -10); + + describe('A gray square with a magenta asterisk in its center.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createImg diff --git a/src/content/reference/en/p5/createInput.mdx b/src/content/reference/en/p5/createInput.mdx new file mode 100644 index 0000000000..75839e9fa3 --- /dev/null +++ b/src/content/reference/en/p5/createInput.mdx @@ -0,0 +1,86 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createInput +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a text <input></input> element. Call + myInput.size() + + to set the length of the text box.

+ +

The first parameter, value, is optional. It's a string that + sets the + + input's default value. The input is blank by default.

+ +

The second parameter, type, is also optional. It's a string + that + + specifies the type of text being input. See MDN for a full + + list of options. + + The default is 'text'.

+line: 1708 +itemtype: method +class: p5 +example: + - |- + +
+ + let myInput; + + function setup() { + // Create an input element and place it + // beneath the canvas. + myInput = createInput(); + myInput.position(0, 100); + + describe('A gray square with a text box beneath it. The text in the square changes when the user types something new in the input bar.'); + } + + function draw() { + background(200); + + // Use the input to display a message. + let msg = myInput.value(); + text(msg, 25, 55); + } + +
+ +
+ + let myInput; + + function setup() { + // Create an input element and place it + // beneath the canvas. Set its default + // text to "hello!". + myInput = createInput('hello!'); + myInput.position(0, 100); + + describe('The text "hello!" written at the center of a gray square. A text box beneath the square also says "hello!". The text in the square changes when the user types something new in the input bar.'); + } + + function draw() { + background(200); + + // Use the input to display a message. + let msg = myInput.value(); + text(msg, 25, 55); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createInput diff --git a/src/content/reference/en/p5/createNumberDict.mdx b/src/content/reference/en/p5/createNumberDict.mdx new file mode 100644 index 0000000000..c4b8794760 --- /dev/null +++ b/src/content/reference/en/p5/createNumberDict.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createNumberDict +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: > +

Creates a new instance of p5.NumberDict using + the key-value pair + or object you provide.

+line: 48 +itemtype: method +class: p5 +example: + - |2- + +
+ + function setup() { + let myDictionary = createNumberDict(100, 42); + print(myDictionary.hasKey(100)); // logs true to console + let anotherDictionary = createNumberDict({ 200: 84 }); + print(anotherDictionary.hasKey(200)); // logs true to console + } +
+return: + description: '' + type: p5.NumberDict +chainable: false +--- + + +# createNumberDict diff --git a/src/content/reference/en/p5/createP.mdx b/src/content/reference/en/p5/createP.mdx new file mode 100644 index 0000000000..5fde80241d --- /dev/null +++ b/src/content/reference/en/p5/createP.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createP +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <p></p> element. It's commonly used for + + paragraph-length text.

+ +

The parameter html is optional. It accepts a string that sets + the + + inner HTML of the new <p></p>.

+line: 488 +params: + - name: html + description: | +

inner HTML for the new <p></p> element.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + let p = createP('Tell me a story.'); + p.position(5, 0); + + describe('A gray square displaying the text "Tell me a story." written in black.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createP diff --git a/src/content/reference/en/p5/createRadio.mdx b/src/content/reference/en/p5/createRadio.mdx new file mode 100644 index 0000000000..38002506f4 --- /dev/null +++ b/src/content/reference/en/p5/createRadio.mdx @@ -0,0 +1,168 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createRadio +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a radio button element.

+ +

The parameter is optional. If a string is passed, as in + + let myRadio = createSelect('food'), then each radio option will + + have "food" as its name parameter: <input + name="food"></input>. + + If an existing <div></div> or + <span></span> + + element is passed, as in let myRadio = createSelect(container), + it will + + become the radio button's parent element.

+ +

Radio buttons extend the p5.Element class with a + few + + helpful methods for managing options:

+ + +line: 1323 +itemtype: method +class: p5 +example: + - |- + +
+ + let myRadio; + + function setup() { + // Create a radio button element and place it + // in the top-left corner. + myRadio = createRadio(); + myRadio.position(0, 0); + myRadio.size(60); + + // Add a few color options. + myRadio.option('red'); + myRadio.option('yellow'); + myRadio.option('blue'); + + // Choose a default option. + myRadio.selected('yellow'); + + describe('A yellow square with three color options listed, "red", "yellow", and "blue". The square changes color when the user selects a new option.'); + } + + function draw() { + // Set the background color using the radio button. + let g = myRadio.value(); + background(g); + } + +
+ +
+ + let myRadio; + + function setup() { + // Create a radio button element and place it + // in the top-left corner. + myRadio = createRadio(); + myRadio.position(0, 0); + myRadio.size(50); + + // Add a few color options. + // Color values are labeled with + // emotions they evoke. + myRadio.option('red', 'love'); + myRadio.option('yellow', 'joy'); + myRadio.option('blue', 'trust'); + + // Choose a default option. + myRadio.selected('yellow'); + + describe('A yellow square with three options listed, "love", "joy", and "trust". The square changes color when the user selects a new option.'); + } + + function draw() { + // Set the background color using the radio button. + let c = myRadio.value(); + background(c); + } + +
+ +
+ + let myRadio; + + function setup() { + // Create a radio button element and place it + // in the top-left corner. + myRadio = createRadio(); + myRadio.position(0, 0); + myRadio.size(50); + + // Add a few color options. + myRadio.option('red'); + myRadio.option('yellow'); + myRadio.option('blue'); + + // Choose a default option. + myRadio.selected('yellow'); + + // Create a button and place it beneath the canvas. + let btn = createButton('disable'); + btn.position(0, 100); + + // Use the button to disable the radio button. + btn.mousePressed(() => { + myRadio.disable(true); + }); + + describe('A yellow square with three options listed, "red", "yellow", and "blue". The square changes color when the user selects a new option. A "disable" button beneath the canvas disables the color options when pressed.'); + } + + function draw() { + // Set the background color using the radio button. + let c = myRadio.value(); + background(c); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createRadio diff --git a/src/content/reference/en/p5/createSelect.mdx b/src/content/reference/en/p5/createSelect.mdx new file mode 100644 index 0000000000..4104604980 --- /dev/null +++ b/src/content/reference/en/p5/createSelect.mdx @@ -0,0 +1,196 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createSelect +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a dropdown menu <select></select> + element.

+ +

The parameter is optional. If true is passed, as in + + let mySelect = createSelect(true), then the dropdown will support + + multiple selections. If an existing <select></select> + element + + is passed, as in let mySelect = createSelect(otherSelect), the + existing + + element will be wrapped in a new p5.Element + + object.

+ +

Dropdowns extend the p5.Element class with a few + + helpful methods for managing options:

+ + +line: 1057 +itemtype: method +class: p5 +example: + - |- + +
+ + let mySelect; + + function setup() { + // Create a dropdown and place it beneath the canvas. + mySelect = createSelect(); + mySelect.position(0, 100); + + // Add color options. + mySelect.option('red'); + mySelect.option('green'); + mySelect.option('blue'); + mySelect.option('yellow'); + + // Set the selected option to "red". + mySelect.selected('red'); + + describe('A red square with a dropdown menu beneath it. The square changes color when a new color is selected.'); + } + + function draw() { + // Use the selected value to paint the background. + let c = mySelect.selected(); + background(c); + } + +
+ +
+ + let mySelect; + + function setup() { + // Create a dropdown and place it beneath the canvas. + mySelect = createSelect(); + mySelect.position(0, 100); + + // Add color options. + mySelect.option('red'); + mySelect.option('green'); + mySelect.option('blue'); + mySelect.option('yellow'); + + // Set the selected option to "red". + mySelect.selected('red'); + + // Disable the "yellow" option. + mySelect.disable('yellow'); + + describe('A red square with a dropdown menu beneath it. The square changes color when a new color is selected.'); + } + + function draw() { + // Use the selected value to paint the background. + let c = mySelect.selected(); + background(c); + } + +
+ +
+ + let mySelect; + + function setup() { + // Create a dropdown and place it beneath the canvas. + mySelect = createSelect(); + mySelect.position(0, 100); + + // Add color options with names and values. + mySelect.option('one', 'red'); + mySelect.option('two', 'green'); + mySelect.option('three', 'blue'); + mySelect.option('four', 'yellow'); + + // Set the selected option to "one". + mySelect.selected('one'); + + describe('A red square with a dropdown menu beneath it. The square changes color when a new color is selected.'); + } + + function draw() { + // Use the selected value to paint the background. + let c = mySelect.selected(); + background(c); + } + +
+ +
+ + // Hold CTRL to select multiple options on Windows and Linux. + // Hold CMD to select multiple options on macOS. + let mySelect; + + function setup() { + // Create a dropdown and allow multiple selections. + // Place it beneath the canvas. + mySelect = createSelect(true); + mySelect.position(0, 100); + + // Add color options. + mySelect.option('red'); + mySelect.option('green'); + mySelect.option('blue'); + mySelect.option('yellow'); + + describe('A gray square with a dropdown menu beneath it. Colorful circles appear when their color is selected.'); + } + + function draw() { + background(200); + + // Use the selected value(s) to draw circles. + let colors = mySelect.selected(); + colors.forEach((c, index) => { + let x = 10 + index * 20; + fill(c); + circle(x, 50, 20); + }); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createSelect diff --git a/src/content/reference/en/p5/createShader.mdx b/src/content/reference/en/p5/createShader.mdx new file mode 100644 index 0000000000..ded7b83e43 --- /dev/null +++ b/src/content/reference/en/p5/createShader.mdx @@ -0,0 +1,105 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createShader +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Creates a new p5.Shader object + + from the provided vertex and fragment shader code.

+ +

Note, shaders can only be used in WEBGL mode.

+ +

Shaders can alter the positioning of shapes drawn with them. + + To ensure consistency in rendering, it's recommended to use the vertex shader + shown in the example below.

+line: 115 +params: + - name: vertSrc + description: | +

source code for the vertex shader

+ type: String + - name: fragSrc + description: | +

source code for the fragment shader

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + + // the vertex shader is called for each vertex + let vs = ` + precision highp float; + uniform mat4 uModelViewMatrix; + uniform mat4 uProjectionMatrix; + + attribute vec3 aPosition; + attribute vec2 aTexCoord; + varying vec2 vTexCoord; + + void main() { + vTexCoord = aTexCoord; + vec4 positionVec4 = vec4(aPosition, 1.0); + gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4; + } + `; + + + // the fragment shader is called for each pixel + let fs = ` + precision highp float; + uniform vec2 p; + uniform float r; + const int I = 500; + varying vec2 vTexCoord; + void main() { + vec2 c = p + gl_FragCoord.xy * r, z = c; + float n = 0.0; + for (int i = I; i > 0; i --) { + if(z.x*z.x+z.y*z.y > 4.0) { + n = float(i)/float(I); + break; + } + z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c; + } + gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0); + }`; + + let mandel; + function setup() { + createCanvas(100, 100, WEBGL); + + // create and initialize the shader + mandel = createShader(vs, fs); + shader(mandel); + noStroke(); + + // 'p' is the center point of the Mandelbrot image + mandel.setUniform('p', [-0.74364388703, 0.13182590421]); + describe('zooming Mandelbrot set. a colorful, infinitely detailed fractal.'); + } + + function draw() { + // 'r' is the size of the image in Mandelbrot-space + mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); + plane(width, height); + } + +
+alt: 'zooming Mandelbrot set. a colorful, infinitely detailed fractal.' +return: + description: |- + a shader object created from the provided + vertex and fragment shaders. + type: p5.Shader +chainable: false +--- + + +# createShader diff --git a/src/content/reference/en/p5/createSlider.mdx b/src/content/reference/en/p5/createSlider.mdx new file mode 100644 index 0000000000..3c13153b91 --- /dev/null +++ b/src/content/reference/en/p5/createSlider.mdx @@ -0,0 +1,151 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createSlider +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a slider <input></input> element. Range + sliders are + + useful for quickly selecting numbers from a given range.

+ +

The first two parameters, min and max, are + numbers that set the + + slider's minimum and maximum.

+ +

The third parameter, value, is optional. It's a number that + sets the + + slider's default value.

+ +

The fourth parameter, step, is also optional. It's a number + that sets the + + spacing between each value in the slider's range. Setting step to + 0 + + allows the slider to move smoothly from min to + max.

+line: 717 +params: + - name: min + description: | +

minimum value of the slider.

+ type: Number + - name: max + description: | +

maximum value of the slider.

+ type: Number + - name: value + description: | +

default value of the slider.

+ type: Number + optional: true + - name: step + description: | +

size for each step in the slider's range.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let slider; + + function setup() { + // Create a slider and place it at the top of the canvas. + slider = createSlider(0, 255); + slider.position(10, 10); + slider.size(80); + + describe('A dark gray square with a range slider at the top. The square changes color when the slider is moved.'); + } + + function draw() { + // Use the slider as a grayscale value. + let g = slider.value(); + background(g); + } + +
+ +
+ + let slider; + + function setup() { + // Create a slider and place it at the top of the canvas. + // Set its default value to 0. + slider = createSlider(0, 255, 0); + slider.position(10, 10); + slider.size(80); + + describe('A black square with a range slider at the top. The square changes color when the slider is moved.'); + } + + function draw() { + // Use the slider as a grayscale value. + let g = slider.value(); + background(g); + } + +
+ +
+ + let slider; + + function setup() { + // Create a slider and place it at the top of the canvas. + // Set its default value to 0. + // Set its step size to 50. + slider = createSlider(0, 255, 0, 50); + slider.position(10, 10); + slider.size(80); + + describe('A black square with a range slider at the top. The square changes color when the slider is moved.'); + } + + function draw() { + // Use the slider as a grayscale value. + let g = slider.value(); + background(g); + } + +
+ +
+ + let slider; + + function setup() { + // Create a slider and place it at the top of the canvas. + // Set its default value to 0. + // Set its step size to 0 so that it moves smoothly. + slider = createSlider(0, 255, 0, 0); + slider.position(10, 10); + slider.size(80); + + describe('A black square with a range slider at the top. The square changes color when the slider is moved.'); + } + + function draw() { + // Use the slider as a grayscale value. + let g = slider.value(); + background(g); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createSlider diff --git a/src/content/reference/en/p5/createSpan.mdx b/src/content/reference/en/p5/createSpan.mdx new file mode 100644 index 0000000000..6cc1a1a91f --- /dev/null +++ b/src/content/reference/en/p5/createSpan.mdx @@ -0,0 +1,87 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createSpan +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <span></span> element. It's commonly + used as a + + container for inline elements. For example, a + <span></span> + + can hold part of a sentence that's a + + different style.

+ +

The parameter html is optional. It accepts a string that sets + the + + inner HTML of the new <span></span>.

+line: 518 +params: + - name: html + description: > +

inner HTML for the new <span></span> + element.

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create a span element. + let span = createSpan('p5*js'); + span.position(25, 35); + + describe('A gray square with the text "p5*js" written in its center.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create a div element as + // a container. + let div = createDiv(); + // Place the div at the + // center. + div.position(25, 35); + + // Create a span element. + let s1 = createSpan('p5'); + // Create a second span element. + let s2 = createSpan('*'); + // Set the span's font color. + s2.style('color', 'deeppink'); + // Create a third span element. + let s3 = createSpan('js'); + + // Add all the spans to the + // container div. + s1.parent(div); + s2.parent(div); + s3.parent(div); + + describe('A gray square with the text "p5*js" written in black at its center. The asterisk is pink.'); + } + +
+return: + description: new p5.Element object. + type: p5.Element +chainable: false +--- + + +# createSpan diff --git a/src/content/reference/en/p5/createStringDict.mdx b/src/content/reference/en/p5/createStringDict.mdx new file mode 100644 index 0000000000..d6f519ffde --- /dev/null +++ b/src/content/reference/en/p5/createStringDict.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createStringDict +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Creates a new instance of p5.StringDict using the key-value pair + or the object you provide.

+line: 14 +itemtype: method +class: p5 +example: + - |2- + +
+ + function setup() { + let myDictionary = createStringDict('p5', 'js'); + print(myDictionary.hasKey('p5')); // logs true to console + let anotherDictionary = createStringDict({ happy: 'coding' }); + print(anotherDictionary.hasKey('happy')); // logs true to console + } +
+return: + description: '' + type: p5.StringDict +chainable: false +--- + + +# createStringDict diff --git a/src/content/reference/en/p5/createVector.mdx b/src/content/reference/en/p5/createVector.mdx new file mode 100644 index 0000000000..7a57bffdbb --- /dev/null +++ b/src/content/reference/en/p5/createVector.mdx @@ -0,0 +1,125 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createVector +module: Math +submodule: Vector +file: src/math/math.js +description: > +

Creates a new p5.Vector object. A vector is like + + an arrow pointing in space. Vectors have both magnitude (length) + + and direction. Calling createVector() without arguments sets the + new + + vector's components to 0.

+ +

p5.Vector objects are often used to program + + motion because they simplify the math. For example, a moving ball has a + + position and a velocity. Position describes where the ball is in space. The + + ball's position vector extends from the origin to the ball's center. + + Velocity describes the ball's speed and the direction it's moving. If the + + ball is moving straight up, its velocity vector points straight up. Adding + + the ball's velocity vector to its position vector moves it, as in + + pos.add(vel). Vector math relies on methods inside the + + p5.Vector class.

+line: 10 +params: + - name: x + description: | +

x component of the vector.

+ type: Number + optional: true + - name: 'y' + description: | +

y component of the vector.

+ type: Number + optional: true + - name: z + description: | +

z component of the vector.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - >- + +
+ + + + let p1 = createVector(25, 25); + + let p2 = createVector(50, 50); + + let p3 = createVector(75, 75); + + + strokeWeight(5); + + point(p1); + + point(p2); + + point(p3); + + + describe('Three black dots form a diagonal line from top left to bottom + right.'); + + + +
+ + +
+ + + + let pos; + + let vel; + + + function setup() { + createCanvas(100, 100); + pos = createVector(width / 2, height); + vel = createVector(0, -1); + } + + + function draw() { + background(200); + + pos.add(vel); + + if (pos.y < 0) { + pos.y = height; + } + + strokeWeight(5); + point(pos); + + describe('A black dot moves from bottom to top on a gray square. The dot reappears at the bottom when it reaches the top.'); + } + + + +
+return: + description: new p5.Vector object. + type: p5.Vector +chainable: false +--- + + +# createVector diff --git a/src/content/reference/en/p5/createVideo.mdx b/src/content/reference/en/p5/createVideo.mdx new file mode 100644 index 0000000000..4a55f73579 --- /dev/null +++ b/src/content/reference/en/p5/createVideo.mdx @@ -0,0 +1,127 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createVideo +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Creates a <video> element for simple audio/video + playback. + + Returns a new p5.MediaElement object.

+ +

Videos are shown by default. They can be hidden by calling + video.hide() + + and drawn to the canvas using image().

+ +

The first parameter, src, is the path the video. If a single + string is + + passed, as in 'assets/topsecret.mp4', a single video is loaded. + An array + + of strings can be used to load the same video in different formats. For + + example, ['assets/topsecret.mp4', 'assets/topsecret.ogv', + 'assets/topsecret.webm']. + + This is useful for ensuring that the video can play across different browsers + with + + different capabilities. See + + MDN + + for more information about supported formats.

+ +

The second parameter, callback, is optional. It's a function + to call once + + the video is ready to play.

+line: 1950 +params: + - name: src + description: | +

path to a video file, or an array of paths for + supporting different browsers.

+ type: 'String|String[]' + - name: callback + description: | +

function to call once the video is ready to play.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + noCanvas(); + + // Load a video and add it to the page. + // Note: this may not work in some browsers. + let video = createVideo('assets/small.mp4'); + // Show the default video controls. + video.showControls(); + + describe('A video of a toy robot with playback controls beneath it.'); + } + +
+ +
+ + function setup() { + noCanvas(); + + // Load a video and add it to the page. + // Provide an array options for different file formats. + let video = createVideo( + ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'] + ); + // Show the default video controls. + video.showControls(); + + describe('A video of a toy robot with playback controls beneath it.'); + } + +
+ +
+ + let video; + + function setup() { + noCanvas(); + + // Load a video and add it to the page. + // Provide an array options for different file formats. + // Call mute() once the video loads. + video = createVideo( + ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'], + muteVideo + ); + // Show the default video controls. + video.showControls(); + + describe('A video of a toy robot with playback controls beneath it.'); + } + + // Mute the video once it loads. + function muteVideo() { + video.volume(0); + } + +
+return: + description: new p5.MediaElement object. + type: p5.MediaElement +chainable: false +--- + + +# createVideo diff --git a/src/content/reference/en/p5/createWriter.mdx b/src/content/reference/en/p5/createWriter.mdx new file mode 100644 index 0000000000..5d7b6cd766 --- /dev/null +++ b/src/content/reference/en/p5/createWriter.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: createWriter +module: IO +submodule: Output +file: src/io/files.js +description: '' +line: 1143 +params: + - name: name + description: | +

name of the file to be created

+ type: String + - name: extension + description: '' + type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + text('click here to save', 10, 10, 70, 80); + } + + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + const writer = createWriter('squares.txt'); + for (let i = 0; i < 10; i++) { + writer.print(i * i); + } + writer.close(); + writer.clear(); + } + } + +
+return: + description: '' + type: p5.PrintWriter +chainable: false +--- + + +# createWriter diff --git a/src/content/reference/en/p5/cursor.mdx b/src/content/reference/en/p5/cursor.mdx new file mode 100644 index 0000000000..1fa779c08b --- /dev/null +++ b/src/content/reference/en/p5/cursor.mdx @@ -0,0 +1,124 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: cursor +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Changes the cursor's appearance.

+ +

The first parameter, type, sets the type of cursor to display. + The + + built-in options are ARROW, CROSS, + HAND, MOVE, TEXT, and + WAIT. + + cursor() also recognizes standard CSS cursor properties passed as + + strings: 'help', 'wait', 'crosshair', + 'not-allowed', 'zoom-in', + + and 'grab'. If the path to an image is passed, as in + + cursor('assets/target.png'), then the image will be used as the + cursor. + + Images must be in .cur, .gif, .jpg, .jpeg, or .png format and should be at + most 32 by 32 pixels large.

+ +

The parameters x and y are optional. If an image + is used for the + + cursor, x and y set the location pointed to within + the image. They are + + both 0 by default, so the cursor points to the image's top-left corner. + x + + and y must be less than the image's width and height, + respectively.

+line: 193 +params: + - name: type + description: | +

Built-in: either ARROW, CROSS, HAND, MOVE, TEXT, or WAIT. + Native CSS properties: 'grab', 'progress', and so on. + Path to cursor image.

+ type: String|Constant + - name: x + description: | +

horizontal active spot of the cursor.

+ type: Number + optional: true + - name: 'y' + description: | +

vertical active spot of the cursor.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + // Set the cursor to crosshairs: + + cursor(CROSS); + + describe('A gray square. The cursor appears as crosshairs.'); + } + +
+ +
+ + function draw() { + background(200); + + // Divide the canvas into quadrants. + line(50, 0, 50, 100); + line(0, 50, 100, 50); + + // Change cursor based on mouse position. + if (mouseX < 50 && mouseY < 50) { + cursor(CROSS); + } else if (mouseX > 50 && mouseY < 50) { + cursor('progress'); + } else if (mouseX > 50 && mouseY > 50) { + cursor('https://avatars0.githubusercontent.com/u/1617169?s=16'); + } else { + cursor('grab'); + } + + describe('A gray square divided into quadrants. The cursor image changes when the mouse moves to each quadrant.'); + } + +
+ +
+ + function draw() { + background(200); + + // Change the cursor's active spot + // when the mouse is pressed. + if (mouseIsPressed === true) { + cursor('https://avatars0.githubusercontent.com/u/1617169?s=16', 8, 8); + } else { + cursor('https://avatars0.githubusercontent.com/u/1617169?s=16'); + } + + describe('An image of three purple curves follows the mouse. The image shifts when the mouse is pressed.'); + } + +
+chainable: false +--- + + +# cursor diff --git a/src/content/reference/en/p5/curve.mdx b/src/content/reference/en/p5/curve.mdx new file mode 100644 index 0000000000..f356c11b35 --- /dev/null +++ b/src/content/reference/en/p5/curve.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: CURVE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 653 +itemtype: property +class: p5 +chainable: false +--- + + +# CURVE diff --git a/src/content/reference/en/p5/curveDetail.mdx b/src/content/reference/en/p5/curveDetail.mdx new file mode 100644 index 0000000000..5b5a7ddb99 --- /dev/null +++ b/src/content/reference/en/p5/curveDetail.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: curveDetail +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: | +

Sets the resolution at which curves display. The default value is 20 while + the minimum value is 3.

+

This function is only useful when using the WEBGL renderer + as the default canvas renderer does not use this + information.

+line: 359 +params: + - name: resolution + description: | +

resolution of the curves

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + + curveDetail(5); + } + function draw() { + background(200); + + curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0); + } + +
+alt: white arch shape with a low level of curve detail. +chainable: true +--- + + +# curveDetail diff --git a/src/content/reference/en/p5/curvePoint.mdx b/src/content/reference/en/p5/curvePoint.mdx new file mode 100644 index 0000000000..e8b7b33838 --- /dev/null +++ b/src/content/reference/en/p5/curvePoint.mdx @@ -0,0 +1,68 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: curvePoint +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: | +

Evaluates the curve at position t for points a, b, c, d. + The parameter t varies between 0 and 1, a and d are control points + of the curve, and b and c are the start and end points of the curve. + This can be done once with the x coordinates and a second time + with the y coordinates to get the location of a curve at t.

+line: 445 +params: + - name: a + description: | +

coordinate of first control point of the curve

+ type: Number + - name: b + description: | +

coordinate of first point

+ type: Number + - name: c + description: | +

coordinate of second point

+ type: Number + - name: d + description: | +

coordinate of second control point

+ type: Number + - name: t + description: | +

value between 0 and 1

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + curve(5, 26, 5, 26, 73, 24, 73, 61); + curve(5, 26, 73, 24, 73, 61, 15, 65); + fill(255); + ellipseMode(CENTER); + let steps = 6; + for (let i = 0; i <= steps; i++) { + let t = i / steps; + let x = curvePoint(5, 5, 73, 73, t); + let y = curvePoint(26, 26, 24, 61, t); + ellipse(x, y, 5, 5); + x = curvePoint(5, 73, 73, 15, t); + y = curvePoint(26, 24, 61, 65, t); + ellipse(x, y, 5, 5); + } + +
+ + line hooking down to right-bottom with 13 5×5 white ellipse points +return: + description: Curve value at position t + type: Number +chainable: false +--- + + +# curvePoint diff --git a/src/content/reference/en/p5/curveTangent.mdx b/src/content/reference/en/p5/curveTangent.mdx new file mode 100644 index 0000000000..9afbd2b83c --- /dev/null +++ b/src/content/reference/en/p5/curveTangent.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: curveTangent +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: | +

Evaluates the tangent to the curve at position t for points a, b, c, d. + The parameter t varies between 0 and 1, a and d are points on the curve, + and b and c are the control points.

+line: 494 +params: + - name: a + description: | +

coordinate of first control point

+ type: Number + - name: b + description: | +

coordinate of first point on the curve

+ type: Number + - name: c + description: | +

coordinate of second point on the curve

+ type: Number + - name: d + description: | +

coordinate of second conrol point

+ type: Number + - name: t + description: | +

value between 0 and 1

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + curve(5, 26, 73, 24, 73, 61, 15, 65); + let steps = 6; + for (let i = 0; i <= steps; i++) { + let t = i / steps; + let x = curvePoint(5, 73, 73, 15, t); + let y = curvePoint(26, 24, 61, 65, t); + //ellipse(x, y, 5, 5); + let tx = curveTangent(5, 73, 73, 15, t); + let ty = curveTangent(26, 24, 61, 65, t); + let a = atan2(ty, tx); + a -= PI / 2.0; + line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); + } + +
+alt: right curving line mid-right of canvas with 7 short lines radiating from it. +return: + description: the tangent at position t + type: Number +chainable: false +--- + + +# curveTangent diff --git a/src/content/reference/en/p5/curveTightness.mdx b/src/content/reference/en/p5/curveTightness.mdx new file mode 100644 index 0000000000..feb393b22b --- /dev/null +++ b/src/content/reference/en/p5/curveTightness.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: curveTightness +module: Shape +submodule: Curves +file: src/core/shape/curves.js +description: > +

Modifies the quality of forms created with curve() + + and curveVertex().The parameter tightness + + determines how the curve fits to the vertex points. The value 0.0 is the + + default value for tightness (this value defines the curves to be Catmull-Rom + + splines) and the value 1.0 connects all the points with straight lines. + + Values within the range -5.0 and 5.0 will deform the curves but will leave + + them recognizable and as values increase in magnitude, they will continue to + deform.

+line: 399 +params: + - name: amount + description: | +

amount of deformation from the original vertices

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + // Move the mouse left and right to see the curve change + function setup() { + createCanvas(100, 100); + noFill(); + } + + function draw() { + background(204); + let t = map(mouseX, 0, width, -5, 5); + curveTightness(t); + beginShape(); + curveVertex(10, 26); + curveVertex(10, 26); + curveVertex(83, 24); + curveVertex(83, 61); + curveVertex(25, 65); + curveVertex(25, 65); + endShape(); + } + +
+alt: 'Line shaped like right-facing arrow,points move with mouse-x and warp shape.' +chainable: true +--- + + +# curveTightness diff --git a/src/content/reference/en/p5/curveVertex.mdx b/src/content/reference/en/p5/curveVertex.mdx new file mode 100644 index 0000000000..7715979210 --- /dev/null +++ b/src/content/reference/en/p5/curveVertex.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: curveVertex +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Specifies vertex coordinates for curves. This function may only + + be used between beginShape() and endShape() and only when there + + is no MODE parameter specified to beginShape(). + + For WebGL mode curveVertex() can be used in 2D as well as 3D mode. + + 2D mode expects 2 parameters, while 3D mode expects 3 parameters.

+ +

The first and last points in a series of curveVertex() lines will be used + to + + guide the beginning and end of the curve. A minimum of four + + points is required to draw a tiny curve between the second and + + third points. Adding a fifth point with curveVertex() will draw + + the curve between the second, third, and fourth points. The + + curveVertex() function is an implementation of Catmull-Rom + + splines.

+line: 419 +itemtype: method +class: p5 +example: + - |- + +
+ + strokeWeight(5); + point(84, 91); + point(68, 19); + point(21, 17); + point(32, 91); + strokeWeight(1); + + noFill(); + beginShape(); + curveVertex(84, 91); + curveVertex(84, 91); + curveVertex(68, 19); + curveVertex(21, 17); + curveVertex(32, 91); + curveVertex(32, 91); + endShape(); + +
+alt: 'Upside-down u-shape line, mid canvas. left point extends beyond canvas view.' +chainable: true +--- + + +# curveVertex diff --git a/src/content/reference/en/p5/cylinder.mdx b/src/content/reference/en/p5/cylinder.mdx new file mode 100644 index 0000000000..6c71f33b10 --- /dev/null +++ b/src/content/reference/en/p5/cylinder.mdx @@ -0,0 +1,125 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: cylinder +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Draw a cylinder with given radius and height

+ +

DetailX and detailY determines the number of subdivisions in the + x-dimension + + and the y-dimension of a cylinder. More subdivisions make the cylinder seem + smoother. + + The recommended maximum value for detailX is 24. Using a value greater than 24 + + may cause a warning or slow down the browser.

+line: 600 +params: + - name: radius + description: | +

radius of the surface

+ type: Number + optional: true + - name: height + description: | +

height of the cylinder

+ type: Number + optional: true + - name: detailX + description: | +

number of subdivisions in x-dimension; + default is 24

+ type: Integer + optional: true + - name: detailY + description: | +

number of subdivisions in y-dimension; + default is 1

+ type: Integer + optional: true + - name: bottomCap + description: | +

whether to draw the bottom of the cylinder

+ type: Boolean + optional: true + - name: topCap + description: | +

whether to draw the top of the cylinder

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a spinning cylinder + // with radius 20 and height 50 + function setup() { + createCanvas(100, 100, WEBGL); + describe('a rotating white cylinder'); + } + + function draw() { + background(205, 105, 94); + rotateX(frameCount * 0.01); + rotateZ(frameCount * 0.01); + cylinder(20, 50); + } + +
+ - |- + +
+ + // slide to see how detailX works + let detailX; + function setup() { + createCanvas(100, 100, WEBGL); + detailX = createSlider(3, 24, 3); + detailX.position(10, height + 5); + detailX.style('width', '80px'); + describe( + 'a rotating white cylinder with limited X detail, with a slider that adjusts detailX' + ); + } + + function draw() { + background(205, 105, 94); + rotateY(millis() / 1000); + cylinder(20, 75, detailX.value(), 1); + } + +
+ - |- + +
+ + // slide to see how detailY works + let detailY; + function setup() { + createCanvas(100, 100, WEBGL); + detailY = createSlider(1, 16, 1); + detailY.position(10, height + 5); + detailY.style('width', '80px'); + describe( + 'a rotating white cylinder with limited Y detail, with a slider that adjusts detailY' + ); + } + + function draw() { + background(205, 105, 94); + rotateY(millis() / 1000); + cylinder(20, 75, 16, detailY.value()); + } + +
+chainable: true +--- + + +# cylinder diff --git a/src/content/reference/en/p5/day.mdx b/src/content/reference/en/p5/day.mdx new file mode 100644 index 0000000000..2741186388 --- /dev/null +++ b/src/content/reference/en/p5/day.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: day +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The day() function + + returns the current day as a value from 1 - 31.

+line: 10 +itemtype: method +class: p5 +example: + - |- + +
+ + let d = day(); + text('Current day: \n' + d, 5, 50); + describe('Current day is displayed'); + +
+return: + description: the current day + type: Integer +chainable: false +--- + + +# day diff --git a/src/content/reference/en/p5/debugMode.mdx b/src/content/reference/en/p5/debugMode.mdx new file mode 100644 index 0000000000..7ca3c95fd4 --- /dev/null +++ b/src/content/reference/en/p5/debugMode.mdx @@ -0,0 +1,162 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: debugMode +module: 3D +submodule: Interaction +file: src/webgl/interaction.js +description: > +

debugMode() helps visualize 3D space by adding a grid to indicate where the + + ‘ground’ is in a sketch and an axes icon which indicates the +X, +Y, and +Z + + directions. This function can be called without parameters to create a + + default grid and axes icon, or it can be called according to the examples + + above to customize the size and position of the grid and/or axes icon. The + + grid is drawn using the most recently set stroke color and weight. To + + specify these parameters, add a call to stroke() and strokeWeight() + + just before the end of the draw() loop.

+ +

By default, the grid will run through the origin (0,0,0) of the sketch + + along the XZ plane + + and the axes icon will be offset from the origin. Both the grid and axes + + icon will be sized according to the current canvas size. Note that because + the + + grid runs parallel to the default camera view, it is often helpful to use + + debugMode along with orbitControl to allow full view of the grid.

+line: 378 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(); + describe( + 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z. the grid and icon disappear when the spacebar is pressed.' + ); + } + + function draw() { + background(200); + orbitControl(); + box(15, 30); + // Press the spacebar to turn debugMode off! + if (keyIsDown(32)) { + noDebugMode(); + } + } + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(GRID); + describe('a 3D box is centered on a grid in a 3D sketch.'); + } + + function draw() { + background(200); + orbitControl(); + box(15, 30); + } + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(AXES); + describe( + 'a 3D box is centered in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z.' + ); + } + + function draw() { + background(200); + orbitControl(); + box(15, 30); + } + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(GRID, 100, 10, 0, 0, 0); + describe('a 3D box is centered on a grid in a 3D sketch'); + } + + function draw() { + background(200); + orbitControl(); + box(15, 30); + } + +
+ - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0); + describe( + 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z.' + ); + } + + function draw() { + noStroke(); + background(200); + orbitControl(); + box(15, 30); + // set the stroke color and weight for the grid! + stroke(255, 0, 150); + strokeWeight(0.8); + } + +
+alt: |- + a 3D box is centered on a grid in a 3D sketch. an icon + indicates the direction of each axis: a red line points +X, + a green line +Y, and a blue line +Z. +chainable: false +--- + + +# debugMode diff --git a/src/content/reference/en/p5/deltaTime.mdx b/src/content/reference/en/p5/deltaTime.mdx new file mode 100644 index 0000000000..0a2e9e0843 --- /dev/null +++ b/src/content/reference/en/p5/deltaTime.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: deltaTime +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Tracks the amount of time, in milliseconds, it took for + + draw to draw the previous frame. + deltaTime is + + useful for simulating physics.

+line: 119 +itemtype: property +class: p5 +example: + - |- + +
+ + let x = 0; + let speed = 0.05; + + function setup() { + // Set the frameRate to 30. + frameRate(30); + } + + function draw() { + background(200); + + // Use deltaTime to calculate + // a change in position. + let deltaX = speed * deltaTime; + + // Update the x variable. + x += deltaX; + + // Reset x to 0 if it's + // greater than 100. + if (x > 100) { + x = 0; + } + + // Use x to set the circle's + // position. + circle(x, 50, 20); + + describe('A white circle moves from left to right on a gray background. It reappears on the left side when it reaches the right side.'); + } + +
+chainable: false +--- + + +# deltaTime diff --git a/src/content/reference/en/p5/describe.mdx b/src/content/reference/en/p5/describe.mdx new file mode 100644 index 0000000000..b83a9624ce --- /dev/null +++ b/src/content/reference/en/p5/describe.mdx @@ -0,0 +1,132 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: describe +module: Environment +submodule: Environment +file: src/accessibility/describe.js +description: > +

Creates a screen reader-accessible description for the canvas.

+ +

The first parameter, text, is the description of the + canvas.

+ +

The second parameter, display, is optional. It determines how + the + + description is displayed. If LABEL is passed, as in + + describe('A description.', LABEL), the description will be + visible in + + a div element next to the canvas. If FALLBACK is passed, as in + + describe('A description.', FALLBACK), the description will only + be + + visible to screen readers. This is the default mode.

+ +

Read + + How to label your p5.js code to + + learn more about making sketches accessible.

+line: 18 +params: + - name: text + description: | +

description of the canvas.

+ type: String + - name: display + description: | +

either LABEL or FALLBACK.

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background('pink'); + + // Draw a heart. + fill('red'); + noStroke(); + circle(67, 67, 20); + circle(83, 67, 20); + triangle(91, 73, 75, 95, 59, 73); + + // Add a general description of the canvas. + describe('A pink square with a red heart in the bottom-right corner.'); + } + +
+ +
+ + function setup() { + background('pink'); + + // Draw a heart. + fill('red'); + noStroke(); + circle(67, 67, 20); + circle(83, 67, 20); + triangle(91, 73, 75, 95, 59, 73); + + // Add a general description of the canvas + // and display it for debugging. + describe('A pink square with a red heart in the bottom-right corner.', LABEL); + } + +
+ +
+ + function draw() { + background(200); + + // The expression + // frameCount % 100 + // causes x to increase from 0 + // to 99, then restart from 0. + let x = frameCount % 100; + + // Draw the circle. + fill(0, 255, 0); + circle(x, 50, 40); + + // Add a general description of the canvas. + describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`); + } + +
+ +
+ + function draw() { + background(200); + + // The expression + // frameCount % 100 + // causes x to increase from 0 + // to 99, then restart from 0. + let x = frameCount % 100; + + // Draw the circle. + fill(0, 255, 0); + circle(x, 50, 40); + + // Add a general description of the canvas + // and display it for debugging. + describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`, LABEL); + } + +
+chainable: false +--- + + +# describe diff --git a/src/content/reference/en/p5/describeElement.mdx b/src/content/reference/en/p5/describeElement.mdx new file mode 100644 index 0000000000..378ab53c4c --- /dev/null +++ b/src/content/reference/en/p5/describeElement.mdx @@ -0,0 +1,119 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: describeElement +module: Environment +submodule: Environment +file: src/accessibility/describe.js +description: > +

Creates a screen reader-accessible description for elements in the canvas. + + Elements are shapes or groups of shapes that create meaning together.

+ +

The first parameter, name, is the name of the element.

+ +

The second parameter, text, is the description of the + element.

+ +

The third parameter, display, is optional. It determines how + the + + description is displayed. If LABEL is passed, as in + + describe('A description.', LABEL), the description will be + visible in + + a div element next to the canvas. Using LABEL creates unhelpful + + duplicates for screen readers. Only use LABEL during development. + If + + FALLBACK is passed, as in describe('A description.', + FALLBACK), the + + description will only be visible to screen readers. This is the default + + mode.

+ +

Read + + How to label your p5.js code to + + learn more about making sketches accessible.

+line: 162 +params: + - name: name + description: | +

name of the element.

+ type: String + - name: text + description: | +

description of the element.

+ type: String + - name: display + description: | +

either LABEL or FALLBACK.

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background('pink'); + + // Describe the first element + // and draw it. + describeElement('Circle', 'A yellow circle in the top-left corner.'); + noStroke(); + fill('yellow'); + circle(25, 25, 40); + + // Describe the second element + // and draw it. + describeElement('Heart', 'A red heart in the bottom-right corner.'); + fill('red'); + circle(66.6, 66.6, 20); + circle(83.2, 66.6, 20); + triangle(91.2, 72.6, 75, 95, 58.6, 72.6); + + // Add a general description of the canvas. + describe('A red heart and yellow circle over a pink background.'); + } + +
+ +
+ + function setup() { + background('pink'); + + // Describe the first element + // and draw it. Display the + // description for debugging. + describeElement('Circle', 'A yellow circle in the top-left corner.', LABEL); + noStroke(); + fill('yellow'); + circle(25, 25, 40); + + // Describe the second element + // and draw it. Display the + // description for debugging. + describeElement('Heart', 'A red heart in the bottom-right corner.', LABEL); + fill('red'); + circle(66.6, 66.6, 20); + circle(83.2, 66.6, 20); + triangle(91.2, 72.6, 75, 95, 58.6, 72.6); + + // Add a general description of the canvas. + describe('A red heart and yellow circle over a pink background.'); + } + +
+chainable: false +--- + + +# describeElement diff --git a/src/content/reference/en/p5/deviceMoved.mdx b/src/content/reference/en/p5/deviceMoved.mdx new file mode 100644 index 0000000000..5108b0c321 --- /dev/null +++ b/src/content/reference/en/p5/deviceMoved.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: deviceMoved +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The deviceMoved() function is called when + the device is moved by more than + + the threshold value along X, Y or Z axis. The default threshold is set to 0.5. + + The threshold value can be changed using setMoveThreshold().

+line: 501 +itemtype: method +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // Move the device around + // to change the value. + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device moves`); + } + function deviceMoved() { + value = value + 5; + if (value > 255) { + value = 0; + } + } + +
+chainable: false +--- + + +# deviceMoved diff --git a/src/content/reference/en/p5/deviceOrientation.mdx b/src/content/reference/en/p5/deviceOrientation.mdx new file mode 100644 index 0000000000..7754d8b3f5 --- /dev/null +++ b/src/content/reference/en/p5/deviceOrientation.mdx @@ -0,0 +1,19 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: deviceOrientation +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable deviceOrientation always contains the orientation of + the device. The value of this variable will either be set 'landscape' + or 'portrait'. If no data is available it will be set to 'undefined'. + either LANDSCAPE or PORTRAIT.

+line: 11 +itemtype: property +class: p5 +chainable: false +--- + + +# deviceOrientation diff --git a/src/content/reference/en/p5/deviceShaken.mdx b/src/content/reference/en/p5/deviceShaken.mdx new file mode 100644 index 0000000000..781e968586 --- /dev/null +++ b/src/content/reference/en/p5/deviceShaken.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: deviceShaken +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The deviceShaken() function is called when + the device total acceleration + + changes of accelerationX and accelerationY values is more than + + the threshold value. The default threshold is set to 30. + + The threshold value can be changed using setShakeThreshold().

+line: 589 +itemtype: method +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // Shake the device to change the value. + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device shakes`); + } + function deviceShaken() { + value = value + 5; + if (value > 255) { + value = 0; + } + } + +
+chainable: false +--- + + +# deviceShaken diff --git a/src/content/reference/en/p5/deviceTurned.mdx b/src/content/reference/en/p5/deviceTurned.mdx new file mode 100644 index 0000000000..fdf4dd4348 --- /dev/null +++ b/src/content/reference/en/p5/deviceTurned.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: deviceTurned +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The deviceTurned() function is called when + the device rotates by + + more than 90 degrees continuously.

+ +

The axis that triggers the deviceTurned() + method is stored in the turnAxis + + variable. The deviceTurned() method can be + locked to trigger on any axis: + + X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.

+line: 531 +itemtype: method +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // Rotate the device by 90 degrees + // to change the value. + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device turns`); + } + function deviceTurned() { + if (value === 0) { + value = 255; + } else if (value === 255) { + value = 0; + } + } + +
+
+ + // Run this example on a mobile device + // Rotate the device by 90 degrees in the + // X-axis to change the value. + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when x-axis turns`); + } + function deviceTurned() { + if (turnAxis === 'X') { + if (value === 0) { + value = 255; + } else if (value === 255) { + value = 0; + } + } + } + +
+chainable: false +--- + + +# deviceTurned diff --git a/src/content/reference/en/p5/directionalLight.mdx b/src/content/reference/en/p5/directionalLight.mdx new file mode 100644 index 0000000000..0db9fa02a7 --- /dev/null +++ b/src/content/reference/en/p5/directionalLight.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: directionalLight +module: 3D +submodule: Lights +file: src/webgl/light.js +description: > +

Creates a directional light with the given color and direction.

+ +

Directional light comes from one direction. + + The direction is specified as numbers inclusively between -1 and 1. + + For example, setting the direction as (0, -1, 0) will cause the + + geometry to be lit from below (since the light will be facing + + directly upwards). Similarly, setting the direction as (1, 0, 0) + + will cause the geometry to be lit from the left (since the light + + will be facing directly rightwards).

+ +

Directional lights do not have a specific point of origin, and + + therefore cannot be positioned closer or farther away from a geometry.

+ +

A maximum of 5 directional lights can be active at + once.

+ +

Note: lights need to be called (whether directly or indirectly) + + within draw() to remain persistent in a looping program. + + Placing them in setup() will cause them to only have an effect + + the first time through the loop.

+line: 246 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe( + 'scene with sphere and directional light. The direction of the light is controlled with the mouse position.' + ); + } + function draw() { + background(0); + //move your mouse to change light direction + let dirX = (mouseX / width - 0.5) * 2; + let dirY = (mouseY / height - 0.5) * 2; + directionalLight(250, 250, 250, -dirX, -dirY, -1); + noStroke(); + sphere(40); + } + +
+alt: |- + scene with sphere and directional light. The direction of + the light is controlled with the mouse position. +chainable: true +--- + + +# directionalLight diff --git a/src/content/reference/en/p5/disableFriendlyErrors.mdx b/src/content/reference/en/p5/disableFriendlyErrors.mdx new file mode 100644 index 0000000000..ff8c03441e --- /dev/null +++ b/src/content/reference/en/p5/disableFriendlyErrors.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: disableFriendlyErrors +module: Structure +submodule: Structure +file: src/core/main.js +description: > +

Turn off some features of the friendly error system (FES), which can give + + a significant boost to performance when needed.

+ +

Note that this will disable the parts of the FES that cause performance + + slowdown (like argument checking). Friendly errors that have no performance + + cost (like giving a descriptive error if a file load fails, or warning you + + if you try to override p5.js functions in the global space), + + will remain in place.

+ +

See + + disabling the friendly error system.

+line: 750 +itemtype: property +class: p5 +example: + - |- + +
+ p5.disableFriendlyErrors = true; + + function setup() { + createCanvas(100, 50); + } +
+chainable: false +--- + + +# disableFriendlyErrors diff --git a/src/content/reference/en/p5/displayDensity.mdx b/src/content/reference/en/p5/displayDensity.mdx new file mode 100644 index 0000000000..6b1fcfcaaa --- /dev/null +++ b/src/content/reference/en/p5/displayDensity.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: displayDensity +module: Environment +submodule: Environment +file: src/core/environment.js +description: | +

Returns the display's current pixel density.

+line: 1010 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Set the pixel density to 1. + pixelDensity(1); + + // Create a canvas and draw + // a circle. + createCanvas(100, 100); + background(200); + circle(50, 50, 70); + + describe('A fuzzy white circle drawn on a gray background. The circle becomes sharper when the mouse is pressed.'); + } + + function mousePressed() { + // Get the current display density. + let d = displayDensity(); + + // Use the display density to set + // the sketch's pixel density. + pixelDensity(d); + + // Paint the background and + // draw a circle. + background(200); + circle(50, 50, 70); + } + +
+return: + description: current pixel density of the display. + type: Number +chainable: false +--- + + +# displayDensity diff --git a/src/content/reference/en/p5/displayHeight.mdx b/src/content/reference/en/p5/displayHeight.mdx new file mode 100644 index 0000000000..1de5d3af22 --- /dev/null +++ b/src/content/reference/en/p5/displayHeight.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: displayHeight +module: Environment +submodule: Environment +file: src/core/environment.js +description: | +

A numeric variable that stores the height of the screen display. Its value + depends on the current pixelDensity(). + displayHeight is useful for running full-screen programs.

+

Note: The actual screen height can be computed as + displayHeight * pixelDensity().

+line: 577 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + // Set the canvas' width and height + // using the display's dimensions. + createCanvas(displayWidth, displayHeight); + + background(200); + + describe('A gray canvas that is the same size as the display.'); + } + +
+alt: This example does not render anything. +chainable: false +--- + + +# displayHeight diff --git a/src/content/reference/en/p5/displayWidth.mdx b/src/content/reference/en/p5/displayWidth.mdx new file mode 100644 index 0000000000..422586d32f --- /dev/null +++ b/src/content/reference/en/p5/displayWidth.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: displayWidth +module: Environment +submodule: Environment +file: src/core/environment.js +description: | +

A numeric variable that stores the width of the screen display. Its value + depends on the current pixelDensity(). + displayWidth is useful for running full-screen programs.

+

Note: The actual screen width can be computed as + displayWidth * pixelDensity().

+line: 547 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + // Set the canvas' width and height + // using the display's dimensions. + createCanvas(displayWidth, displayHeight); + + background(200); + + describe('A gray canvas that is the same size as the display.'); + } + +
+alt: This example does not render anything. +chainable: false +--- + + +# displayWidth diff --git a/src/content/reference/en/p5/dist.mdx b/src/content/reference/en/p5/dist.mdx new file mode 100644 index 0000000000..d24ce06dee --- /dev/null +++ b/src/content/reference/en/p5/dist.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: dist +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the distance between two points.

+ +

The version of dist() with four parameters calculates distance + in two + + dimensions.

+ +

The version of dist() with six parameters calculates distance + in three + + dimensions.

+ +

Use p5.Vector.dist() to calculate the + + distance between two p5.Vector objects.

+line: 124 +itemtype: method +class: p5 +example: + - >- + +
+ + + + let x1 = 10; + + let y1 = 50; + + let x2 = 90; + + let y2 = 50; + + + line(x1, y1, x2, y2); + + strokeWeight(5); + + point(x1, y1); + + point(x2, y2); + + + let d = dist(x1, y1, x2, y2); + + text(d, 43, 40); + + + describe('Two dots connected by a horizontal line. The number 80 is written + above the center of the line.'); + + + +
+return: + description: distance between the two points. + type: Number +chainable: false +--- + + +# dist diff --git a/src/content/reference/en/p5/doubleClicked.mdx b/src/content/reference/en/p5/doubleClicked.mdx new file mode 100644 index 0000000000..1144fa8705 --- /dev/null +++ b/src/content/reference/en/p5/doubleClicked.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: doubleClicked +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The doubleClicked() function is executed + every time a event + + listener has detected a dblclick event which is a part of the + + DOM L3 specification. The doubleClicked event is fired when a + + pointing device button (usually a mouse's primary button) + + is clicked twice on a single element. For more info on the + + dblclick event refer to mozilla's documentation here: + + https://developer.mozilla.org/en-US/docs/Web/Events/dblclick

+line: 826 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Click within the image to change + // the value of the rectangle + // after the mouse has been double clicked + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('black 50-by-50 rect turns white with mouse doubleClick/press.'); + } + + function doubleClicked() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+ +
+ + function doubleClicked() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function doubleClicked(event) { + console.log(event); + } + +
+chainable: false +--- + + +# doubleClicked diff --git a/src/content/reference/en/p5/draw.mdx b/src/content/reference/en/p5/draw.mdx new file mode 100644 index 0000000000..61669e8848 --- /dev/null +++ b/src/content/reference/en/p5/draw.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: draw +module: Structure +submodule: Structure +file: src/core/main.js +description: > +

Called directly after setup(), the draw() function continuously executes + + the lines of code contained inside its block until the program is stopped + + or noLoop() is called. Note if noLoop() is called in setup(), + draw() will + + still be executed once before stopping. draw() is + called automatically and + + should never be called explicitly.

+ +

It should always be controlled with noLoop(), redraw() and loop(). After + + noLoop() stops the code in draw() from executing, redraw() + causes the + + code inside draw() to execute once, and loop() will cause the code + + inside draw() to resume executing continuously.

+ +

The number of times draw() executes in each second + may be controlled with + + the frameRate() function.

+ +

There can only be one draw() function for each + sketch, and draw() must + + exist if you want the code to run continuously, or to process events such + + as mousePressed(). Sometimes, you might have + an empty call to draw() in + + your program, as shown in the above example.

+ +

It is important to note that the drawing coordinate system will be reset + + at the beginning of each draw() call. If any + transformations are performed + + within draw() (ex: scale, rotate, translate), their + effects will be + + undone at the beginning of draw(), so transformations + will not accumulate + + over time. On the other hand, styling applied (ex: fill, stroke, etc) will + + remain in effect.

+line: 113 +itemtype: method +class: p5 +example: + - |- + +
+ let yPos = 0; + function setup() { + // setup() runs once + frameRate(30); + } + function draw() { + // draw() loops forever, until stopped + background(204); + yPos = yPos - 1; + if (yPos < 0) { + yPos = height; + } + line(0, yPos, width, yPos); + } +
+alt: nothing displayed +chainable: false +--- + + +# draw diff --git a/src/content/reference/en/p5/drawingContext.mdx b/src/content/reference/en/p5/drawingContext.mdx new file mode 100644 index 0000000000..9fa83bb63c --- /dev/null +++ b/src/content/reference/en/p5/drawingContext.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: drawingContext +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

The p5.js API provides a lot of functionality for creating graphics, but + there is + + some native HTML5 Canvas functionality that is not exposed by p5. You can + still call + + it directly using the variable drawingContext, as in the example + shown. This is + + the equivalent of calling canvas.getContext('2d'); or + canvas.getContext('webgl');. + + See this + + + + reference for the native canvas API for possible drawing functions you can + call.

+line: 535 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + drawingContext.shadowOffsetX = 5; + drawingContext.shadowOffsetY = -5; + drawingContext.shadowBlur = 10; + drawingContext.shadowColor = 'black'; + background(200); + ellipse(width / 2, height / 2, 50, 50); + } + +
+alt: white ellipse with shadow blur effect around edges +chainable: false +--- + + +# drawingContext diff --git a/src/content/reference/en/p5/ellipse.mdx b/src/content/reference/en/p5/ellipse.mdx new file mode 100644 index 0000000000..a88ad5a6a5 --- /dev/null +++ b/src/content/reference/en/p5/ellipse.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ellipse +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws an ellipse (oval) to the canvas. An ellipse with equal width and + height + + is a circle. By default, the first two parameters set the location of the + + center of the ellipse. The third and fourth parameters set the shape's width + + and height, respectively. The origin may be changed with the + + ellipseMode() function.

+ +

If no height is specified, the value of width is used for both the width + and + + height. If a negative height or width is specified, the absolute value is + + taken.

+line: 231 +itemtype: method +class: p5 +example: + - | + +
+ + ellipse(56, 46, 55, 55); + describe('A white ellipse with black outline in middle of a gray canvas.'); + +
+chainable: true +--- + + +# ellipse diff --git a/src/content/reference/en/p5/ellipseMode.mdx b/src/content/reference/en/p5/ellipseMode.mdx new file mode 100644 index 0000000000..57f667fa6e --- /dev/null +++ b/src/content/reference/en/p5/ellipseMode.mdx @@ -0,0 +1,107 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ellipseMode +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Modifies the location from which ellipses, circles, and arcs are drawn. By + default, the + + first two parameters are the x- and y-coordinates of the shape's center. The + next + + parameters are its width and height. This is equivalent to calling + ellipseMode(CENTER).

+ +

ellipseMode(RADIUS) also uses the first two parameters to set + the x- and y-coordinates + + of the shape's center. The next parameters are half of the shapes's width and + height. + + Calling ellipse(0, 0, 10, 15) draws a shape with a width of 20 + and height of 30.

+ +

ellipseMode(CORNER) uses the first two parameters as the + upper-left corner of the + + shape. The next parameters are its width and height.

+ +

ellipseMode(CORNERS) uses the first two parameters as the + location of one corner + + of the ellipse's bounding box. The third and fourth parameters are the + location of the + + opposite corner.

+ +

The argument passed to ellipseMode() must be written in ALL + CAPS because the constants + + CENTER, RADIUS, CORNER, and + CORNERS are defined this way. JavaScript is a + + case-sensitive language.

+line: 12 +params: + - name: mode + description: | +

either CENTER, RADIUS, CORNER, or CORNERS

+ type: Constant +itemtype: method +class: p5 +example: + - >- + +
+ + + + ellipseMode(RADIUS); + + fill(255); + + ellipse(50, 50, 30, 30); + + ellipseMode(CENTER); + + fill(100); + + ellipse(50, 50, 30, 30); + + describe('A white circle with a gray circle at its center. Both circles have + black outlines.'); + + + +
+ + +
+ + + + ellipseMode(CORNER); + + fill(255); + + ellipse(25, 25, 50, 50); + + ellipseMode(CORNERS); + + fill(100); + + ellipse(25, 25, 50, 50); + + describe('A white circle with a gray circle at its top-left corner. Both + circles have black outlines.'); + + + +
+chainable: true +--- + + +# ellipseMode diff --git a/src/content/reference/en/p5/ellipsoid.mdx b/src/content/reference/en/p5/ellipsoid.mdx new file mode 100644 index 0000000000..187c3c5a8c --- /dev/null +++ b/src/content/reference/en/p5/ellipsoid.mdx @@ -0,0 +1,120 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ellipsoid +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Draw an ellipsoid with given radius

+ +

DetailX and detailY determine the number of subdivisions in the x-dimension + and + + the y-dimension of a cone. More subdivisions make the ellipsoid appear to be + smoother. + + Avoid detail number above 150, it may crash the browser.

+line: 864 +params: + - name: radiusx + description: | +

x-radius of ellipsoid

+ type: Number + optional: true + - name: radiusy + description: | +

y-radius of ellipsoid

+ type: Number + optional: true + - name: radiusz + description: | +

z-radius of ellipsoid

+ type: Number + optional: true + - name: detailX + description: | +

number of segments, + the more segments the smoother geometry + default is 24. Avoid detail number above + 150, it may crash the browser.

+ type: Integer + optional: true + - name: detailY + description: | +

number of segments, + the more segments the smoother geometry + default is 16. Avoid detail number above + 150, it may crash the browser.

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw an ellipsoid + // with radius 30, 40 and 40. + function setup() { + createCanvas(100, 100, WEBGL); + describe('a white 3d ellipsoid'); + } + + function draw() { + background(205, 105, 94); + ellipsoid(30, 40, 40); + } + +
+ - |- + +
+ + // slide to see how detailX works + let detailX; + function setup() { + createCanvas(100, 100, WEBGL); + detailX = createSlider(2, 24, 12); + detailX.position(10, height + 5); + detailX.style('width', '80px'); + describe( + 'a rotating white ellipsoid with limited X detail, with a slider that adjusts detailX' + ); + } + + function draw() { + background(205, 105, 94); + rotateY(millis() / 1000); + ellipsoid(30, 40, 40, detailX.value(), 8); + } + +
+ - |- + +
+ + // slide to see how detailY works + let detailY; + function setup() { + createCanvas(100, 100, WEBGL); + detailY = createSlider(2, 24, 6); + detailY.position(10, height + 5); + detailY.style('width', '80px'); + describe( + 'a rotating white ellipsoid with limited Y detail, with a slider that adjusts detailY' + ); + } + + function draw() { + background(205, 105, 9); + rotateY(millis() / 1000); + ellipsoid(30, 40, 40, 12, detailY.value()); + } + +
+chainable: true +--- + + +# ellipsoid diff --git a/src/content/reference/en/p5/emissiveMaterial.mdx b/src/content/reference/en/p5/emissiveMaterial.mdx new file mode 100644 index 0000000000..6db16410f1 --- /dev/null +++ b/src/content/reference/en/p5/emissiveMaterial.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: emissiveMaterial +module: 3D +submodule: Material +file: src/webgl/material.js +description: | +

Sets the emissive color of the material.

+

An emissive material will display the emissive color at + full strength regardless of lighting. This can give the + appearance that the object is glowing.

+

Note, "emissive" is a misnomer in the sense that the material + does not actually emit light that will affect surrounding objects.

+

You can view more materials in this + example.

+line: 982 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe('sphere with green emissive material'); + } + function draw() { + background(0); + noStroke(); + ambientLight(0); + emissiveMaterial(130, 230, 0); + sphere(40); + } + +
+alt: sphere with green emissive material +chainable: true +--- + + +# emissiveMaterial diff --git a/src/content/reference/en/p5/endClip.mdx b/src/content/reference/en/p5/endClip.mdx new file mode 100644 index 0000000000..b94835588b --- /dev/null +++ b/src/content/reference/en/p5/endClip.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: endClip +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

Finishes defining a shape that will mask subsequent things drawn to the + canvas. + + Only opaque regions of the mask shape will allow content to be drawn. + + Any shapes drawn between beginClip() and this + + will contribute to the mask shape.

+line: 108 +itemtype: method +class: p5 +chainable: false +--- + + +# endClip diff --git a/src/content/reference/en/p5/endContour.mdx b/src/content/reference/en/p5/endContour.mdx new file mode 100644 index 0000000000..458b178247 --- /dev/null +++ b/src/content/reference/en/p5/endContour.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: endContour +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Use the beginContour() and endContour() functions to create negative + + shapes within shapes such as the center of the letter 'O'. beginContour() + + begins recording vertices for the shape and endContour() stops recording. + + The vertices that define a negative shape must "wind" in the opposite + + direction from the exterior shape. First draw vertices for the exterior + + clockwise order, then for internal shapes, draw vertices + + shape in counter-clockwise.

+ +

These functions can only be used within a beginShape()/endShape() + pair and + + transformations such as translate(), rotate(), and scale() do not + work + + within a beginContour()/endContour() pair. It is also not possible to use + + other shapes, such as ellipse() or rect() within.

+line: 528 +itemtype: method +class: p5 +example: + - |- + +
+ + translate(50, 50); + stroke(255, 0, 0); + beginShape(); + // Exterior part of shape, clockwise winding + vertex(-40, -40); + vertex(40, -40); + vertex(40, 40); + vertex(-40, 40); + // Interior part of shape, counter-clockwise winding + beginContour(); + vertex(-20, -20); + vertex(-20, 20); + vertex(20, 20); + vertex(20, -20); + endContour(); + endShape(CLOSE); + +
+alt: white rect and smaller grey rect with red outlines in center of canvas. +chainable: true +--- + + +# endContour diff --git a/src/content/reference/en/p5/endGeometry.mdx b/src/content/reference/en/p5/endGeometry.mdx new file mode 100644 index 0000000000..f3656115fa --- /dev/null +++ b/src/content/reference/en/p5/endGeometry.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: endGeometry +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: | +

Finishes creating a new p5.Geometry that was + started using beginGeometry(). One can also + use buildGeometry() to pass a function that + draws shapes.

+line: 89 +itemtype: method +class: p5 +return: + description: The model that was built. + type: p5.Geometry +chainable: false +--- + + +# endGeometry diff --git a/src/content/reference/en/p5/endShape.mdx b/src/content/reference/en/p5/endShape.mdx new file mode 100644 index 0000000000..188a34b06e --- /dev/null +++ b/src/content/reference/en/p5/endShape.mdx @@ -0,0 +1,160 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: endShape +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

The endShape() function is the companion to beginShape() and may only be + + called after beginShape(). When endShape() is called, all of the image + + data defined since the previous call to beginShape() is written into the image + + buffer. The constant CLOSE is the value for the mode parameter to + close + + the shape (to connect the beginning and the end). + + When using instancing with endShape() the + instancing will not apply to the strokes. + + When the count parameter is used with a value greater than 1, it enables + instancing for shapes built when in WEBGL mode. Instancing + + is a feature that allows the GPU to efficiently draw multiples of the same + shape. It's often used for particle effects or other + + times when you need a lot of repetition. In order to take advantage of + instancing, you will also need to write your own custom + + shader using the gl_InstanceID keyword. You can read more about instancing + + here + or by working from the example on this + + page.

+line: 591 +params: + - name: mode + description: | +

use CLOSE to close the shape

+ type: Constant + optional: true + - name: count + description: > +

number of times you want to draw/instance the shape (for WebGL + mode).

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + noFill(); + + beginShape(); + vertex(20, 20); + vertex(45, 20); + vertex(45, 80); + endShape(CLOSE); + + beginShape(); + vertex(50, 20); + vertex(75, 20); + vertex(75, 80); + endShape(); + +
+ - |- + +
+ + let fx; + let vs = `#version 300 es + + precision mediump float; + + in vec3 aPosition; + flat out int instanceID; + + uniform mat4 uModelViewMatrix; + uniform mat4 uProjectionMatrix; + + void main() { + + // copy the instance ID to the fragment shader + instanceID = gl_InstanceID; + vec4 positionVec4 = vec4(aPosition, 1.0); + + // gl_InstanceID represents a numeric value for each instance + // using gl_InstanceID allows us to move each instance separately + // here we move each instance horizontally by id * 23 + float xOffset = float(gl_InstanceID) * 23.0; + + // apply the offset to the final position + gl_Position = uProjectionMatrix * uModelViewMatrix * (positionVec4 - + vec4(xOffset, 0.0, 0.0, 0.0)); + } + `; + let fs = `#version 300 es + + precision mediump float; + + out vec4 outColor; + flat in int instanceID; + uniform float numInstances; + + void main() { + vec4 red = vec4(1.0, 0.0, 0.0, 1.0); + vec4 blue = vec4(0.0, 0.0, 1.0, 1.0); + + // Normalize the instance id + float normId = float(instanceID) / numInstances; + + // Mix between two colors using the normalized instance id + outColor = mix(red, blue, normId); + } + `; + + function setup() { + createCanvas(100, 100, WEBGL); + fx = createShader(vs, fs); + } + + function draw() { + background(220); + + // strokes aren't instanced, and are rather used for debug purposes + shader(fx); + fx.setUniform('numInstances', 4); + + // this doesn't have to do with instancing, this is just for centering the squares + translate(25, -10); + + // here we draw the squares we want to instance + beginShape(); + vertex(0, 0); + vertex(0, 20); + vertex(20, 20); + vertex(20, 0); + vertex(0, 0); + endShape(CLOSE, 4); + + resetShader(); + } + +
+alt: Triangle line shape with smallest interior angle on bottom and upside-down L. +chainable: true +--- + + +# endShape diff --git a/src/content/reference/en/p5/erase.mdx b/src/content/reference/en/p5/erase.mdx new file mode 100644 index 0000000000..b9f13eecbe --- /dev/null +++ b/src/content/reference/en/p5/erase.mdx @@ -0,0 +1,152 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: erase +module: Color +submodule: Setting +file: src/color/setting.js +description: > +

All drawing that follows erase() will subtract + + from the canvas, revealing the web page underneath. The erased areas will + + become transparent, allowing the content behind the canvas to show through. + + The fill(), stroke(), and + + blendMode() have no effect once + erase() is + + called.

+ +

The erase() function has two optional parameters. The first + parameter + + sets the strength of erasing by the shape's interior. A value of 0 means + + that no erasing will occur. A value of 255 means that the shape's interior + + will fully erase the content underneath. The default value is 255 + + (full strength).

+ +

The second parameter sets the strength of erasing by the shape's edge. A + + value of 0 means that no erasing will occur. A value of 255 means that the + + shape's edge will fully erase the content underneath. The default value is + + 255 (full strength).

+ +

To cancel the erasing effect, use the noErase() + + function.

+ +

erase() has no effect on drawing done with the + + image() and + + background() functions.

+line: 1005 +params: + - name: strengthFill + description: | +

a number (0-255) for the strength of erasing under a shape's interior. + Defaults to 255, which is full strength.

+ type: Number + optional: true + - name: strengthStroke + description: | +

a number (0-255) for the strength of erasing under a shape's edge. + Defaults to 255, which is full strength.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - >- + +
+ + + + background(100, 100, 250); + + fill(250, 100, 100); + + square(20, 20, 60); + + erase(); + + circle(25, 30, 30); + + noErase(); + + describe('A purple canvas with a pink square in the middle. A circle is + erased from the top-left, leaving a white hole.'); + + + +
+ + +
+ + + + let p = createP('I am a DOM element'); + + p.style('font-size', '12px'); + + p.style('width', '65px'); + + p.style('text-align', 'center'); + + p.position(18, 26); + + + background(100, 170, 210); + + erase(200, 100); + + circle(50, 50, 77); + + noErase(); + + describe('A blue canvas with a circular hole in the center that reveals the + message "I am a DOM element".'); + + + +
+ + +
+ + + + background(150, 250, 150); + + fill(100, 100, 250); + + square(20, 20, 60); + + strokeWeight(5); + + erase(150, 255); + + triangle(50, 10, 70, 50, 90, 10); + + noErase(); + + describe('A mint green canvas with a purple square in the center. A triangle + in the top-right corner partially erases its interior and a fully erases its + outline.'); + + + +
+chainable: true +--- + + +# erase diff --git a/src/content/reference/en/p5/exitPointerLock.mdx b/src/content/reference/en/p5/exitPointerLock.mdx new file mode 100644 index 0000000000..40c0b1ab5a --- /dev/null +++ b/src/content/reference/en/p5/exitPointerLock.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: exitPointerLock +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The function exitPointerLock() + + exits a previously triggered pointer + Lock + + for example to make ui elements usable etc

+line: 1005 +itemtype: method +class: p5 +example: + - |- + +
+ + //click the canvas to lock the pointer + //click again to exit (otherwise escape) + let locked = false; + function draw() { + background(237, 34, 93); + describe('cursor gets locked / unlocked on mouse-click'); + } + function mouseClicked() { + if (!locked) { + locked = true; + requestPointerLock(); + } else { + exitPointerLock(); + locked = false; + } + } + +
+chainable: false +--- + + +# exitPointerLock diff --git a/src/content/reference/en/p5/exp.mdx b/src/content/reference/en/p5/exp.mdx new file mode 100644 index 0000000000..eaaf021ba3 --- /dev/null +++ b/src/content/reference/en/p5/exp.mdx @@ -0,0 +1,45 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: exp +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Returns Euler's number e (2.71828...) raised to the power of the + n + + parameter.

+line: 184 +params: + - name: 'n' + description: | +

exponent to raise.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Invert the y-axis. + scale(1, -1); + translate(0, -height); + + let x = frameCount; + let y = 0.005 * exp(x * 0.1); + point(x, y); + + describe('A series of black dots that grow exponentially from left to right.'); + } + +
+return: + description: e^n + type: Number +chainable: false +--- + + +# exp diff --git a/src/content/reference/en/p5/fill.mdx b/src/content/reference/en/p5/fill.mdx new file mode 100644 index 0000000000..89caedeb26 --- /dev/null +++ b/src/content/reference/en/p5/fill.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: FILL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 665 +itemtype: property +class: p5 +chainable: false +--- + + +# FILL diff --git a/src/content/reference/en/p5/filter.mdx b/src/content/reference/en/p5/filter.mdx new file mode 100644 index 0000000000..741ed31f03 --- /dev/null +++ b/src/content/reference/en/p5/filter.mdx @@ -0,0 +1,236 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: filter +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Applies an image filter to the canvas. The preset options are:

+ +

INVERT + + Inverts the colors in the image. No parameter is used.

+ +

GRAY + + Converts the image to grayscale. No parameter is used.

+ +

THRESHOLD + + Converts the image to black and white. Pixels with a grayscale value + + above a given threshold are converted to white. The rest are converted to + + black. The threshold must be between 0.0 (black) and 1.0 (white). If no + + value is specified, 0.5 is used.

+ +

OPAQUE + + Sets the alpha channel to entirely opaque. No parameter is used.

+ +

POSTERIZE + + Limits the number of colors in the image. Each color channel is limited to + + the number of colors specified. Values between 2 and 255 are valid, but + + results are most noticeable with lower values. The default value is 4.

+ +

BLUR + + Blurs the image. The level of blurring is specified by a blur radius. Larger + + values increase the blur. The default value is 4. A gaussian blur is used + + in P2D mode. A box blur is used in WEBGL mode.

+ +

ERODE + + Reduces the light areas. No parameter is used.

+ +

DILATE + + Increases the light areas. No parameter is used.

+ +

filter() uses WebGL in the background by default because it's + faster. + + This can be disabled in P2D mode by adding a false + argument, as in + + filter(BLUR, false). This may be useful to keep computation off + the GPU + + or to work around a lack of WebGL support.

+ +

In WEBGL mode, filter() can also use custom + shaders. See + + createFilterShader() for more + + information.

+line: 343 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(INVERT); + + describe('A blue brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(GRAY); + + describe('A brick wall drawn in grayscale.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(THRESHOLD); + + describe('A brick wall drawn in black and white.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(OPAQUE); + + describe('A red brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(POSTERIZE, 3); + + describe('An image of a red brick wall drawn with limited color palette.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(BLUR, 3); + + describe('A blurry image of a red brick wall.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(DILATE); + + describe('A red brick wall with bright lines between each brick.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + filter(ERODE); + + describe('A red brick wall with faint lines between each brick.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + image(img, 0, 0); + // Don't use WebGL. + filter(BLUR, 3, false); + + describe('A blurry image of a red brick wall.'); + } + +
+chainable: false +--- + + +# filter diff --git a/src/content/reference/en/p5/floor.mdx b/src/content/reference/en/p5/floor.mdx new file mode 100644 index 0000000000..e9dae098e1 --- /dev/null +++ b/src/content/reference/en/p5/floor.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: floor +module: Math +submodule: Calculation +file: src/math/calculation.js +description: | +

Calculates the closest integer value that is less than or equal to the + value of the n parameter.

+line: 210 +params: + - name: 'n' + description: | +

number to round down.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + // Set the range for RGB values from 0 to 1. + + colorMode(RGB, 1); + + noStroke(); + + + let r = 0.8; + + fill(r, 0, 0); + + rect(0, 0, width / 2, height); + + + // Round r down to 0. + + r = floor(r); + + fill(r, 0, 0); + + rect(width / 2, 0, width / 2, height); + + + describe('Two rectangles. The one on the left is bright red and the one on + the right is black.'); + + + +
+return: + description: rounded down number. + type: Integer +chainable: false +--- + + +# floor diff --git a/src/content/reference/en/p5/focused.mdx b/src/content/reference/en/p5/focused.mdx new file mode 100644 index 0000000000..2e1257b45c --- /dev/null +++ b/src/content/reference/en/p5/focused.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: focused +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Tracks whether the browser window is focused and can receive user input. + + focused is true if the window if focused and + false if not.

+line: 164 +itemtype: property +class: p5 +example: + - |- + +
+ + // Open this example in two separate browser + // windows placed side-by-side to demonstrate. + + function draw() { + // Change the background color + // when the browser window + // goes in/out of focus. + if (focused === true) { + background(0, 255, 0); + } else { + background(255, 0, 0); + } + + describe('A square changes color from green to red when the browser window is out of focus.'); + } + +
+chainable: false +--- + + +# focused diff --git a/src/content/reference/en/p5/for.mdx b/src/content/reference/en/p5/for.mdx new file mode 100644 index 0000000000..0626ed803a --- /dev/null +++ b/src/content/reference/en/p5/for.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: for +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

for creates a loop that is useful for executing one + + section of code multiple times.

+ +

A 'for loop' consists of three different expressions inside of a + parenthesis, + + all of which are optional.These expressions are used to control the number of + + times the loop is run.The first expression is a statement that is used to set + + the initial state for the loop.The second expression is a condition that you + + would like to check before each loop. If this expression returns false then + + the loop will exit.The third expression is executed at the end of each loop. + + These expression are separated by ; (semi-colon).In case of an empty + expression, + + only a semi-colon is written.

+ +

The code inside of the loop body (in between the curly braces) is executed + between the evaluation of the second + + and third expression.

+ +

As with any loop, it is important to ensure that the loop can 'exit', or + that + + the test condition will eventually evaluate to false. The test condition with + a for loop + + is the second expression detailed above. Ensuring that this expression can + eventually + + become false ensures that your loop doesn't attempt to run an infinite amount + of times, + + which can crash your browser.

+ +

From the + MDN entry: + + Creates a loop that executes a specified statement until the test condition + evaluates to false. + + The condition is evaluated after executing the statement, resulting in the + specified statement executing at least once.

+line: 408 +itemtype: property +class: p5 +example: + - |- + +
+ + for (let i = 0; i < 9; i++) { + console.log(i); + } + +
+alt: This example does not render anything +chainable: false +--- + + +# for diff --git a/src/content/reference/en/p5/fract.mdx b/src/content/reference/en/p5/fract.mdx new file mode 100644 index 0000000000..e9597bf18a --- /dev/null +++ b/src/content/reference/en/p5/fract.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: fract +module: Math +submodule: Calculation +file: src/math/calculation.js +description: | +

Calculates the fractional part of a number. For example, + fract(12.34) returns 0.34.

+line: 730 +params: + - name: 'n' + description: | +

number whose fractional part will be found.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let n = 56.78; + text(n, 20, 33); + let f = fract(n); + text(f, 20, 66); + + describe('The number 56.78 written above the number 0.78.'); + +
+return: + description: fractional part of n. + type: Number +chainable: false +--- + + +# fract diff --git a/src/content/reference/en/p5/frameCount.mdx b/src/content/reference/en/p5/frameCount.mdx new file mode 100644 index 0000000000..a9090e9db7 --- /dev/null +++ b/src/content/reference/en/p5/frameCount.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: frameCount +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Tracks the number of frames drawn since the sketch started.

+ +

frameCount's value is 0 inside setup(). It + + increments by 1 each time the code in draw() + + finishes executing.

+line: 69 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Display the value of + // frameCount. + textSize(30); + textAlign(CENTER, CENTER); + text(frameCount, 50, 50); + + describe('The number 0 written in black in the middle of a gray square.'); + } + +
+ +
+ + function setup() { + // Set the frameRate to 30. + frameRate(30); + + textSize(30); + textAlign(CENTER, CENTER); + } + + function draw() { + background(200); + + // Display the value of + // frameCount. + text(frameCount, 50, 50); + + describe('A number written in black in the middle of a gray square. Its value increases rapidly.'); + } + +
+chainable: false +--- + + +# frameCount diff --git a/src/content/reference/en/p5/frameRate.mdx b/src/content/reference/en/p5/frameRate.mdx new file mode 100644 index 0000000000..e95233621f --- /dev/null +++ b/src/content/reference/en/p5/frameRate.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: frameRate +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Sets the number of frames to draw per second.

+ +

Calling frameRate() with one numeric argument, as in + frameRate(30), + + attempts to draw 30 frames per second (FPS). The target frame rate may not + + be achieved depending on the sketch's processing needs. Most computers + + default to a frame rate of 60 FPS. Frame rates of 24 FPS and above are + + fast enough for smooth animations.

+ +

Calling frameRate() without an argument returns the current + frame rate. + + The value returned is an approximation.

+line: 302 +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + // Set the x variable based + // on the current frameCount. + let x = frameCount % 100; + + // If the mouse is pressed, + // decrease the frame rate. + if (mouseIsPressed === true) { + frameRate(10); + } else { + frameRate(60); + } + + // Use x to set the circle's + // position. + circle(x, 50, 20); + + describe('A white circle on a gray background. The circle moves from left to right in a loop. It slows down when the mouse is pressed.'); + } + +
+ +
+ + function draw() { + background(200); + + // If the mouse is pressed, do lots + // of math to slow down drawing. + if (mouseIsPressed === true) { + for (let i = 0; i < 1000000; i += 1) { + random(); + } + } + + // Get the current frame rate + // and display it. + let fps = frameRate(); + text(fps, 50, 50); + + describe('A number written in black written on a gray background. The number decreases when the mouse is pressed.'); + } + +
+chainable: true +--- + + +# frameRate diff --git a/src/content/reference/en/p5/freeGeometry.mdx b/src/content/reference/en/p5/freeGeometry.mdx new file mode 100644 index 0000000000..1647a1f935 --- /dev/null +++ b/src/content/reference/en/p5/freeGeometry.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: freeGeometry +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: | +

Clears the resources of a model to free up browser memory. A model whose + resources have been cleared can still be drawn, but the first time it is + drawn again, it might take longer.

+

This method works on models generated with + buildGeometry() as well as those loaded + from loadModel().

+line: 167 +params: + - name: geometry + description: | +

The geometry whose resources should be freed

+ type: p5.Geometry +itemtype: method +class: p5 +chainable: false +--- + + +# freeGeometry diff --git a/src/content/reference/en/p5/freqToMidi.mdx b/src/content/reference/en/p5/freqToMidi.mdx new file mode 100644 index 0000000000..1d74f9d7e2 --- /dev/null +++ b/src/content/reference/en/p5/freqToMidi.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: freqToMidi +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the closest MIDI note value for + a given frequency.

+line: 825 +params: + - name: frequency + description: | +

A freqeuncy, for example, the "A" + above Middle C is 440Hz

+ type: Number +itemtype: method +class: p5 +return: + description: MIDI note value + type: Number +chainable: false +--- + + +# freqToMidi diff --git a/src/content/reference/en/p5/frustum.mdx b/src/content/reference/en/p5/frustum.mdx new file mode 100644 index 0000000000..74d8825bae --- /dev/null +++ b/src/content/reference/en/p5/frustum.mdx @@ -0,0 +1,95 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: frustum +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets the frustum of the current camera as defined by + the parameters.

+

A frustum is a geometric form: a pyramid with its top + cut off. With the viewer's eye at the imaginary top of + the pyramid, the six planes of the frustum act as clipping + planes when rendering a 3D view. Thus, any form inside the + clipping planes is visible; anything outside + those planes is not visible.

+

Setting the frustum changes the perspective of the scene being rendered. + This can be achieved more simply in many cases by using + perspective().

+

If no parameters are given, the following default is used: + frustum(-width/20, width/20, height/20, -height/20, eyeZ/10, eyeZ*10), + where eyeZ is equal to 800.

+line: 259 +params: + - name: left + description: | +

camera frustum left plane

+ type: Number + optional: true + - name: right + description: | +

camera frustum right plane

+ type: Number + optional: true + - name: bottom + description: | +

camera frustum bottom plane

+ type: Number + optional: true + - name: top + description: | +

camera frustum top plane

+ type: Number + optional: true + - name: near + description: | +

camera frustum near plane

+ type: Number + optional: true + - name: far + description: | +

camera frustum far plane

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + setAttributes('antialias', true); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + frustum(-0.1, 0.1, -0.1, 0.1, 0.1, 200); + describe( + 'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.' + ); + } + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateY(-0.2); + rotateX(-0.3); + push(); + translate(-15, 0, sin(frameCount / 30) * 25); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 25); + box(30); + pop(); + } + +
+alt: >- + two 3D boxes move back and forth along same plane, rotating as mouse is + dragged. +chainable: true +--- + + +# frustum diff --git a/src/content/reference/en/p5/fullscreen.mdx b/src/content/reference/en/p5/fullscreen.mdx new file mode 100644 index 0000000000..09aa784796 --- /dev/null +++ b/src/content/reference/en/p5/fullscreen.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: fullscreen +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Toggles full-screen mode or returns the current mode.

+ +

Calling fullscreen(true) makes the sketch full-screen. Calling + + fullscreen(false) makes the sketch its original size.

+ +

Calling fullscreen() without an argument returns + true if the sketch + + is in full-screen mode and false if not.

+ +

Note: Due to browser restrictions, fullscreen() can only be + called with + + user input such as a mouse press.

+line: 888 +params: + - name: val + description: | +

whether the sketch should be in fullscreen mode.

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + describe('A gray canvas that switches between default and full-screen display when clicked.'); + } + + // If the mouse is pressed, + // toggle full-screen mode. + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + let fs = fullscreen(); + fullscreen(!fs); + } + } + +
+return: + description: current fullscreen state. + type: Boolean +chainable: false +--- + + +# fullscreen diff --git a/src/content/reference/en/p5/function.mdx b/src/content/reference/en/p5/function.mdx new file mode 100644 index 0000000000..90576a26d2 --- /dev/null +++ b/src/content/reference/en/p5/function.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: function +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Creates and names a function. + + A function is a set of statements that perform a + task.

+ +

Optionally, functions can have parameters. Parameters + + are variables that are scoped to the function, that can be assigned a value + + when calling the function.Multiple parameters can be given by seperating them + + with commmas.

+ +

From the + MDN entry: + + Declares a function with the specified parameters.

+line: 231 +itemtype: property +class: p5 +example: + - |- + +
+ + let myName = 'Hridi'; + function sayHello(name) { + console.log('Hello ' + name + '!'); + } + sayHello(myName); // calling the function, prints "Hello Hridi!" to console. + +
+ +
+ + let square = number => number * number; + console.log(square(5)); + +
+alt: This example does not render anything +chainable: false +--- + + +# function diff --git a/src/content/reference/en/p5/get.mdx b/src/content/reference/en/p5/get.mdx new file mode 100644 index 0000000000..29b949e0b9 --- /dev/null +++ b/src/content/reference/en/p5/get.mdx @@ -0,0 +1,108 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: get +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Gets a pixel or a region of pixels from the canvas.

+ +

get() is easy to use but it's not as fast as + + pixels. Use pixels + + to read many pixel values.

+ +

The version of get() with no parameters returns the entire + canvas.

+ +

The version of get() with two parameters interprets them as + + coordinates. It returns an array with the [R, G, B, A] values of + the + + pixel at the given point.

+ +

The version of get() with four parameters interprets them as + coordinates + + and dimensions. It returns a subsection of the canvas as a + + p5.Image object. The first two parameters are the + + coordinates for the upper-left corner of the subsection. The last two + + parameters are the width and height of the subsection.

+ +

Use p5.Image.get() to work directly with + + p5.Image objects.

+line: 665 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let c = get(); + image(c, width / 2, 0); + + describe('Two identical mountain landscapes shown side-by-side.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let c = get(50, 90); + fill(c); + noStroke(); + square(25, 25, 50); + + describe('A mountain landscape with an olive green square in its center.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0); + let c = get(0, 0, width / 2, height / 2); + image(c, width / 2, height / 2); + + describe('A mountain landscape drawn on top of another mountain landscape.'); + } + +
+return: + description: subsection as a p5.Image object. + type: p5.Image +chainable: false +--- + + +# get diff --git a/src/content/reference/en/p5/getAudioContext.mdx b/src/content/reference/en/p5/getAudioContext.mdx new file mode 100644 index 0000000000..386d5038e5 --- /dev/null +++ b/src/content/reference/en/p5/getAudioContext.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getAudioContext +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

Returns the Audio Context for this sketch. Useful for users + who would like to dig deeper into the Web Audio API + .

+ +

Some browsers require users to startAudioContext + with a user gesture, such as touchStarted in the example below.

+line: 159 +itemtype: method +class: p5 +example: + - |- + +
+ function draw() { + background(255); + textAlign(CENTER); + + if (getAudioContext().state !== 'running') { + text('click to start audio', width/2, height/2); + } else { + text('audio is enabled', width/2, height/2); + } + } + + function touchStarted() { + if (getAudioContext().state !== 'running') { + getAudioContext().resume(); + } + var synth = new p5.MonoSynth(); + synth.play('A4', 0.5, 0, 0.2); + } + +
+return: + description: AudioContext for this sketch + type: Object +chainable: false +--- + + +# getAudioContext diff --git a/src/content/reference/en/p5/getItem.mdx b/src/content/reference/en/p5/getItem.mdx new file mode 100644 index 0000000000..2b094caead --- /dev/null +++ b/src/content/reference/en/p5/getItem.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getItem +module: Data +submodule: LocalStorage +file: src/data/local_storage.js +description: | +

Returns the value of an item that was stored in local storage + using storeItem()

+line: 99 +params: + - name: key + description: | +

name that you wish to use to store in local storage

+ type: String +itemtype: method +class: p5 +example: + - |2- + +
+ // Click the mouse to change + // the color of the background + // Once you have changed the color + // it will stay changed even when you + // reload the page. + let myColor; + function setup() { + createCanvas(100, 100); + myColor = getItem('myColor'); + } + function draw() { + if (myColor !== null) { + background(myColor); + } + describe(`If you click, the canvas changes to a random color.· + If you reload the page, the canvas is still the color it was when the + page was previously loaded.`); + } + function mousePressed() { + myColor = color(random(255), random(255), random(255)); + storeItem('myColor', myColor); + } +
+return: + description: Value of stored item + type: Number|Object|String|Boolean|p5.Color|p5.Vector +chainable: false +--- + + +# getItem diff --git a/src/content/reference/en/p5/getOutputVolume.mdx b/src/content/reference/en/p5/getOutputVolume.mdx new file mode 100644 index 0000000000..b553e63a90 --- /dev/null +++ b/src/content/reference/en/p5/getOutputVolume.mdx @@ -0,0 +1,22 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getOutputVolume +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns a number representing the output volume for sound + in this sketch.

+line: 726 +itemtype: method +class: p5 +return: + description: |- + Output volume for sound in this sketch. + Should be between 0.0 (silence) and 1.0. + type: Number +chainable: false +--- + + +# getOutputVolume diff --git a/src/content/reference/en/p5/getTargetFrameRate.mdx b/src/content/reference/en/p5/getTargetFrameRate.mdx new file mode 100644 index 0000000000..9b9049356c --- /dev/null +++ b/src/content/reference/en/p5/getTargetFrameRate.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getTargetFrameRate +module: Environment +submodule: Environment +file: src/core/environment.js +description: | +

Returns the target frame rate. The value is either the system frame rate or + the last value passed to frameRate().

+line: 411 +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + // Set the frame rate to 20. + frameRate(20); + + // Get the target frame rate and + // display it. + let fps = getTargetFrameRate(); + text(fps, 43, 54); + + describe('The number 20 written in black on a gray background.'); + } + +
+return: + description: _targetFrameRate + type: Number +chainable: false +--- + + +# getTargetFrameRate diff --git a/src/content/reference/en/p5/getURL.mdx b/src/content/reference/en/p5/getURL.mdx new file mode 100644 index 0000000000..70aa91bf73 --- /dev/null +++ b/src/content/reference/en/p5/getURL.mdx @@ -0,0 +1,43 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getURL +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Returns the sketch's current + + URL + + as a string.

+line: 1081 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Get the sketch's URL + // and display it. + let url = getURL(); + textWrap(CHAR); + text(url, 0, 40, 100); + + describe('The URL "https://p5js.org/reference/#/p5/getURL" written in black on a gray background.'); + } + +
+return: + description: url + type: String +chainable: false +--- + + +# getURL diff --git a/src/content/reference/en/p5/getURLParams.mdx b/src/content/reference/en/p5/getURLParams.mdx new file mode 100644 index 0000000000..82d8cc65c0 --- /dev/null +++ b/src/content/reference/en/p5/getURLParams.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getURLParams +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Returns the current + + URL parameters + + in an Object.

+ +

For example, calling getURLParams() in a sketch hosted at the + URL + + http://p5js.org?year=2014&month=May&day=15 returns + + { year: 2014, month: 'May', day: 15 }.

+line: 1140 +itemtype: method +class: p5 +example: + - |- + +
+ + // Imagine this sketch is hosted at the following URL: + // https://p5js.org?year=2014&month=May&day=15 + + function setup() { + background(200); + + // Get the sketch's URL + // parameters and display + // them. + let params = getURLParams(); + text(params.day, 10, 20); + text(params.month, 10, 40); + text(params.year, 10, 60); + + describe('The text "15", "May", and "2014" written in black on separate lines.'); + } + +
+alt: This example does not render anything. +return: + description: URL params + type: Object +chainable: false +--- + + +# getURLParams diff --git a/src/content/reference/en/p5/getURLPath.mdx b/src/content/reference/en/p5/getURLPath.mdx new file mode 100644 index 0000000000..adc7f72a44 --- /dev/null +++ b/src/content/reference/en/p5/getURLPath.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: getURLPath +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Returns the current + + URL + + path as an array of strings.

+ +

For example, consider a sketch hosted at the URL + + https://example.com/sketchbook. Calling getURLPath() + returns + + ['sketchbook']. For a sketch hosted at the URL + + https://example.com/sketchbook/monday, getURLPath() + returns + + ['sketchbook', 'monday'].

+line: 1107 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Get the sketch's URL path + // and display the first + // part. + let path = getURLPath(); + text(path[0], 25, 54); + + describe('The word "reference" written in black on a gray background.'); + } + +
+return: + description: path components. + type: 'String[]' +chainable: false +--- + + +# getURLPath diff --git a/src/content/reference/en/p5/green.mdx b/src/content/reference/en/p5/green.mdx new file mode 100644 index 0000000000..68f5f9e27a --- /dev/null +++ b/src/content/reference/en/p5/green.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: green +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the green value from a p5.Color object, + array of color components, or CSS color string.

+line: 303 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - >- + +
+ + + + const c = color(20, 75, 200); + + fill(c); + + rect(15, 20, 35, 60); + + // Sets 'greenValue' to 75. + + const greenValue = green(c); + + fill(0, greenValue, 0); + + rect(50, 20, 35, 60); + + describe('Two rectangles. The rectangle on the left is blue and the one on + the right is green.'); + + + +
+return: + description: the green value. + type: Number +chainable: false +--- + + +# green diff --git a/src/content/reference/en/p5/gridOutput.mdx b/src/content/reference/en/p5/gridOutput.mdx new file mode 100644 index 0000000000..d054fcff31 --- /dev/null +++ b/src/content/reference/en/p5/gridOutput.mdx @@ -0,0 +1,162 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: gridOutput +module: Environment +submodule: Environment +file: src/accessibility/outputs.js +description: > +

Creates a screen reader-accessible description for shapes on the canvas. + + gridOutput() adds a general description, table of shapes, and + list of + + shapes to the web page.

+ +

The general description includes the canvas size, canvas color, and number + of + + shapes. For example, + + gray canvas, 100 by 100 pixels, contains 2 shapes: 1 circle 1 + square.

+ +

gridOutput() uses its table of shapes as a grid. Each shape in + the grid + + is placed in a cell whose row and column correspond to the shape's location + + on the canvas. The grid cells describe the color and type of shape at that + + location. For example, red circle. These descriptions can be + selected + + individually to get more details. This is different from + + textOutput(), which uses its table as a + list.

+ +

A list of shapes follows the table. The list describes the color, type, + + location, and area of each shape. For example, + + red circle, location = middle, area = 3 %.

+ +

The display parameter is optional. It determines how the + description is + + displayed. If LABEL is passed, as in + gridOutput(LABEL), the description + + will be visible in a div element next to the canvas. Using LABEL + creates + + unhelpful duplicates for screen readers. Only use LABEL during + + development. If FALLBACK is passed, as in + gridOutput(FALLBACK), the + + description will only be visible to screen readers. This is the default + + mode.

+ +

Read + + How to label your p5.js code to + + learn more about making sketches accessible.

+line: 145 +params: + - name: display + description: | +

either FALLBACK or LABEL.

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Add the grid description. + gridOutput(); + + // Draw a couple of shapes. + background(200); + fill(255, 0, 0); + circle(20, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle and a blue square on a gray background.'); + } + +
+ +
+ + function setup() { + // Add the grid description and + // display it for debugging. + gridOutput(LABEL); + + // Draw a couple of shapes. + background(200); + fill(255, 0, 0); + circle(20, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle and a blue square on a gray background.'); + } + +
+ +
+ + function draw() { + // Add the grid description. + gridOutput(); + + // Draw a moving circle. + background(200); + let x = frameCount * 0.1; + fill(255, 0, 0); + circle(x, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle moves from left to right above a blue square.'); + } + +
+ +
+ + function draw() { + // Add the grid description and + // display it for debugging. + gridOutput(LABEL); + + // Draw a moving circle. + background(200); + let x = frameCount * 0.1; + fill(255, 0, 0); + circle(x, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle moves from left to right above a blue square.'); + } + +
+chainable: false +--- + + +# gridOutput diff --git a/src/content/reference/en/p5/height.mdx b/src/content/reference/en/p5/height.mdx new file mode 100644 index 0000000000..f81cee2aa1 --- /dev/null +++ b/src/content/reference/en/p5/height.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: height +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

A numeric variable that stores the height of the drawing canvas. Its + + default value is 100.

+ +

Calling createCanvas() or + + resizeCanvas() changes the value of + + height. Calling noCanvas() sets its + value to + + 0.

+line: 819 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Display the canvas' height. + text(height, 42, 54); + + describe('The number 100 written in black on a gray square.'); + } + +
+ +
+ + function setup() { + createCanvas(100, 50); + + background(200); + + // Display the canvas' height. + text(height, 42, 27); + + describe('The number 50 written in black on a gray rectangle.'); + } + +
+ +
+ + function setup() { + createCanvas(100, 100); + + background(200); + + // Display the canvas' height. + text(height, 42, 54); + + describe('The number 100 written in black on a gray square. When the mouse is pressed, the square becomes a rectangle and the number becomes 50.'); + } + + // If the mouse is pressed, reisze + // the canvas and display its new + // height. + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + resizeCanvas(100, 50); + background(200); + text(height, 42, 27); + } + } + +
+chainable: false +--- + + +# height diff --git a/src/content/reference/en/p5/hex.mdx b/src/content/reference/en/p5/hex.mdx new file mode 100644 index 0000000000..ae437bd125 --- /dev/null +++ b/src/content/reference/en/p5/hex.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hex +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a number to a string in its equivalent hexadecimal notation. If a + second parameter is passed, it is used to set the number of characters to + generate in the hexadecimal notation. When an array is passed in, an + array of strings in hexadecimal notation of the same length is returned.

+line: 243 +itemtype: method +class: p5 +example: + - |- + +
+ print(hex(255)); // "000000FF" + print(hex(255, 6)); // "0000FF" + print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ] + print(Infinity); // "FFFFFFFF" + print(-Infinity); // "00000000" +
+return: + description: hexadecimal string representation of value + type: String +chainable: false +--- + + +# hex diff --git a/src/content/reference/en/p5/hour.mdx b/src/content/reference/en/p5/hour.mdx new file mode 100644 index 0000000000..c7d11bc098 --- /dev/null +++ b/src/content/reference/en/p5/hour.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hour +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The hour() function + + returns the current hour as a value from 0 - 23.

+line: 29 +itemtype: method +class: p5 +example: + - |- + +
+ + let h = hour(); + text('Current hour:\n' + h, 5, 50); + describe('Current hour is displayed'); + +
+return: + description: the current hour + type: Integer +chainable: false +--- + + +# hour diff --git a/src/content/reference/en/p5/httpDo.mdx b/src/content/reference/en/p5/httpDo.mdx new file mode 100644 index 0000000000..03d4a61fd5 --- /dev/null +++ b/src/content/reference/en/p5/httpDo.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: httpDo +module: IO +submodule: Input +file: src/io/files.js +description: > +

Method for executing an HTTP request. If data type is not specified, + + p5 will try to guess based on the URL, defaulting to text.

+ + For more advanced use, you may also pass in the path as the first argument + + and a object as the second argument, the signature follows the one specified + + in the Fetch API specification. + + This method is suitable for fetching files up to size of 64MB when "GET" is + used.

+line: 907 +itemtype: method +class: p5 +example: + - |- + +
+ + // Examples use USGS Earthquake API: + // https://earthquake.usgs.gov/fdsnws/event/1/#methods + + // displays an animation of all USGS earthquakes + let earthquakes; + let eqFeatureIndex = 0; + + function preload() { + let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson'; + httpDo( + url, + { + method: 'GET', + // Other Request options, like special headers for apis + headers: { authorization: 'Bearer secretKey' } + }, + function(res) { + earthquakes = res; + } + ); + } + + function draw() { + // wait until the data is loaded + if (!earthquakes || !earthquakes.features[eqFeatureIndex]) { + return; + } + clear(); + + let feature = earthquakes.features[eqFeatureIndex]; + let mag = feature.properties.mag; + let rad = mag / 11 * ((width + height) / 2); + fill(255, 0, 0, 100); + ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad); + + if (eqFeatureIndex >= earthquakes.features.length) { + eqFeatureIndex = 0; + } else { + eqFeatureIndex += 1; + } + } + +
+return: + description: |- + A promise that resolves with the data when the operation + completes successfully or rejects with the error after + one occurs. + type: Promise +chainable: false +--- + + +# httpDo diff --git a/src/content/reference/en/p5/httpGet.mdx b/src/content/reference/en/p5/httpGet.mdx new file mode 100644 index 0000000000..ea8e512928 --- /dev/null +++ b/src/content/reference/en/p5/httpGet.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: httpGet +module: IO +submodule: Input +file: src/io/files.js +description: > +

Method for executing an HTTP GET request. If data type is not specified, + + p5 will try to guess based on the URL, defaulting to text. This is equivalent + to + + calling httpDo(path, 'GET'). The 'binary' datatype will return + + a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer + + which can be used to initialize typed arrays (such as Uint8Array).

+line: 740 +itemtype: method +class: p5 +example: + - |- + +
+ // Examples use USGS Earthquake API: + // https://earthquake.usgs.gov/fdsnws/event/1/#methods + let earthquakes; + function preload() { + // Get the most recent earthquake in the database + let url = + 'https://earthquake.usgs.gov/fdsnws/event/1/query?' + + 'format=geojson&limit=1&orderby=time'; + httpGet(url, 'jsonp', false, function(response) { + // when the HTTP request completes, populate the variable that holds the + // earthquake data used in the visualization. + earthquakes = response; + }); + } + + function draw() { + if (!earthquakes) { + // Wait until the earthquake data has loaded before drawing. + return; + } + background(200); + // Get the magnitude and name of the earthquake out of the loaded JSON + let earthquakeMag = earthquakes.features[0].properties.mag; + let earthquakeName = earthquakes.features[0].properties.place; + ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + textAlign(CENTER); + text(earthquakeName, 0, height - 30, width, 30); + noLoop(); + } +
+return: + description: |- + A promise that resolves with the data when the operation + completes successfully or rejects with the error after + one occurs. + type: Promise +chainable: false +--- + + +# httpGet diff --git a/src/content/reference/en/p5/httpPost.mdx b/src/content/reference/en/p5/httpPost.mdx new file mode 100644 index 0000000000..db661ae7a7 --- /dev/null +++ b/src/content/reference/en/p5/httpPost.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: httpPost +module: IO +submodule: Input +file: src/io/files.js +description: > +

Method for executing an HTTP POST request. If data type is not specified, + + p5 will try to guess based on the URL, defaulting to text. This is equivalent + to + + calling httpDo(path, 'POST').

+line: 817 +itemtype: method +class: p5 +example: + - >- + +
+ + + + // Examples use jsonplaceholder.typicode.com for a Mock Data API + + + let url = 'https://jsonplaceholder.typicode.com/posts'; + + let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very + cool.' }; + + + function setup() { + createCanvas(100, 100); + background(200); + } + + + function mousePressed() { + httpPost(url, 'json', postData, function(result) { + strokeWeight(2); + text(result.body, mouseX, mouseY); + }); + } + + + +
+ + +
+ + let url = 'ttps://invalidURL'; // A bad URL that will cause errors + + let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' }; + + + function setup() { + createCanvas(100, 100); + background(200); + } + + + function mousePressed() { + httpPost( + url, + 'json', + postData, + function(result) { + // ... won't be called + }, + function(error) { + strokeWeight(2); + text(error.toString(), mouseX, mouseY); + } + ); + } + +
+return: + description: |- + A promise that resolves with the data when the operation + completes successfully or rejects with the error after + one occurs. + type: Promise +chainable: false +--- + + +# httpPost diff --git a/src/content/reference/en/p5/hue.mdx b/src/content/reference/en/p5/hue.mdx new file mode 100644 index 0000000000..ed851f77cd --- /dev/null +++ b/src/content/reference/en/p5/hue.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: hue +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the hue value from a + p5.Color object, array of color components, or + CSS color string.

+

Hue exists in both HSB and HSL. It describes a color's position on the + color wheel. By default, this function returns the HSL-normalized hue. If + the colorMode() is set to HSB, it returns the + HSB-normalized hue.

+line: 330 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - | + +
+ + noStroke(); + colorMode(HSB, 255); + const c = color(0, 126, 255); + fill(c); + rect(15, 20, 35, 60); + // Sets 'hueValue' to 0. + const hueValue = hue(c); + fill(hueValue); + rect(50, 20, 35, 60); + describe( + 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.' + ); + +
+return: + description: the hue + type: Number +chainable: false +--- + + +# hue diff --git a/src/content/reference/en/p5/if-else.mdx b/src/content/reference/en/p5/if-else.mdx new file mode 100644 index 0000000000..88323b6bae --- /dev/null +++ b/src/content/reference/en/p5/if-else.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: if-else +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

The if-else statement helps control the flow of + your code.

+ +

A condition is placed between the parenthesis following 'if', + + when that condition evalues to truthy, + + the code between the following curly braces is run. + + Alternatively, when the condition evaluates to falsy, + + the code between the curly braces of 'else' block is run instead. Writing an + + else block is optional.

+ +

From the + MDN entry: + + The 'if' statement executes a statement if a specified condition is truthy. + + If the condition is falsy, another statement can be executed

+line: 200 +itemtype: property +class: p5 +example: + - |- + +
+ + let a = 4; + if (a > 0) { + console.log('positive'); + } else { + console.log('negative'); + } + +
+alt: This example does not render anything +chainable: false +--- + + +# if-else diff --git a/src/content/reference/en/p5/imageLight.mdx b/src/content/reference/en/p5/imageLight.mdx new file mode 100644 index 0000000000..98181e567f --- /dev/null +++ b/src/content/reference/en/p5/imageLight.mdx @@ -0,0 +1,111 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: imageLight +module: 3D +submodule: Lights +file: src/webgl/light.js +description: | +

Creates an image light with the given image.

+

The image light simulates light from all the directions. + This is done by using the image as a texture for an infinitely + large sphere light. This sphere contains + or encapsulates the whole scene/drawing. + It will have different effect for varying shininess of the + object in the drawing. + Under the hood it is mainly doing 2 types of calculations, + the first one is creating an irradiance map the + environment map of the input image. + The second one is managing reflections based on the shininess + or roughness of the material used in the scene.

+

Note: The image's diffuse light will be affected by fill() + and the specular reflections will be affected by specularMaterial() + and shininess().

+line: 497 +params: + - name: img + description: | +

image for the background

+ type: p5.image +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/outdoor_image.jpg'); + } + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0 ,1, 0); + perspective(PI/3, 1, 5, 500); + } + function draw() { + background(220); + + push(); + camera(0, 0, 1, 0, 0, 0, 0, 1, 0); + ortho(-1, 1, -1, 1, 0, 1); + noLights(); + noStroke(); + texture(img); + plane(2); + pop(); + + ambientLight(50); + imageLight(img); + specularMaterial(20); + noStroke(); + rotateX(frameCount * 0.005); + rotateY(frameCount * 0.005); + box(50); + } + +
+ - |- + +
+ + let img; + let slider; + + function preload() { + img = loadImage('assets/outdoor_spheremap.jpg'); + } + function setup() { + createCanvas(100, 100, WEBGL); + slider = createSlider(0, 400, 100, 1); + slider.position(0, height); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0 ,1, 0); + perspective(PI/3, 1, 5, 500); + } + function draw() { + background(220); + + push(); + camera(0, 0, 1, 0, 0, 0, 0, 1, 0); + ortho(-1, 1, -1, 1, 0, 1); + noLights(); + noStroke(); + texture(img); + plane(2); + pop(); + + ambientLight(50); + imageLight(img); + specularMaterial(20); + shininess(slider.value()); + noStroke(); + sphere(30); + } + +
+alt: light with slider having a slider for varying roughness +chainable: false +--- + + +# imageLight diff --git a/src/content/reference/en/p5/imageMode.mdx b/src/content/reference/en/p5/imageMode.mdx new file mode 100644 index 0000000000..cb2a955086 --- /dev/null +++ b/src/content/reference/en/p5/imageMode.mdx @@ -0,0 +1,103 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: imageMode +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: > +

Changes the location from which images are drawn when + + image() is called.

+ +

By default, the first + + two parameters of image() are the x- and + + y-coordinates of the image's upper-left corner. The next parameters are + + its width and height. This is the same as calling + imageMode(CORNER).

+ +

imageMode(CORNERS) also uses the first two parameters of + + image() as the x- and y-coordinates of the image's + + top-left corner. The third and fourth parameters are the coordinates of its + + bottom-right corner.

+ +

imageMode(CENTER) uses the first two parameters of + + image() as the x- and y-coordinates of the image's + + center. The next parameters are its width and height.

+line: 1262 +params: + - name: mode + description: | +

either CORNER, CORNERS, or CENTER.

+ type: Constant +itemtype: method +class: p5 +example: + - |- + + +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + background(200); + imageMode(CORNER); + image(img, 10, 10, 50, 50); + + describe('A square image of a brick wall is drawn at the top left of a gray square.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + background(200); + imageMode(CORNERS); + image(img, 10, 10, 90, 40); + + describe('An image of a brick wall is drawn on a gray square. The image is squeezed into a small rectangular area.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/bricks.jpg'); + } + + function setup() { + background(200); + imageMode(CENTER); + image(img, 50, 50, 80, 80); + + describe('A square image of a brick wall is drawn on a gray square.'); + } + +
+chainable: false +--- + + +# imageMode diff --git a/src/content/reference/en/p5/input.mdx b/src/content/reference/en/p5/input.mdx new file mode 100644 index 0000000000..6958bc54c0 --- /dev/null +++ b/src/content/reference/en/p5/input.mdx @@ -0,0 +1,76 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: input +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

myElement.input() sets a function to call when input is + detected within + + the p5.Element object. It's often used to with + + text inputs and sliders. Calling myElement.input(false) disables + the + + function.

+line: 371 +params: + - name: fxn + description: | +

function to call when input is detected within + the element. + false disables the function.

+ type: Function|Boolean +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Create a slider and place it beneath the canvas. + let slider = createSlider(0, 255, 200); + slider.position(0, 100); + + // When the slider changes, use its value to paint + // the background. + slider.input(() => { + let g = slider.value(); + background(g); + }); + + describe('A gray square with a range slider underneath it. The background changes shades of gray when the slider is moved.'); + } + +
+ +
+ + function setup() { + background(200); + + // Create an input and place it beneath the canvas. + let inp = createInput(''); + inp.position(0, 100); + + // When input is detected, paint the background gray + // and display the text. + inp.input(() => { + background(200); + let msg = inp.value(); + text(msg, 5, 50); + }); + + describe('A gray square with a text input bar beneath it. Any text written in the input appears in the middle of the square.'); + } + +
+chainable: true +--- + + +# input diff --git a/src/content/reference/en/p5/int.mdx b/src/content/reference/en/p5/int.mdx new file mode 100644 index 0000000000..f029fb06bd --- /dev/null +++ b/src/content/reference/en/p5/int.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: int +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a boolean, string, or float to its integer representation. + When an array of values is passed in, then an int array of the same length + is returned.

+line: 42 +itemtype: method +class: p5 +example: + - |- + +
+ print(int('10')); // 10 + print(int(10.31)); // 10 + print(int(-10)); // -10 + print(int(true)); // 1 + print(int(false)); // 0 + print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9] + print(int(Infinity)); // Infinity + print(int('-Infinity')); // -Infinity +
+return: + description: integer representation of value + type: Number +chainable: false +--- + + +# int diff --git a/src/content/reference/en/p5/isLooping.mdx b/src/content/reference/en/p5/isLooping.mdx new file mode 100644 index 0000000000..ac5562e1cc --- /dev/null +++ b/src/content/reference/en/p5/isLooping.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: isLooping +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

By default, p5.js loops through draw() + continuously, + + executing the code within it. If the sketch is stopped with + + noLoop() or resumed with loop(), + + isLooping() returns the current state for use within custom event + handlers.

+line: 133 +itemtype: method +class: p5 +example: + - |- + +
+ + let checkbox, button, colBG, colFill; + + function setup() { + createCanvas(100, 100); + + button = createButton('Colorize if loop()'); + button.position(0, 120); + button.mousePressed(changeBG); + + checkbox = createCheckbox('loop()', true); + checkbox.changed(checkLoop); + + colBG = color(0); + colFill = color(255); + } + + function changeBG() { + if (isLooping()) { + colBG = color(random(255), random(255), random(255)); + colFill = color(random(255), random(255), random(255)); + } + } + + function checkLoop() { + if (this.checked()) { + loop(); + } else { + noLoop(); + } + } + + function draw() { + background(colBG); + fill(colFill); + ellipse(frameCount % width, height / 2, 50); + } + +
+alt: |- + Ellipse moves slowly from left. Checkbox toggles loop()/noLoop(). + Button colorizes sketch if isLooping(). +return: + description: '' + type: Boolean +chainable: false +--- + + +# isLooping diff --git a/src/content/reference/en/p5/join.mdx b/src/content/reference/en/p5/join.mdx new file mode 100644 index 0000000000..ec293209aa --- /dev/null +++ b/src/content/reference/en/p5/join.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: join +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

Combines an array of Strings into one String, each separated by the + + character(s) used for the separator parameter. To join arrays of ints or + + floats, it's necessary to first convert them to Strings using nf() or + + nfs().

+line: 15 +params: + - name: list + description: | +

array of Strings to be joined

+ type: Array + - name: separator + description: | +

String to be placed between each item

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + let array = ['Hello', 'world!']; + let separator = ' '; + let message = join(array, separator); + text(message, 5, 50); + describe('“Hello world!” displayed middle left of canvas.'); + +
+return: + description: joined String + type: String +chainable: false +--- + + +# join diff --git a/src/content/reference/en/p5/key.mdx b/src/content/reference/en/p5/key.mdx new file mode 100644 index 0000000000..c5dec37919 --- /dev/null +++ b/src/content/reference/en/p5/key.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: key +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The system variable key always contains the value of the most recent + + key on the keyboard that was typed. To get the proper capitalization, it + + is best to use it within keyTyped(). For non-ASCII + keys, use the keyCode + + variable.

+line: 34 +itemtype: property +class: p5 +example: + - |- + +
+ // Click any key to display it! + // (Not Guaranteed to be Case Sensitive) + function setup() { + fill(245, 123, 158); + textSize(50); + } + + function draw() { + background(200); + text(key, 33, 65); // Display last key pressed. + describe('canvas displays any key value that is pressed in pink font.'); + } +
+chainable: false +--- + + +# key diff --git a/src/content/reference/en/p5/keyCode.mdx b/src/content/reference/en/p5/keyCode.mdx new file mode 100644 index 0000000000..6f0997c3dd --- /dev/null +++ b/src/content/reference/en/p5/keyCode.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyCode +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: | +

The variable keyCode is used to detect special keys such as BACKSPACE, + DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW, + DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW. + You can also check for custom keys by looking up the keyCode of any key + on a site like this: keycode.info.

+line: 60 +itemtype: property +class: p5 +example: + - |- + +
+ let fillVal = 126; + function draw() { + fill(fillVal); + rect(25, 25, 50, 50); + describe(`Grey rect center. turns white when up arrow pressed and black when down. + Display key pressed and its keyCode in a yellow box.`); + } + + function keyPressed() { + if (keyCode === UP_ARROW) { + fillVal = 255; + } else if (keyCode === DOWN_ARROW) { + fillVal = 0; + } + } +
+
+ function draw() {} + function keyPressed() { + background('yellow'); + text(`${key} ${keyCode}`, 10, 40); + print(key, ' ', keyCode); + } +
+chainable: false +--- + + +# keyCode diff --git a/src/content/reference/en/p5/keyIsDown.mdx b/src/content/reference/en/p5/keyIsDown.mdx new file mode 100644 index 0000000000..599594048c --- /dev/null +++ b/src/content/reference/en/p5/keyIsDown.mdx @@ -0,0 +1,97 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyIsDown +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The keyIsDown() function checks if the key is + currently down, i.e. pressed. + + It can be used if you have an object that moves, and you want several keys + + to be able to affect its behaviour simultaneously, such as moving a + + sprite diagonally. You can put in any number representing the keyCode of + + the key, or use any of the variable keyCode names + listed + + here.

+line: 301 +params: + - name: code + description: | +

The key to check for.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ let x = 100; + let y = 100; + + function setup() { + createCanvas(512, 512); + fill(255, 0, 0); + } + + function draw() { + if (keyIsDown(LEFT_ARROW)) { + x -= 5; + } + + if (keyIsDown(RIGHT_ARROW)) { + x += 5; + } + + if (keyIsDown(UP_ARROW)) { + y -= 5; + } + + if (keyIsDown(DOWN_ARROW)) { + y += 5; + } + + clear(); + ellipse(x, y, 50, 50); + describe(`50-by-50 red ellipse moves left, right, up, and + down with arrow presses.`); + } +
+ +
+ let diameter = 50; + + function setup() { + createCanvas(512, 512); + } + + function draw() { + // 107 and 187 are keyCodes for "+" + if (keyIsDown(107) || keyIsDown(187)) { + diameter += 1; + } + + // 109 and 189 are keyCodes for "-" + if (keyIsDown(109) || keyIsDown(189)) { + diameter -= 1; + } + + clear(); + fill(255, 0, 0); + ellipse(50, 50, diameter, diameter); + describe(`50-by-50 red ellipse gets bigger or smaller when + + or - are pressed.`); + } +
+return: + description: whether key is down or not + type: Boolean +chainable: false +--- + + +# keyIsDown diff --git a/src/content/reference/en/p5/keyIsPressed.mdx b/src/content/reference/en/p5/keyIsPressed.mdx new file mode 100644 index 0000000000..0be24214a1 --- /dev/null +++ b/src/content/reference/en/p5/keyIsPressed.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyIsPressed +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The boolean system variable keyIsPressed is + true if any key is pressed + + and false if no keys are pressed.

+line: 10 +itemtype: property +class: p5 +example: + - |- + +
+ + function draw() { + if (keyIsPressed === true) { + fill(0); + } else { + fill(255); + } + rect(25, 25, 50, 50); + describe('50-by-50 white rect that turns black on keypress.'); + } + +
+chainable: false +--- + + +# keyIsPressed diff --git a/src/content/reference/en/p5/keyPressed.mdx b/src/content/reference/en/p5/keyPressed.mdx new file mode 100644 index 0000000000..08b9161088 --- /dev/null +++ b/src/content/reference/en/p5/keyPressed.mdx @@ -0,0 +1,104 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyPressed +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The keyPressed() function is called once + every time a key is pressed. The + + keyCode for the key that was pressed is stored in the keyCode variable.

+ +

For non-ASCII keys, use the keyCode variable. You can check if the keyCode + + equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, + + OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.

+ +

For ASCII keys, the key that was pressed is stored in the key variable. + However, it + + does not distinguish between uppercase and lowercase. For this reason, it + + is recommended to use keyTyped() to read the key + variable, in which the + + case of the variable will be distinguished.

+ +

Because of how operating systems handle key repeats, holding down a key + + may cause multiple calls to keyTyped() (and keyReleased() as well). The + + rate of repeat is set by the operating system and how each computer is + + configured.

+ + Browsers may have different default + + behaviors attached to various key events. To prevent any default + + behavior for this event, add "return false" to the end of the method.

+line: 98 +params: + - name: event + description: | +

optional KeyboardEvent callback argument.

+ type: KeyboardEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black rect center. turns white when key pressed and black + when released.`); + } + function keyPressed() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+
+ + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black rect center. turns white when left arrow pressed and + black when right.`); + } + function keyPressed() { + if (keyCode === LEFT_ARROW) { + value = 255; + } else if (keyCode === RIGHT_ARROW) { + value = 0; + } + } + +
+
+ + function keyPressed() { + // Do something + return false; // prevent any default behaviour + } + +
+chainable: false +--- + + +# keyPressed diff --git a/src/content/reference/en/p5/keyReleased.mdx b/src/content/reference/en/p5/keyReleased.mdx new file mode 100644 index 0000000000..53e10915b1 --- /dev/null +++ b/src/content/reference/en/p5/keyReleased.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyReleased +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The keyReleased() function is called once + every time a key is released. + + See key and keyCode for more + information.

+ + Browsers may have different default + + behaviors attached to various key events. To prevent any default + + behavior for this event, add "return false" to the end of the function.

+line: 185 +params: + - name: event + description: | +

optional KeyboardEvent callback argument.

+ type: KeyboardEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black rect center. turns white when key pressed and black + when pressed again`); + } + function keyReleased() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + return false; // prevent any default behavior + } + +
+chainable: false +--- + + +# keyReleased diff --git a/src/content/reference/en/p5/keyTyped.mdx b/src/content/reference/en/p5/keyTyped.mdx new file mode 100644 index 0000000000..29351f4249 --- /dev/null +++ b/src/content/reference/en/p5/keyTyped.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: keyTyped +module: Events +submodule: Keyboard +file: src/events/keyboard.js +description: > +

The keyTyped() function is called once every + time a key is pressed, but + + action keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored. If + you are trying to detect + + a keyCode for one of these keys, use the keyPressed() function instead. + + The most recent key typed will be stored in the key variable.

+ +

Because of how operating systems handle key repeats, holding down a key + + will cause multiple calls to keyTyped() (and keyReleased() as well). The + + rate of repeat is set by the operating system and how each computer is + + configured.

+ + Browsers may have different default behaviors attached to various key + + events. To prevent any default behavior for this event, add "return false" + + to the end of the function.

+line: 237 +params: + - name: event + description: | +

optional KeyboardEvent callback argument.

+ type: KeyboardEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black rect center. turns white when 'a' key typed and + black when 'b' pressed`); + } + function keyTyped() { + if (key === 'a') { + value = 255; + } else if (key === 'b') { + value = 0; + } + // uncomment to prevent any default behavior + // return false; + } + +
+chainable: false +--- + + +# keyTyped diff --git a/src/content/reference/en/p5/lerp.mdx b/src/content/reference/en/p5/lerp.mdx new file mode 100644 index 0000000000..939238f381 --- /dev/null +++ b/src/content/reference/en/p5/lerp.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lerp +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates a number between two numbers at a specific increment. The + amt + + parameter is the amount to interpolate between the two numbers. 0.0 is + + equal to the first number, 0.1 is very near the first number, 0.5 is + + half-way in between, and 1.0 is equal to the second number. The + lerp() + + function is convenient for creating motion along a straight path and for + + drawing dotted lines.

+ +

If the value of amt is less than 0 or more than 1, + lerp() will return a + + number outside of the original interval. For example, calling + + lerp(0, 10, 1.5) will return 15.

+line: 239 +params: + - name: start + description: | +

first value.

+ type: Number + - name: stop + description: | +

second value.

+ type: Number + - name: amt + description: | +

number.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + let a = 20; + + let b = 80; + + let c = lerp(a, b, 0.2); + + let d = lerp(a, b, 0.5); + + let e = lerp(a, b, 0.8); + + + let y = 50; + + + strokeWeight(5); + + + // Draw the original points in black. + + stroke(0); + + point(a, y); + + point(b, y); + + + // Draw the lerped points in gray. + + stroke(100); + + point(c, y); + + point(d, y); + + point(e, y); + + + describe('Five points in a horizontal line. The outer points are black and + the inner points are gray.'); + + + +
+return: + description: lerped value. + type: Number +chainable: false +--- + + +# lerp diff --git a/src/content/reference/en/p5/lerpColor.mdx b/src/content/reference/en/p5/lerpColor.mdx new file mode 100644 index 0000000000..b8aa3f9549 --- /dev/null +++ b/src/content/reference/en/p5/lerpColor.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lerpColor +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: > +

Blends two colors to find a third color between them. The amt + parameter + + specifies the amount to interpolate between the two values. 0 is equal to + + the first color, 0.1 is very near the first color, 0.5 is halfway between + + the two colors, and so on. Negative numbers are set to 0. Numbers greater + + than 1 are set to 1. This differs from the behavior of + + lerp. It's necessary because numbers outside of the + + interval [0, 1] will produce strange and unexpected colors.

+ +

The way that colors are interpolated depends on the current + + colorMode().

+line: 368 +params: + - name: c1 + description: | +

interpolate from this color.

+ type: p5.Color + - name: c2 + description: | +

interpolate to this color.

+ type: p5.Color + - name: amt + description: | +

number between 0 and 1.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + colorMode(RGB); + stroke(255); + background(51); + const from = color(218, 165, 32); + const to = color(72, 61, 139); + colorMode(RGB); + const interA = lerpColor(from, to, 0.33); + const interB = lerpColor(from, to, 0.66); + fill(from); + rect(10, 20, 20, 60); + fill(interA); + rect(30, 20, 20, 60); + fill(interB); + rect(50, 20, 20, 60); + fill(to); + rect(70, 20, 20, 60); + describe( + 'Four rectangles with white edges. From left to right, the rectangles are tan, brown, brownish purple, and purple.' + ); + +
+return: + description: interpolated color. + type: p5.Color +chainable: false +--- + + +# lerpColor diff --git a/src/content/reference/en/p5/let.mdx b/src/content/reference/en/p5/let.mdx new file mode 100644 index 0000000000..d910912631 --- /dev/null +++ b/src/content/reference/en/p5/let.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: let +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

Creates and names a new variable. A variable is a container for a + value.

+ +

Variables that are declared with let will have + block-scope. + + This means that the variable only exists within the + + + + block that it is created within.

+ +

From the + MDN entry: + + Declares a block scope local variable, optionally initializing it to a + value.

+line: 7 +itemtype: property +class: p5 +example: + - |- + +
+ + let x = 2; + console.log(x); // prints 2 to the console + x = 1; + console.log(x); // prints 1 to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# let diff --git a/src/content/reference/en/p5/lightFalloff.mdx b/src/content/reference/en/p5/lightFalloff.mdx new file mode 100644 index 0000000000..9bb7d8c87a --- /dev/null +++ b/src/content/reference/en/p5/lightFalloff.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lightFalloff +module: 3D +submodule: Lights +file: src/webgl/light.js +description: > +

Sets the falloff rate for pointLight() + + and spotLight().

+ +

lightFalloff() affects only the lights which are created after it + + in the code.

+ +

The constant, linear, an quadratic + parameters are used to calculate falloff as follows:

+ +

d = distance from light position to vertex position

+ +

falloff = 1 / (CONSTANT + d * LINEAR + (d * d) * QUADRATIC)

+line: 646 +params: + - name: constant + description: | +

CONSTANT value for determining falloff

+ type: Number + - name: linear + description: | +

LINEAR value for determining falloff

+ type: Number + - name: quadratic + description: | +

QUADRATIC value for determining falloff

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + describe( + 'Two spheres with different falloff values show different intensity of light' + ); + } + function draw() { + background(125); + + let locX = mouseX - width / 2; + let locY = mouseY - height / 2; + locX /= 2; // half scale + + lightFalloff(1, 0, 0); + push(); + translate(-25, 0, 0); + pointLight(250, 250, 250, locX - 25, locY, 50); + sphere(20); + pop(); + + lightFalloff(0.97, 0.03, 0); + push(); + translate(25, 0, 0); + pointLight(250, 250, 250, locX + 25, locY, 50); + sphere(20); + pop(); + } + +
+alt: Two spheres with different falloff values show different intensity of light +chainable: true +--- + + +# lightFalloff diff --git a/src/content/reference/en/p5/lightness.mdx b/src/content/reference/en/p5/lightness.mdx new file mode 100644 index 0000000000..25b1784743 --- /dev/null +++ b/src/content/reference/en/p5/lightness.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lightness +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the HSL lightness value from a + p5.Color object, array of color components, or + CSS color string.

+line: 474 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - >- + +
+ + + + noStroke(); + + colorMode(HSL); + + const c = color(156, 100, 50, 1); + + fill(c); + + rect(15, 20, 35, 60); + + // Sets 'lightValue' to 50. + + const lightValue = lightness(c); + + fill(lightValue); + + rect(50, 20, 35, 60); + + describe('Two rectangles. The rectangle on the left is light green and the + one on the right is gray.'); + + + +
+return: + description: the lightness + type: Number +chainable: false +--- + + +# lightness diff --git a/src/content/reference/en/p5/lights.mdx b/src/content/reference/en/p5/lights.mdx new file mode 100644 index 0000000000..27d3fc909a --- /dev/null +++ b/src/content/reference/en/p5/lights.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: lights +module: 3D +submodule: Lights +file: src/webgl/light.js +description: | +

Places an ambient and directional light in the scene. + The lights are set to ambientLight(128, 128, 128) and + directionalLight(128, 128, 128, 0, 0, -1).

+

Note: lights need to be called (whether directly or indirectly) + within draw() to remain persistent in a looping program. + Placing them in setup() will cause them to only have an effect + the first time through the loop.

+line: 602 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + describe('the light is partially ambient and partially directional'); + } + function draw() { + background(0); + lights(); + rotateX(millis() / 1000); + rotateY(millis() / 1000); + rotateZ(millis() / 1000); + box(); + } + +
+alt: the light is partially ambient and partially directional +chainable: true +--- + + +# lights diff --git a/src/content/reference/en/p5/line.mdx b/src/content/reference/en/p5/line.mdx new file mode 100644 index 0000000000..45b92b7d9f --- /dev/null +++ b/src/content/reference/en/p5/line.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: line +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws a line, a straight path between two points. Its default width is one + pixel. + + The version of line() with four parameters draws the line in 2D. + To color a line, + + use the stroke() function. To change its width, use + the + + strokeWeight() function. A line + + can't be filled, so the fill() function won't affect + + the color of a line.

+ +

The version of line() with six parameters allows the line to + be drawn in 3D + + space. Doing so requires adding the WEBGL argument to + + createCanvas().

+line: 334 +itemtype: method +class: p5 +example: + - | + +
+ + line(30, 20, 85, 75); + describe( + 'A black line on a gray canvas running from top-center to bottom-right.' + ); + +
+ +
+ + line(30, 20, 85, 20); + stroke(126); + line(85, 20, 85, 75); + stroke(255); + line(85, 75, 30, 75); + describe( + 'Three lines drawn in grayscale on a gray canvas. They form the top, right, and bottom sides of a square.' + ); + +
+ +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe('A black line drawn on a gray canvas.'); + } + + function draw() { + background(220); + line(0, 0, 0, 10, 10, 0); + } + +
+chainable: true +--- + + +# line diff --git a/src/content/reference/en/p5/loadBytes.mdx b/src/content/reference/en/p5/loadBytes.mdx new file mode 100644 index 0000000000..e7dbe3dacb --- /dev/null +++ b/src/content/reference/en/p5/loadBytes.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadBytes +module: IO +submodule: Input +file: src/io/files.js +description: | +

This method is suitable for fetching files up to size of 64MB.

+line: 683 +params: + - name: file + description: | +

name of the file or URL to load

+ type: String + - name: callback + description: | +

function to be executed after loadBytes() + completes

+ type: Function + optional: true + - name: errorCallback + description: | +

function to be executed if there + is an error

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ let data; + + function preload() { + data = loadBytes('assets/mammals.xml'); + } + + function setup() { + for (let i = 0; i < 5; i++) { + console.log(data.bytes[i].toString(16)); + } + describe('no image displayed'); + } +
+return: + description: an object whose 'bytes' property will be the loaded buffer + type: Object +chainable: false +--- + + +# loadBytes diff --git a/src/content/reference/en/p5/loadFont.mdx b/src/content/reference/en/p5/loadFont.mdx new file mode 100644 index 0000000000..c39a4f0ab0 --- /dev/null +++ b/src/content/reference/en/p5/loadFont.mdx @@ -0,0 +1,165 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadFont +module: Typography +submodule: Loading & Displaying +file: src/typography/loading_displaying.js +description: > +

Loads a font and creates a p5.Font object. + + loadFont() can load fonts in either .otf or .ttf format. Loaded + fonts can + + be used to style text on the canvas and in HTML elements.

+ +

The first parameter, path, is the path to a font file. + + Paths to local files should be relative. For example, + + 'assets/inconsolata.otf'. The Inconsolata font used in the + following + + examples can be downloaded for free + + here. + + Paths to remote files should be URLs. For example, + + 'https://example.com/inconsolata.otf'. URLs may be blocked due to + browser + + security.

+ +

The second parameter, successCallback, is optional. If a + function is + + passed, it will be called once the font has loaded. The callback function + + may use the new p5.Font object if needed.

+ +

The third parameter, failureCallback, is also optional. If a + function is + + passed, it will be called if the font fails to load. The callback function + + may use the error + + Event + + object if needed.

+ +

Fonts can take time to load. Calling loadFont() in + + preload() ensures fonts load before they're + + used in setup() or + + draw().

+line: 16 +params: + - name: path + description: | +

path of the font to be loaded.

+ type: String + - name: successCallback + description: | +

function called with the + p5.Font object after it + loads.

+ type: Function + optional: true + - name: failureCallback + description: | +

function called with the error + Event + object if the font fails to load.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + + +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + fill('deeppink'); + textFont(font); + textSize(36); + text('p5*js', 10, 50); + + describe('The text "p5*js" written in pink on a white background.'); + } + +
+ +
+ + function setup() { + loadFont('assets/inconsolata.otf', font => { + fill('deeppink'); + textFont(font); + textSize(36); + text('p5*js', 10, 50); + + describe('The text "p5*js" written in pink on a white background.'); + }); + } + +
+ +
+ + function setup() { + loadFont('assets/inconsolata.otf', success, failure); + } + + function success(font) { + fill('deeppink'); + textFont(font); + textSize(36); + text('p5*js', 10, 50); + + describe('The text "p5*js" written in pink on a white background.'); + } + + function failure(event) { + console.error('Oops!', event); + } + +
+ +
+ + function preload() { + loadFont('assets/inconsolata.otf'); + } + + function setup() { + let p = createP('p5*js'); + p.style('color', 'deeppink'); + p.style('font-family', 'Inconsolata'); + p.style('font-size', '36px'); + p.position(10, 50); + + describe('The text "p5*js" written in pink on a white background.'); + } + +
+return: + description: p5.Font object. + type: p5.Font +chainable: false +--- + + +# loadFont diff --git a/src/content/reference/en/p5/loadImage.mdx b/src/content/reference/en/p5/loadImage.mdx new file mode 100644 index 0000000000..f5b8c3d0f7 --- /dev/null +++ b/src/content/reference/en/p5/loadImage.mdx @@ -0,0 +1,117 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadImage +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: > +

Loads an image to create a p5.Image object.

+ +

loadImage() interprets the first parameter one of three ways. + If the path + + to an image file is provided, loadImage() will load it. Paths to + local + + files should be relative, such as 'assets/thundercat.jpg'. URLs + such as + + 'https://example.com/thundercat.jpg' may be blocked due to + browser + + security. Raw image data can also be passed as a base64 encoded image in + + the form 'data:image/png;base64,arandomsequenceofcharacters'.

+ +

The second parameter is optional. If a function is passed, it will be + + called once the image has loaded. The callback function can optionally use + + the new p5.Image object.

+ +

The third parameter is also optional. If a function is passed, it will be + + called if the image fails to load. The callback function can optionally use + + the event error.

+ +

Images can take time to load. Calling loadImage() in + + preload() ensures images load before they're + + used in setup() or draw().

+line: 18 +params: + - name: path + description: | +

path of the image to be loaded or base64 encoded image.

+ type: String + - name: successCallback + description: | +

function called with + p5.Image once it + loads.

+ type: function(p5.Image) + optional: true + - name: failureCallback + description: | +

function called with event + error if the image fails to load.

+ type: Function(Event) + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + image(img, 0, 0); + describe('Image of the underside of a white umbrella and a gridded ceiling.'); + } + +
+ +
+ + function setup() { + loadImage('assets/laDefense.jpg', img => { + image(img, 0, 0); + }); + describe('Image of the underside of a white umbrella and a gridded ceiling.'); + } + +
+ +
+ + function setup() { + loadImage('assets/laDefense.jpg', success, failure); + } + + function success(img) { + image(img, 0, 0); + describe('Image of the underside of a white umbrella and a gridded ceiling.'); + } + + function failure(event) { + console.error('Oops!', event); + } + +
+return: + description: the p5.Image object. + type: p5.Image +chainable: false +--- + + +# loadImage diff --git a/src/content/reference/en/p5/loadJSON.mdx b/src/content/reference/en/p5/loadJSON.mdx new file mode 100644 index 0000000000..394736c3fc --- /dev/null +++ b/src/content/reference/en/p5/loadJSON.mdx @@ -0,0 +1,107 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadJSON +module: IO +submodule: Input +file: src/io/files.js +description: | +

Loads a JSON file from a file or a URL, and returns an Object. + Note that even if the JSON file contains an Array, an Object will be + returned with index numbers as keys.

+

This method is asynchronous, meaning it may not finish before the next + line in your sketch is executed. JSONP is supported via a polyfill and you + can pass in as the second argument an object with definitions of the json + callback following the syntax specified here.

+

This method is suitable for fetching files up to size of 64MB.

+line: 17 +itemtype: method +class: p5 +example: + - >- + + + Calling loadJSON() inside preload() guarantees to complete the + + operation before setup() and draw() are called. + + +
+ + // Examples use USGS Earthquake API: + + // https://earthquake.usgs.gov/fdsnws/event/1/#methods + + let earthquakes; + + function preload() { + // Get the most recent earthquake in the database + let url = + 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + + 'summary/all_day.geojson'; + earthquakes = loadJSON(url); + } + + + function setup() { + noLoop(); + } + + + function draw() { + background(200); + // Get the magnitude and name of the earthquake out of the loaded JSON + let earthquakeMag = earthquakes.features[0].properties.mag; + let earthquakeName = earthquakes.features[0].properties.place; + ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + textAlign(CENTER); + text(earthquakeName, 0, height - 30, width, 30); + describe(`50×50 ellipse that changes from black to white + depending on the current humidity`); + } + +
+ + + Outside of preload(), you may supply a callback function to handle the + + object: + +
+ + function setup() { + noLoop(); + let url = + 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + + 'summary/all_day.geojson'; + loadJSON(url, drawEarthquake); + } + + + function draw() { + background(200); + describe(`50×50 ellipse that changes from black to white + depending on the current humidity`); + } + + + function drawEarthquake(earthquakes) { + // Get the magnitude and name of the earthquake out of the loaded JSON + let earthquakeMag = earthquakes.features[0].properties.mag; + let earthquakeName = earthquakes.features[0].properties.place; + ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + textAlign(CENTER); + text(earthquakeName, 0, height - 30, width, 30); + } + +
+return: + description: JSON data + type: Object|Array +chainable: false +--- + + +# loadJSON diff --git a/src/content/reference/en/p5/loadModel.mdx b/src/content/reference/en/p5/loadModel.mdx new file mode 100644 index 0000000000..35961e6bb3 --- /dev/null +++ b/src/content/reference/en/p5/loadModel.mdx @@ -0,0 +1,121 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadModel +module: Shape +submodule: 3D Models +file: src/webgl/loading.js +description: > +

Load a 3d model from an OBJ or STL file.

+ +

loadModel() should be placed inside of preload(). + + This allows the model to load fully before the rest of your code is run.

+ +

One of the limitations of the OBJ and STL format is that it doesn't have a + built-in + + sense of scale. This means that models exported from different programs might + + be very different sizes. If your model isn't displaying, try calling + + loadModel() with the normalized parameter set to + true. This will resize the + + model to a scale appropriate for p5. You can also make additional changes to + + the final size of your model with the scale() + function.

+ +

Also, the support for colored STL files is not present. STL files with + color will be + + rendered without color properties.

+ +

Options can include:

+ + +line: 12 +itemtype: method +class: p5 +example: + - |- + +
+ + //draw a spinning octahedron + let octahedron; + + function preload() { + octahedron = loadModel('assets/octahedron.obj'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('Vertically rotating 3-d octahedron.'); + } + + function draw() { + background(200); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + model(octahedron); + } + +
+ - |- + +
+ + //draw a spinning teapot + let teapot; + + function preload() { + // Load model with normalise parameter set to true + teapot = loadModel('assets/teapot.obj', true); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('Vertically rotating 3-d teapot with red, green and blue gradient.'); + } + + function draw() { + background(200); + scale(0.4); // Scaled to make model fit into canvas + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + normalMaterial(); // For effect + model(teapot); + } + +
+alt: 'Vertically rotating 3-d teapot with red, green and blue gradient.' +return: + description: the p5.Geometry object + type: p5.Geometry +chainable: false +--- + + +# loadModel diff --git a/src/content/reference/en/p5/loadPixels.mdx b/src/content/reference/en/p5/loadPixels.mdx new file mode 100644 index 0000000000..6409f4046f --- /dev/null +++ b/src/content/reference/en/p5/loadPixels.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadPixels +module: Image +submodule: Pixels +file: src/image/pixels.js +description: | +

Loads the current value of each pixel on the canvas into the + pixels array. This + function must be called before reading from or writing to + pixels.

+line: 765 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0, width, height); + let d = pixelDensity(); + let halfImage = 4 * (d * width) * (d * height / 2); + loadPixels(); + for (let i = 0; i < halfImage; i += 1) { + pixels[i + halfImage] = pixels[i]; + } + updatePixels(); + + describe('Two identical images of mountain landscapes, one on top of the other.'); + } + +
+chainable: false +--- + + +# loadPixels diff --git a/src/content/reference/en/p5/loadShader.mdx b/src/content/reference/en/p5/loadShader.mdx new file mode 100644 index 0000000000..4641c16eda --- /dev/null +++ b/src/content/reference/en/p5/loadShader.mdx @@ -0,0 +1,87 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadShader +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Creates a new p5.Shader object + + from the provided vertex and fragment shader files.

+ +

The shader files are loaded asynchronously in the + + background, so this method should be used in preload().

+ +

Shaders can alter the positioning of shapes drawn with them. + + To ensure consistency in rendering, it's recommended to use the vertex shader + in the createShader example.

+ +

Note, shaders can only be used in WEBGL mode.

+line: 12 +params: + - name: vertFilename + description: | +

path to file containing vertex shader + source code

+ type: String + - name: fragFilename + description: | +

path to file containing fragment shader + source code

+ type: String + - name: callback + description: > +

callback to be executed after loadShader + + completes. On success, the p5.Shader object is passed as the first + argument.

+ type: Function + optional: true + - name: errorCallback + description: | +

callback to be executed when an error + occurs inside loadShader. On error, the error is passed as the first + argument.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let mandel; + function preload() { + // load the shader definitions from files + mandel = loadShader('assets/shader.vert', 'assets/shader.frag'); + } + function setup() { + createCanvas(100, 100, WEBGL); + // use the shader + shader(mandel); + noStroke(); + mandel.setUniform('p', [-0.74364388703, 0.13182590421]); + describe('zooming Mandelbrot set. a colorful, infinitely detailed fractal.'); + } + + function draw() { + mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); + quad(-1, -1, 1, -1, 1, 1, -1, 1); + } + +
+alt: 'zooming Mandelbrot set. a colorful, infinitely detailed fractal.' +return: + description: |- + a shader object created from the provided + vertex and fragment shader files. + type: p5.Shader +chainable: false +--- + + +# loadShader diff --git a/src/content/reference/en/p5/loadSound.mdx b/src/content/reference/en/p5/loadSound.mdx new file mode 100644 index 0000000000..d828c41023 --- /dev/null +++ b/src/content/reference/en/p5/loadSound.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadSound +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

loadSound() returns a new p5.SoundFile from a specified + path. If called during preload(), the p5.SoundFile will be ready + to play in time for setup() and draw(). If called outside of + preload, the p5.SoundFile will not be ready immediately, so + loadSound accepts a callback as the second parameter. Using a + + local server is recommended when loading external files.

+line: 2946 +params: + - name: path + description: | +

Path to the sound file, or an array with + paths to soundfiles in multiple formats + i.e. ['sound.ogg', 'sound.mp3']. + Alternately, accepts an object: either + from the HTML5 File API, or a p5.File.

+ type: String|Array + - name: successCallback + description: | +

Name of a function to call once file loads

+ type: Function + optional: true + - name: errorCallback + description: | +

Name of a function to call if there is + an error loading the file.

+ type: Function + optional: true + - name: whileLoading + description: | +

Name of a function to call while file is loading. + This function will receive the percentage loaded + so far, from 0.0 to 1.0.

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ let mySound; + function preload() { + soundFormats('mp3', 'ogg'); + mySound = loadSound('assets/doorbell'); + } + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(canvasPressed); + background(220); + text('tap here to play', 10, 20); + } + + function canvasPressed() { + // playing a sound file on a user gesture + // is equivalent to `userStartAudio()` + mySound.play(); + } +
+return: + description: Returns a p5.SoundFile + type: SoundFile +chainable: false +--- + + +# loadSound diff --git a/src/content/reference/en/p5/loadStrings.mdx b/src/content/reference/en/p5/loadStrings.mdx new file mode 100644 index 0000000000..f6d5806fea --- /dev/null +++ b/src/content/reference/en/p5/loadStrings.mdx @@ -0,0 +1,98 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadStrings +module: IO +submodule: Input +file: src/io/files.js +description: | +

Reads the contents of a file and creates a String array of its individual + lines. If the name of the file is used as the parameter, as in the above + example, the file must be located in the sketch directory/folder.

+

Alternatively, the file may be loaded from anywhere on the local + computer using an absolute path (something that starts with / on Unix and + Linux, or a drive letter on Windows), or the filename parameter can be a + URL for a file found on a network.

+

This method is asynchronous, meaning it may not finish before the next + line in your sketch is executed.

+

This method is suitable for fetching files up to size of 64MB.

+line: 180 +params: + - name: filename + description: | +

name of the file or url to load

+ type: String + - name: callback + description: > +

function to be executed after loadStrings() + completes, Array is passed in as first + argument

+ type: Function + optional: true + - name: errorCallback + description: | +

function to be executed if + there is an error, response is passed + in as first argument

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - >- + + + Calling loadStrings() inside preload() guarantees + to complete the + + operation before setup() and draw() are called. + + +
+ + let result; + + function preload() { + result = loadStrings('assets/test.txt'); + } + + + function setup() { + background(200); + text(random(result), 10, 10, 80, 80); + describe(`randomly generated text from a file, + for example "i smell like butter"`); + } + +
+ + + Outside of preload(), you may supply a callback function to handle the + + object: + + +
+ + function setup() { + loadStrings('assets/test.txt', pickString); + describe(`randomly generated text from a file, + for example "i have three feet"`); + } + + + function pickString(result) { + background(200); + text(random(result), 10, 10, 80, 80); + } + +
+return: + description: Array of Strings + type: 'String[]' +chainable: false +--- + + +# loadStrings diff --git a/src/content/reference/en/p5/loadTable.mdx b/src/content/reference/en/p5/loadTable.mdx new file mode 100644 index 0000000000..f940821424 --- /dev/null +++ b/src/content/reference/en/p5/loadTable.mdx @@ -0,0 +1,120 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadTable +module: IO +submodule: Input +file: src/io/files.js +description: > +

Reads the contents of a file or URL and creates a p5.Table object with + + its values. If a file is specified, it must be located in the sketch's + + "data" folder. The filename parameter can also be a URL to a file found + + online. By default, the file is assumed to be comma-separated (in CSV + + format). Table only looks for a header row if the 'header' option is + + included.

+ +

This method is asynchronous, meaning it may not finish before the next + + line in your sketch is executed. Calling loadTable() inside preload() + + guarantees to complete the operation before setup() + and draw() are called. + + Outside of preload(), you may supply a callback + function to handle the + + object:

+ +

All files loaded and saved use UTF-8 encoding. This method is suitable for + fetching files up to size of 64MB.

+line: 300 +params: + - name: filename + description: | +

name of the file or URL to load

+ type: String + - name: extension + description: | +

parse the table by comma-separated values "csv", semicolon-separated + values "ssv", or tab-separated values "tsv"

+ type: String + optional: true + - name: header + description: | +

"header" to indicate table has header row

+ type: String + optional: true + - name: callback + description: | +

function to be executed after + loadTable() completes. On success, the + Table object is passed in as the + first argument.

+ type: Function + optional: true + - name: errorCallback + description: | +

function to be executed if + there is an error, response is passed + in as first argument

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Given the following CSV file called "mammals.csv" + // located in the project's "assets" folder: + // + // id,species,name + // 0,Capra hircus,Goat + // 1,Panthera pardus,Leopard + // 2,Equus zebra,Zebra + + let table; + + function preload() { + //my table is comma separated value "csv" + //and has a header specifying the columns labels + table = loadTable('assets/mammals.csv', 'csv', 'header'); + //the file can be remote + //table = loadTable("http://p5js.org/reference/assets/mammals.csv", + // "csv", "header"); + } + + function setup() { + //count the columns + print(table.getRowCount() + ' total rows in table'); + print(table.getColumnCount() + ' total columns in table'); + + print(table.getColumn('name')); + //["Goat", "Leopard", "Zebra"] + + //cycle through the table + for (let r = 0; r < table.getRowCount(); r++) + for (let c = 0; c < table.getColumnCount(); c++) { + print(table.getString(r, c)); + } + describe(`randomly generated text from a file, + for example "i smell like butter"`); + } + +
+return: + description: Table object containing data + type: Object +chainable: false +--- + + +# loadTable diff --git a/src/content/reference/en/p5/loadXML.mdx b/src/content/reference/en/p5/loadXML.mdx new file mode 100644 index 0000000000..bfcce5e978 --- /dev/null +++ b/src/content/reference/en/p5/loadXML.mdx @@ -0,0 +1,102 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loadXML +module: IO +submodule: Input +file: src/io/files.js +description: > +

Reads the contents of a file and creates an XML object with its values. + + If the name of the file is used as the parameter, as in the above example, + + the file must be located in the sketch directory/folder.

+ +

Alternatively, the file maybe be loaded from anywhere on the local + + computer using an absolute path (something that starts with / on Unix and + + Linux, or a drive letter on Windows), or the filename parameter can be a + + URL for a file found on a network.

+ +

This method is asynchronous, meaning it may not finish before the next + + line in your sketch is executed. Calling loadXML() + inside preload() + + guarantees to complete the operation before setup() + and draw() are called.

+ +

Outside of preload(), you may supply a callback + function to handle the + + object.

+ +

This method is suitable for fetching files up to size of 64MB.

+line: 575 +params: + - name: filename + description: | +

name of the file or URL to load

+ type: String + - name: callback + description: | +

function to be executed after loadXML() + completes, XML object is passed in as + first argument

+ type: Function + optional: true + - name: errorCallback + description: | +

function to be executed if + there is an error, response is passed + in as first argument

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ // The following short XML file called "mammals.xml" is parsed + // in the code below. + // + // + // <mammals> + // <animal id="0" species="Capra hircus">Goat</animal> + // <animal id="1" species="Panthera pardus">Leopard</animal> + // <animal id="2" species="Equus zebra">Zebra</animal> + // </mammals> + + let xml; + + function preload() { + xml = loadXML('assets/mammals.xml'); + } + + function setup() { + let children = xml.getChildren('animal'); + + for (let i = 0; i < children.length; i++) { + let id = children[i].getNum('id'); + let coloring = children[i].getString('species'); + let name = children[i].getContent(); + print(id + ', ' + coloring + ', ' + name); + } + describe('no image displayed'); + } + + // Sketch prints: + // 0, Capra hircus, Goat + // 1, Panthera pardus, Leopard + // 2, Equus zebra, Zebra +
+return: + description: XML object containing data + type: Object +chainable: false +--- + + +# loadXML diff --git a/src/content/reference/en/p5/log.mdx b/src/content/reference/en/p5/log.mdx new file mode 100644 index 0000000000..092097b518 --- /dev/null +++ b/src/content/reference/en/p5/log.mdx @@ -0,0 +1,45 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: log +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the natural logarithm (the base-e logarithm) of a number. This + + function expects the n parameter to be a value greater than + 0.0.

+line: 289 +params: + - name: 'n' + description: | +

number greater than 0.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Invert the y-axis. + scale(1, -1); + translate(0, -height); + + let x = frameCount; + let y = 15 * log(x); + point(x, y); + + describe('A series of black dots that get higher slowly from left to right.'); + } + +
+return: + description: natural logarithm of n. + type: Number +chainable: false +--- + + +# log diff --git a/src/content/reference/en/p5/loop.mdx b/src/content/reference/en/p5/loop.mdx new file mode 100644 index 0000000000..a1bceb60b3 --- /dev/null +++ b/src/content/reference/en/p5/loop.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: loop +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

By default, p5.js loops through draw() continuously, executing the code + within + + it. However, the draw() loop may be stopped by calling + + noLoop(). In that case, the draw() + + loop can be resumed with loop().

+ +

Avoid calling loop() from inside setup().

+ +

Use isLooping() to check the current state of + loop().

+line: 82 +itemtype: method +class: p5 +example: + - |- + +
+ + let x = 0; + function setup() { + createCanvas(100, 100); + noLoop(); + } + + function draw() { + background(204); + x = x + 0.1; + if (x > width) { + x = 0; + } + line(x, 0, x, height); + } + + function mousePressed() { + loop(); + } + + function mouseReleased() { + noLoop(); + } + +
+alt: horizontal line moves slowly from left. Loops but stops on mouse press. +chainable: false +--- + + +# loop diff --git a/src/content/reference/en/p5/mag.mdx b/src/content/reference/en/p5/mag.mdx new file mode 100644 index 0000000000..5e26677ce9 --- /dev/null +++ b/src/content/reference/en/p5/mag.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mag +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the magnitude, or length, of a vector. A vector is like an arrow + + pointing in space. Vectors are commonly used for programming motion.

+ +

Vectors don't have a "start" position because the same arrow can be drawn + + anywhere. A vector's magnitude can be thought of as the distance from the + + origin (0, 0) to its tip at (x, y). mag(x, y) is a shortcut for + calling + + dist(0, 0, x, y).

+line: 315 +params: + - name: x + description: | +

first component.

+ type: Number + - name: 'y' + description: | +

second component.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + let x = 30; + + let y = 40; + + let m = mag(x, y); + + + line(0, 0, x, y); + + text(m, x, y); + + + describe('A diagonal line is drawn from the top left of the canvas. The + number 50 is written at the end of the line.'); + + + +
+return: + description: 'magnitude of vector from (0,0) to (x,y).' + type: Number +chainable: false +--- + + +# mag diff --git a/src/content/reference/en/p5/map.mdx b/src/content/reference/en/p5/map.mdx new file mode 100644 index 0000000000..90a940442b --- /dev/null +++ b/src/content/reference/en/p5/map.mdx @@ -0,0 +1,90 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: map +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Re-maps a number from one range to another.

+ +

For example, calling map(2, 0, 10, 0, 100) returns 20. The + first three + + arguments set the original value to 2 and the original range from 0 to 10. + + The last two arguments set the target range from 0 to 100. 20's position + + in the target range [0, 100] is proportional to 2's position in the + + original range [0, 10].

+line: 347 +params: + - name: value + description: | +

the incoming value to be converted.

+ type: Number + - name: start1 + description: | +

lower bound of the value's current range.

+ type: Number + - name: stop1 + description: | +

upper bound of the value's current range.

+ type: Number + - name: start2 + description: | +

lower bound of the value's target range.

+ type: Number + - name: stop2 + description: | +

upper bound of the value's target range.

+ type: Number + - name: withinBounds + description: | +

constrain the value to the newly mapped range.

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let n = map(7, 0, 10, 0, 100); + text(n, 50, 50); + + describe('The number 70 written in the middle of a gray square.'); + +
+ +
+ + let x = map(2, 0, 10, 0, width); + circle(x, 50, 10); + + describe('A white circle drawn on the left side of a gray square.'); + +
+ +
+ + function draw() { + background(200); + + let c = map(mouseX, 0, width, 0, 255); + fill(c); + circle(50, 50, 20); + + describe('A circle changes color from black to white as the mouse moves from left to right.'); + } + +
+return: + description: remapped number. + type: Number +chainable: false +--- + + +# map diff --git a/src/content/reference/en/p5/match.mdx b/src/content/reference/en/p5/match.mdx new file mode 100644 index 0000000000..d9ae0898b2 --- /dev/null +++ b/src/content/reference/en/p5/match.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: match +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: | +

This function is used to apply a regular expression to a piece of text, + and return matching groups (elements found inside parentheses) as a + String array. If there are no matches, a null value will be returned. + If no groups are specified in the regular expression, but the sequence + matches, an array of length 1 (with the matched text as the first element + of the array) will be returned.

+

To use the function, first check to see if the result is null. If the + result is null, then the sequence did not match at all. If the sequence + did match, an array is returned.

+

If there are groups (specified by sets of parentheses) in the regular + expression, then the contents of each will be returned in the array. + Element [0] of a regular expression match returns the entire matching + string, and the match groups start at element [1] (the first group is [1], + the second [2], and so on).

+line: 41 +params: + - name: str + description: | +

the String to be searched

+ type: String + - name: regexp + description: | +

the regexp to be used for matching

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + let string = 'Hello p5js*!'; + let regexp = 'p5js\\*'; + let m = match(string, regexp); + text(m, 5, 50); + describe('“p5js*” displayed middle left of canvas.'); + +
+return: + description: Array of Strings found + type: 'String[]' +chainable: false +--- + + +# match diff --git a/src/content/reference/en/p5/matchAll.mdx b/src/content/reference/en/p5/matchAll.mdx new file mode 100644 index 0000000000..0141f19fbc --- /dev/null +++ b/src/content/reference/en/p5/matchAll.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: matchAll +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: | +

This function is used to apply a regular expression to a piece of text, + and return a list of matching groups (elements found inside parentheses) + as a two-dimensional String array. If there are no matches, a null value + will be returned. If no groups are specified in the regular expression, + but the sequence matches, a two dimensional array is still returned, but + the second dimension is only of length one.

+

To use the function, first check to see if the result is null. If the + result is null, then the sequence did not match at all. If the sequence + did match, a 2D array is returned.

+

If there are groups (specified by sets of parentheses) in the regular + expression, then the contents of each will be returned in the array. + Assuming a loop with counter variable i, element [i][0] of a regular + expression match returns the entire matching string, and the match groups + start at element [i][1] (the first group is [i][1], the second [i][2], + and so on).

+line: 79 +params: + - name: str + description: | +

the String to be searched

+ type: String + - name: regexp + description: | +

the regexp to be used for matching

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + let string = 'Hello p5js*! Hello world!'; + let regexp = 'Hello'; + matchAll(string, regexp); + +
+return: + description: 2d Array of Strings found + type: 'String[]' +chainable: false +--- + + +# matchAll diff --git a/src/content/reference/en/p5/max.mdx b/src/content/reference/en/p5/max.mdx new file mode 100644 index 0000000000..205fc35ffa --- /dev/null +++ b/src/content/reference/en/p5/max.mdx @@ -0,0 +1,105 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: max +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Returns the largest value in a sequence of numbers.

+ +

The version of max() with one parameter interprets it as an + array of + + numbers and returns the largest number.

+ +

The version of max() with two or more parameters interprets + them as + + individual numbers and returns the largest number.

+line: 410 +itemtype: method +class: p5 +example: + - >- + +
+ + + + let m = max(10, 20); + + text(m, 50, 50); + + + describe('The number 20 written in the middle of a gray square.'); + + + +
+ + +
+ + + + let m = max([10, 20]); + + text(m, 50, 50); + + + describe('The number 20 written in the middle of a gray square.'); + + + +
+ + +
+ + + + let numbers = [2, 1, 5, 4, 8, 9]; + + + // Draw all of the numbers in the array. + + noStroke(); + + let spacing = 15; + + numbers.forEach((n, index) => { + let x = index * spacing; + let y = 25; + text(n, x, y); + }); + + + // Draw the maximum value in the array. + + let m = max(numbers); + + let maxX = 33; + + let maxY = 80; + + + textSize(32); + + text(m, maxX, maxY); + + + describe('The numbers 2 1 5 4 8 9 are written in small text at the top of a + gray square. The number 9 is written in large text at the center of the + square.'); + + + +
+return: + description: maximum number. + type: Number +chainable: false +--- + + +# max diff --git a/src/content/reference/en/p5/metalness.mdx b/src/content/reference/en/p5/metalness.mdx new file mode 100644 index 0000000000..f01b2c30f0 --- /dev/null +++ b/src/content/reference/en/p5/metalness.mdx @@ -0,0 +1,113 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: metalness +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the metalness property of a material used in 3D rendering.

+ +

The metalness property controls the degree to which the material + + appears metallic. A higher metalness value makes the material look + + more metallic, while a lower value makes it appear less metallic.

+ +

The default and minimum value is 0, indicating a non-metallic + appearance.

+ +

Unlike other materials, metals exclusively rely on reflections, + particularly + + those produced by specular lights (mirrorLike lights). They don't incorporate + + diffuse or ambient lighting. Metals use a fill color to influence the overall + + color of their reflections. Pick a fill color, and you can easily change the + + appearance of the metal surfaces. When no fill color is provided, it defaults + + to using white.

+line: 1186 +params: + - name: metallic + description: | + + type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + let slider; + let slider2; + function preload() { + img = loadImage('assets/outdoor_spheremap.jpg'); + } + function setup() { + createCanvas(100, 100, WEBGL); + slider = createSlider(0, 300, 100, 1); + let sliderLabel = createP('Metalness'); + sliderLabel.position(100, height - 25); + slider2 = createSlider(0, 350, 100); + slider2.position(0, height + 20); + slider2Label = createP('Shininess'); + slider2Label.position(100, height); + } + function draw() { + background(220); + imageMode(CENTER); + push(); + image(img, 0, 0, width, height); + clearDepth(); + pop(); + imageLight(img); + fill('gray'); + specularMaterial('gray'); + shininess(slider2.value()); + metalness(slider.value()); + noStroke(); + sphere(30); + } + +
+ - |- + +
+ + let slider; + let slider2; + function setup() { + createCanvas(100, 100, WEBGL); + slider = createSlider(0, 200, 100); + let sliderLabel = createP('Metalness'); + sliderLabel.position(100, height - 25); + slider2 = createSlider(0, 200, 2); + slider2.position(0, height + 25); + let slider2Label = createP('Shininess'); + slider2Label.position(100, height); + } + function draw() { + noStroke(); + background(100); + fill(255, 215, 0); + pointLight(255, 255, 255, 5000, 5000, 75); + specularMaterial('gray'); + ambientLight(100); + shininess(slider2.value()); + metalness(slider.value()); + rotateY(frameCount * 0.01); + torus(20, 10); + } + +
+chainable: false +--- + + +# metalness diff --git a/src/content/reference/en/p5/midiToFreq.mdx b/src/content/reference/en/p5/midiToFreq.mdx new file mode 100644 index 0000000000..919ab415f6 --- /dev/null +++ b/src/content/reference/en/p5/midiToFreq.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: midiToFreq +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns the frequency value of a MIDI note value. + General MIDI treats notes as integers where middle C + is 60, C# is 61, D is 62 etc. Useful for generating + musical frequencies with oscillators.

+line: 841 +params: + - name: midiNote + description: | +

The number of a MIDI note

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ let midiNotes = [60, 64, 67, 72]; + let noteIndex = 0; + let midiVal, freq; + + function setup() { + let cnv = createCanvas(100, 100); + cnv.mousePressed(startSound); + osc = new p5.TriOsc(); + env = new p5.Envelope(); + } + + function draw() { + background(220); + text('tap to play', 10, 20); + if (midiVal) { + text('MIDI: ' + midiVal, 10, 40); + text('Freq: ' + freq, 10, 60); + } + } + + function startSound() { + // see also: userStartAudio(); + osc.start(); + + midiVal = midiNotes[noteIndex % midiNotes.length]; + freq = midiToFreq(midiVal); + osc.freq(freq); + env.ramp(osc, 0, 1.0, 0); + + noteIndex++; + } +
+return: + description: Frequency value of the given MIDI note + type: Number +chainable: false +--- + + +# midiToFreq diff --git a/src/content/reference/en/p5/millis.mdx b/src/content/reference/en/p5/millis.mdx new file mode 100644 index 0000000000..d6730cfc27 --- /dev/null +++ b/src/content/reference/en/p5/millis.mdx @@ -0,0 +1,34 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: millis +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

Returns the number of milliseconds (thousandths of a second) since + + starting the sketch (when setup() is called). This information is + often + + used for timing events and animation sequences.

+line: 67 +itemtype: method +class: p5 +example: + - |- + +
+ + let millisecond = millis(); + text('Milliseconds \nrunning: \n' + millisecond, 5, 40); + describe('number of milliseconds since sketch has started displayed'); + +
+return: + description: the number of milliseconds since starting the sketch + type: Number +chainable: false +--- + + +# millis diff --git a/src/content/reference/en/p5/min.mdx b/src/content/reference/en/p5/min.mdx new file mode 100644 index 0000000000..a970d25a6b --- /dev/null +++ b/src/content/reference/en/p5/min.mdx @@ -0,0 +1,105 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: min +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Returns the smallest value in a sequence of numbers.

+ +

The version of min() with one parameter interprets it as an + array of + + numbers and returns the smallest number.

+ +

The version of min() with two or more parameters interprets + them as + + individual numbers and returns the smallest number.

+line: 488 +itemtype: method +class: p5 +example: + - >- + +
+ + + + let m = min(10, 20); + + text(m, 50, 50); + + + describe('The number 10 written in the middle of a gray square.'); + + + +
+ + +
+ + + + let m = min([10, 20]); + + text(m, 50, 50); + + + describe('The number 10 written in the middle of a gray square.'); + + + +
+ + +
+ + + + let numbers = [2, 1, 5, 4, 8, 9]; + + + // Draw all of the numbers in the array. + + noStroke(); + + let spacing = 15; + + numbers.forEach((n, index) => { + let x = index * spacing; + let y = 25; + text(n, x, y); + }); + + + // Draw the minimum value in the array. + + let m = min(numbers); + + let minX = 33; + + let minY = 80; + + + textSize(32); + + text(m, minX, minY); + + + describe('The numbers 2 1 5 4 8 9 are written in small text at the top of a + gray square. The number 1 is written in large text at the center of the + square.'); + + + +
+return: + description: minimum number. + type: Number +chainable: false +--- + + +# min diff --git a/src/content/reference/en/p5/minute.mdx b/src/content/reference/en/p5/minute.mdx new file mode 100644 index 0000000000..fa08a33636 --- /dev/null +++ b/src/content/reference/en/p5/minute.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: minute +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The minute() function + + returns the current minute as a value from 0 - 59.

+line: 48 +itemtype: method +class: p5 +example: + - |- + +
+ + let m = minute(); + text('Current minute: \n' + m, 5, 50); + describe('Current minute is displayed'); + +
+return: + description: the current minute + type: Integer +chainable: false +--- + + +# minute diff --git a/src/content/reference/en/p5/model.mdx b/src/content/reference/en/p5/model.mdx new file mode 100644 index 0000000000..f1e08804f3 --- /dev/null +++ b/src/content/reference/en/p5/model.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: model +module: Shape +submodule: 3D Models +file: src/webgl/loading.js +description: | +

Render a 3d model to the screen.

+line: 636 +params: + - name: model + description: | +

Loaded 3d model to be rendered

+ type: p5.Geometry +itemtype: method +class: p5 +example: + - |- + +
+ + //draw a spinning octahedron + let octahedron; + + function preload() { + octahedron = loadModel('assets/octahedron.obj'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('Vertically rotating 3-d octahedron.'); + } + + function draw() { + background(200); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + model(octahedron); + } + +
+alt: Vertically rotating 3-d octahedron. +chainable: false +--- + + +# model diff --git a/src/content/reference/en/p5/month.mdx b/src/content/reference/en/p5/month.mdx new file mode 100644 index 0000000000..3b3bcabb67 --- /dev/null +++ b/src/content/reference/en/p5/month.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: month +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The month() function + + returns the current month as a value from 1 - 12.

+line: 92 +itemtype: method +class: p5 +example: + - |- + +
+ + let m = month(); + text('Current month: \n' + m, 5, 50); + describe('Current month is displayed'); + +
+return: + description: the current month + type: Integer +chainable: false +--- + + +# month diff --git a/src/content/reference/en/p5/mouseButton.mdx b/src/content/reference/en/p5/mouseButton.mdx new file mode 100644 index 0000000000..1ee24e7256 --- /dev/null +++ b/src/content/reference/en/p5/mouseButton.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseButton +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

p5 automatically tracks if the mouse button is pressed and which + button is pressed. The value of the system variable mouseButton is either + LEFT, RIGHT, or CENTER depending on which button was pressed last. + Warning: different browsers may track mouseButton differently.

+line: 341 +itemtype: property +class: p5 +example: + - |- + +
+ + function draw() { + background(237, 34, 93); + fill(0); + + if (mouseIsPressed === true) { + if (mouseButton === LEFT) { + ellipse(50, 50, 50, 50); + } + if (mouseButton === RIGHT) { + rect(25, 25, 50, 50); + } + if (mouseButton === CENTER) { + triangle(23, 75, 50, 20, 78, 75); + } + } + + print(mouseButton); + describe(`50-by-50 black ellipse appears on center of fuchsia + canvas on mouse click/press.`); + } + +
+chainable: false +--- + + +# mouseButton diff --git a/src/content/reference/en/p5/mouseClicked.mdx b/src/content/reference/en/p5/mouseClicked.mdx new file mode 100644 index 0000000000..bf26df51fd --- /dev/null +++ b/src/content/reference/en/p5/mouseClicked.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseClicked +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The mouseClicked() function is called once + after a mouse button has been + + pressed and then released.

+ + Browsers handle clicks differently, so this function is only guaranteed to be + + run when the left mouse button is clicked. To handle other mouse buttons + + being pressed or released, see mousePressed() + or mouseReleased().

+ + Browsers may have different default + + behaviors attached to various mouse events. To prevent any default + + behavior for this event, add "return false" to the end of the function.

+line: 760 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Click within the image to change + // the value of the rectangle + // after the mouse has been clicked + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('black 50-by-50 rect turns white with mouse click/press.'); + } + + function mouseClicked() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+ +
+ + function mouseClicked() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function mouseClicked(event) { + console.log(event); + } + +
+chainable: false +--- + + +# mouseClicked diff --git a/src/content/reference/en/p5/mouseDragged.mdx b/src/content/reference/en/p5/mouseDragged.mdx new file mode 100644 index 0000000000..f073b93cc1 --- /dev/null +++ b/src/content/reference/en/p5/mouseDragged.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseDragged +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The mouseDragged() function is called once + every time the mouse moves and + + a mouse button is pressed. If no mouseDragged() function is defined, the + + touchMoved() function will be called instead if + it is defined.

+ + Browsers may have different default + + behaviors attached to various mouse events. To prevent any default + + behavior for this event, add "return false" to the end of the function.

+line: 521 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Drag the mouse across the page + // to change its value + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black 50-by-50 rect turns lighter with mouse click and + drag until white, resets`); + } + function mouseDragged() { + value = value + 5; + if (value > 255) { + value = 0; + } + } + +
+ +
+ + function mouseDragged() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function mouseDragged(event) { + console.log(event); + } + +
+chainable: false +--- + + +# mouseDragged diff --git a/src/content/reference/en/p5/mouseIsPressed.mdx b/src/content/reference/en/p5/mouseIsPressed.mdx new file mode 100644 index 0000000000..49f7996a47 --- /dev/null +++ b/src/content/reference/en/p5/mouseIsPressed.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseIsPressed +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The boolean system variable mouseIsPressed is true if the mouse is pressed + and false if not.

+line: 378 +itemtype: property +class: p5 +example: + - |- + +
+ + function draw() { + background(237, 34, 93); + fill(0); + + if (mouseIsPressed === true) { + ellipse(50, 50, 50, 50); + } else { + rect(25, 25, 50, 50); + } + + print(mouseIsPressed); + describe(`black 50-by-50 rect becomes ellipse with mouse click/press. + fuchsia background.`); + } + +
+chainable: false +--- + + +# mouseIsPressed diff --git a/src/content/reference/en/p5/mouseMoved.mdx b/src/content/reference/en/p5/mouseMoved.mdx new file mode 100644 index 0000000000..68dea0f7e4 --- /dev/null +++ b/src/content/reference/en/p5/mouseMoved.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseMoved +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The mouseMoved() function is called every + time the mouse moves and a mouse + + button is not pressed.

+ + Browsers may have different default + + behaviors attached to various mouse events. To prevent any default + + behavior for this event, add "return false" to the end of the method.

+line: 469 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Move the mouse across the page + // to change its value + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`black 50-by-50 rect becomes lighter with mouse movements until + white then resets no image displayed`); + } + function mouseMoved() { + value = value + 5; + if (value > 255) { + value = 0; + } + } + +
+ +
+ + function mouseMoved() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function mouseMoved(event) { + console.log(event); + } + +
+chainable: false +--- + + +# mouseMoved diff --git a/src/content/reference/en/p5/mousePressed.mdx b/src/content/reference/en/p5/mousePressed.mdx new file mode 100644 index 0000000000..a6576a4a4d --- /dev/null +++ b/src/content/reference/en/p5/mousePressed.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mousePressed +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The mousePressed() function is called once + after every time a mouse button + + is pressed. The mouseButton variable (see the related reference entry) + + can be used to determine which button has been pressed. If no + + mousePressed() function is defined, the touchStarted() function will be + + called instead if it is defined.

+ + Browsers may have different default + + behaviors attached to various mouse events. To prevent any default + + behavior for this event, add "return false" to the end of the function.

+line: 599 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Click anywhere in the webpage to change + // the color value of the rectangle + + let colorValue = 0; + function draw() { + fill(colorValue); + rect(25, 25, 50, 50); + describe('black 50-by-50 rect turns white with mouse click/press.'); + } + function mousePressed() { + if (colorValue === 0) { + colorValue = 255; + } else { + colorValue = 0; + } + } + +
+ +
+ + function mousePressed() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function mousePressed(event) { + console.log(event); + } + +
+chainable: false +--- + + +# mousePressed diff --git a/src/content/reference/en/p5/mouseReleased.mdx b/src/content/reference/en/p5/mouseReleased.mdx new file mode 100644 index 0000000000..e931c1579b --- /dev/null +++ b/src/content/reference/en/p5/mouseReleased.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseReleased +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The mouseReleased() function is called + every time a mouse button is + + released. If no mouseReleased() function is + defined, the touchEnded() + + function will be called instead if it is defined.

+ + Browsers may have different default + + behaviors attached to various mouse events. To prevent any default + + behavior for this event, add "return false" to the end of the function.

+line: 680 +params: + - name: event + description: | +

optional MouseEvent callback argument.

+ type: MouseEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Click within the image to change + // the value of the rectangle + // after the mouse has been clicked + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('black 50-by-50 rect turns white with mouse click/press.'); + } + function mouseReleased() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+ +
+ + function mouseReleased() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + +
+ +
+ + // returns a MouseEvent object + // as a callback argument + function mouseReleased(event) { + console.log(event); + } + +
+chainable: false +--- + + +# mouseReleased diff --git a/src/content/reference/en/p5/mouseWheel.mdx b/src/content/reference/en/p5/mouseWheel.mdx new file mode 100644 index 0000000000..2daacc7364 --- /dev/null +++ b/src/content/reference/en/p5/mouseWheel.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseWheel +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The function mouseWheel() is executed every + time a vertical mouse wheel + + event is detected either triggered by an actual mouse wheel or by a + + touchpad.

+ + The event.delta property returns the amount the mouse wheel + + have scrolled. The values can be positive or negative depending on the + + scroll direction (on macOS with "natural" scrolling enabled, the signs + + are inverted).

+ + Browsers may have different default behaviors attached to various + + mouse events. To prevent any default behavior for this event, add + + "return false" to the end of the method.

+ + Due to the current support of the "wheel" event on Safari, the function + + may only work as expected if "return false" is included while using + Safari.

+line: 908 +params: + - name: event + description: | +

optional WheelEvent callback argument.

+ type: WheelEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let pos = 25; + + function draw() { + background(237, 34, 93); + fill(0); + rect(25, pos, 50, 50); + describe(`black 50-by-50 rect moves up and down with vertical scroll. + fuchsia background`); + } + + function mouseWheel(event) { + print(event.delta); + //move the square according to the vertical scroll amount + pos += event.delta; + //uncomment to block page scrolling + //return false; + } + +
+chainable: false +--- + + +# mouseWheel diff --git a/src/content/reference/en/p5/mouseX.mdx b/src/content/reference/en/p5/mouseX.mdx new file mode 100644 index 0000000000..618dc0e93f --- /dev/null +++ b/src/content/reference/en/p5/mouseX.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseX +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable mouseX always contains the current horizontal + position of the mouse, relative to (0, 0) of the canvas. The value at + the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL. + If touch is used instead of mouse input, mouseX will hold the x value + of the most recent touch point.

+line: 80 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move the mouse across the canvas + function draw() { + background(244, 248, 252); + line(mouseX, 0, mouseX, 100); + describe('horizontal black line moves left and right with mouse x-position'); + } + +
+chainable: false +--- + + +# mouseX diff --git a/src/content/reference/en/p5/mouseY.mdx b/src/content/reference/en/p5/mouseY.mdx new file mode 100644 index 0000000000..e504359935 --- /dev/null +++ b/src/content/reference/en/p5/mouseY.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: mouseY +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable mouseY always contains the current vertical + position of the mouse, relative to (0, 0) of the canvas. The value at + the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL. + If touch is used instead of mouse input, mouseY will hold the y value + of the most recent touch point.

+line: 104 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move the mouse across the canvas + function draw() { + background(244, 248, 252); + line(0, mouseY, 100, mouseY); + describe('vertical black line moves up and down with mouse y-position'); + } + +
+chainable: false +--- + + +# mouseY diff --git a/src/content/reference/en/p5/movedX.mdx b/src/content/reference/en/p5/movedX.mdx new file mode 100644 index 0000000000..5b9c08484f --- /dev/null +++ b/src/content/reference/en/p5/movedX.mdx @@ -0,0 +1,41 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: movedX +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The variable movedX contains the horizontal movement of the mouse since the + last frame

+line: 12 +itemtype: property +class: p5 +example: + - |2- + +
+ + let x = 50; + function setup() { + rectMode(CENTER); + } + function draw() { + if (x > 48) { + x -= 2; + } else if (x < 48) { + x += 2; + } + x += floor(movedX / 5); + background(237, 34, 93); + fill(0); + rect(x, 50, 50, 50); + describe(`box moves left and right according to mouse movement + then slowly back towards the center`); + } + +
+chainable: false +--- + + +# movedX diff --git a/src/content/reference/en/p5/movedY.mdx b/src/content/reference/en/p5/movedY.mdx new file mode 100644 index 0000000000..c1dc03f53b --- /dev/null +++ b/src/content/reference/en/p5/movedY.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: movedY +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The variable movedY contains the vertical movement of the mouse since the + last frame

+line: 43 +itemtype: property +class: p5 +example: + - |- + +
+ + let y = 50; + function setup() { + rectMode(CENTER); + } + + function draw() { + if (y > 48) { + y -= 2; + } else if (y < 48) { + y += 2; + } + y += floor(movedY / 5); + background(237, 34, 93); + fill(0); + rect(50, y, 50, 50); + describe(`box moves up and down according to mouse movement then + slowly back towards the center`); + } + +
+chainable: false +--- + + +# movedY diff --git a/src/content/reference/en/p5/nf.mdx b/src/content/reference/en/p5/nf.mdx new file mode 100644 index 0000000000..e92b806625 --- /dev/null +++ b/src/content/reference/en/p5/nf.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: nf +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

Utility function for formatting numbers into strings. There are two + + versions: one for formatting floats, and one for formatting ints.

+ +

The values for the digits, left, and right parameters should always + + be positive integers.

+ +

(NOTE): Be cautious when using left and right parameters as it prepends + numbers of 0's if the parameter + + if greater than the current length of the number.

+ +

For example if number is 123.2 and left parameter passed is 4 which is + greater than length of 123 + + (integer part) i.e 3 than result will be 0123.2. Same case for right parameter + i.e. if right is 3 than + + the result will be 123.200.

+line: 126 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + let num1 = 321; + let num2 = -1321; + + noStroke(); + fill(0); + textSize(16); + + text(nf(num1, 4, 2), 10, 30); + text(nf(num2, 4, 2), 10, 80); + // Draw dividing line + stroke(120); + line(0, 50, width, 50); + + describe('“0321.00” middle top, “-1321.00” middle bottom canvas'); + } + +
+return: + description: formatted String + type: String +chainable: false +--- + + +# nf diff --git a/src/content/reference/en/p5/nfc.mdx b/src/content/reference/en/p5/nfc.mdx new file mode 100644 index 0000000000..80cf8e9c38 --- /dev/null +++ b/src/content/reference/en/p5/nfc.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: nfc +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: | +

Utility function for formatting numbers into strings and placing + appropriate commas to mark units of 1000. There are two versions: one + for formatting ints, and one for formatting an array of ints. The value + for the right parameter should always be a positive integer.

+line: 216 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + let num = 11253106.115; + let numArr = [1, 1, 2]; + + noStroke(); + fill(0); + textSize(12); + + // Draw formatted numbers + text(nfc(num, 4), 10, 30); + text(nfc(numArr, 2), 10, 80); + + // Draw dividing line + stroke(120); + line(0, 50, width, 50); + + describe('“11,253,106.115” top middle and “1.00,1.00,2.00” displayed bottom mid'); + } + +
+return: + description: formatted String + type: String +chainable: false +--- + + +# nfc diff --git a/src/content/reference/en/p5/nfp.mdx b/src/content/reference/en/p5/nfp.mdx new file mode 100644 index 0000000000..94085c0a4b --- /dev/null +++ b/src/content/reference/en/p5/nfp.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: nfp +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

Utility function for formatting numbers into strings. Similar to nf() but + + puts a "+" in front of positive numbers and a "-" in front of negative + + numbers. There are two versions: one for formatting floats, and one for + + formatting ints. The values for left, and right parameters + + should always be positive integers.

+line: 289 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + let num1 = 11253106.115; + let num2 = -11253106.115; + + noStroke(); + fill(0); + textSize(12); + + // Draw formatted numbers + text(nfp(num1, 4, 2), 10, 30); + text(nfp(num2, 4, 2), 10, 80); + + // Draw dividing line + stroke(120); + line(0, 50, width, 50); + + describe('“+11253106.11” top middle and “-11253106.11” displayed bottom middle'); + } + +
+return: + description: formatted String + type: String +chainable: false +--- + + +# nfp diff --git a/src/content/reference/en/p5/nfs.mdx b/src/content/reference/en/p5/nfs.mdx new file mode 100644 index 0000000000..2a99e22b06 --- /dev/null +++ b/src/content/reference/en/p5/nfs.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: nfs +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

Utility function for formatting numbers into strings. Similar to nf() but + + puts an additional "_" (space) in front of positive numbers just in case to + align it with negative + + numbers which includes "-" (minus) sign.

+ +

The main usecase of nfs() can be seen when one wants to align the digits + (place values) of a non-negative + + number with some negative number (See the example to get a clear picture). + + There are two versions: one for formatting float, and one for formatting + int.

+ +

The values for the digits, left, and right parameters should always be + positive integers.

+ +

(IMP): The result on the canvas basically the expected alignment can vary + based on the typeface you are using.

+ +

(NOTE): Be cautious when using left and right parameters as it prepends + numbers of 0's if the parameter + + if greater than the current length of the number.

+ +

For example if number is 123.2 and left parameter passed is 4 which is + greater than length of 123 + + (integer part) i.e 3 than result will be 0123.2. Same case for right parameter + i.e. if right is 3 than + + the result will be 123.200.

+line: 350 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + let num1 = 321; + let num2 = -1321; + + noStroke(); + fill(0); + textSize(16); + + // nfs() aligns num1 (positive number) with num2 (negative number) by + // adding a blank space in front of the num1 (positive number) + // [left = 4] in num1 add one 0 in front, to align the digits with num2 + // [right = 2] in num1 and num2 adds two 0's after both numbers + // To see the differences check the example of nf() too. + text(nfs(num1, 4, 2), 10, 30); + text(nfs(num2, 4, 2), 10, 80); + // Draw dividing line + stroke(120); + line(0, 50, width, 50); + + describe('“0321.00” top middle and “-1321.00” displayed bottom middle'); + } + +
+return: + description: formatted String + type: String +chainable: false +--- + + +# nfs diff --git a/src/content/reference/en/p5/noCanvas.mdx b/src/content/reference/en/p5/noCanvas.mdx new file mode 100644 index 0000000000..dffc0a0208 --- /dev/null +++ b/src/content/reference/en/p5/noCanvas.mdx @@ -0,0 +1,28 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noCanvas +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: > +

Removes the default canvas for a p5 sketch that doesn't require a + canvas

+line: 222 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + noCanvas(); + } + +
+alt: no image displayed +chainable: false +--- + + +# noCanvas diff --git a/src/content/reference/en/p5/noCursor.mdx b/src/content/reference/en/p5/noCursor.mdx new file mode 100644 index 0000000000..4bae90ddf3 --- /dev/null +++ b/src/content/reference/en/p5/noCursor.mdx @@ -0,0 +1,35 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noCursor +module: Environment +submodule: Environment +file: src/core/environment.js +description: | +

Hides the cursor from view.

+line: 440 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Hide the cursor. + noCursor(); + } + + function draw() { + background(200); + + circle(mouseX, mouseY, 10); + + describe('A white circle on a gray background. The circle follows the mouse as it moves. The cursor is hidden.'); + } + +
+chainable: false +--- + + +# noCursor diff --git a/src/content/reference/en/p5/noDebugMode.mdx b/src/content/reference/en/p5/noDebugMode.mdx new file mode 100644 index 0000000000..29311fe087 --- /dev/null +++ b/src/content/reference/en/p5/noDebugMode.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noDebugMode +module: 3D +submodule: Interaction +file: src/webgl/interaction.js +description: | +

Turns off debugMode() in a 3D sketch.

+line: 602 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + normalMaterial(); + debugMode(); + describe( + 'a 3D box is centered on a grid in a 3D sketch. an icon indicates the direction of each axis: a red line points +X, a green line +Y, and a blue line +Z. the grid and icon disappear when the spacebar is pressed.' + ); + } + + function draw() { + background(200); + orbitControl(); + box(15, 30); + // Press the spacebar to turn debugMode off! + if (keyIsDown(32)) { + noDebugMode(); + } + } + +
+alt: |- + a 3D box is centered on a grid in a 3D sketch. an icon + indicates the direction of each axis: a red line points +X, + a green line +Y, and a blue line +Z. the grid and icon disappear when the + spacebar is pressed. +chainable: false +--- + + +# noDebugMode diff --git a/src/content/reference/en/p5/noErase.mdx b/src/content/reference/en/p5/noErase.mdx new file mode 100644 index 0000000000..d7fffaf264 --- /dev/null +++ b/src/content/reference/en/p5/noErase.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noErase +module: Color +submodule: Setting +file: src/color/setting.js +description: | +

Ends erasing that was started with erase(). + The fill(), stroke(), and + blendMode() settings will return to what they + were prior to calling erase().

+line: 1086 +itemtype: method +class: p5 +example: + - >- + +
+ + + + background(235, 145, 15); + + noStroke(); + + fill(30, 45, 220); + + rect(30, 10, 10, 80); + + erase(); + + circle(50, 50, 60); + + noErase(); + + rect(70, 10, 10, 80); + + describe('An orange canvas with two tall blue rectangles. A circular hole in + the center erases the rectangle on the left but not the one on the right.'); + + + +
+chainable: true +--- + + +# noErase diff --git a/src/content/reference/en/p5/noFill.mdx b/src/content/reference/en/p5/noFill.mdx new file mode 100644 index 0000000000..ed76870f98 --- /dev/null +++ b/src/content/reference/en/p5/noFill.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noFill +module: Color +submodule: Setting +file: src/color/setting.js +description: | +

Disables setting the interior color of shapes. This is the same as making + the fill completely transparent. If both + noStroke() and + noFill() are called, nothing will be drawn to the + screen.

+line: 747 +itemtype: method +class: p5 +example: + - >- + +
+ + + + square(32, 10, 35); + + noFill(); + + square(32, 55, 35); + + describe('A white square on top of an empty square. Both squares have black + outlines.'); + + + +
+ + +
+ + + + function setup() { + createCanvas(100, 100, WEBGL); + } + + + function draw() { + background(0); + noFill(); + stroke(100, 100, 240); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + box(45, 45, 45); + describe('A purple cube wireframe spinning on a black canvas.'); + } + + + +
+chainable: true +--- + + +# noFill diff --git a/src/content/reference/en/p5/noLights.mdx b/src/content/reference/en/p5/noLights.mdx new file mode 100644 index 0000000000..b56b517363 --- /dev/null +++ b/src/content/reference/en/p5/noLights.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noLights +module: 3D +submodule: Lights +file: src/webgl/light.js +description: | +

Removes all lights present in a sketch.

+

All subsequent geometry is rendered without lighting (until a new + light is created with a call to one of the lighting functions + (lights(), + ambientLight(), + directionalLight(), + pointLight(), + spotLight()).

+line: 1108 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe( + 'Three white spheres. Each appears as a different color due to lighting.' + ); + } + function draw() { + background(200); + noStroke(); + + ambientLight(255, 0, 0); + translate(-30, 0, 0); + ambientMaterial(255); + sphere(13); + + noLights(); + translate(30, 0, 0); + ambientMaterial(255); + sphere(13); + + ambientLight(0, 255, 0); + translate(30, 0, 0); + ambientMaterial(255); + sphere(13); + } + +
+alt: |- + Three white spheres. Each appears as a different + color due to lighting. +chainable: true +--- + + +# noLights diff --git a/src/content/reference/en/p5/noLoop.mdx b/src/content/reference/en/p5/noLoop.mdx new file mode 100644 index 0000000000..ce4d70ae8c --- /dev/null +++ b/src/content/reference/en/p5/noLoop.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noLoop +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

Stops p5.js from continuously executing the code within draw(). + + If loop() is called, the code in draw() + + begins to run continuously again. If using noLoop() + + in setup(), it should be the last line inside the + block.

+ +

When noLoop() is used, it's not possible to + manipulate + + or access the screen inside event handling functions such as + + mousePressed() or + + keyPressed(). Instead, use those functions to + + call redraw() or loop(), + + which will run draw(), which can update the screen + + properly. This means that when noLoop() has been + + called, no drawing can happen, and functions like saveFrames() + + or loadPixels() may not be used.

+ +

Note that if the sketch is resized, redraw() will + + be called to update the sketch, even after noLoop() + + has been specified. Otherwise, the sketch would enter an odd state until + + loop() was called.

+ +

Use isLooping() to check the current state of + loop().

+line: 9 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + noLoop(); + } + + function draw() { + line(10, 10, 90, 90); + } + +
+ +
+ + let x = 0; + function setup() { + createCanvas(100, 100); + } + + function draw() { + background(204); + x = x + 0.1; + if (x > width) { + x = 0; + } + line(x, 0, x, height); + } + + function mousePressed() { + noLoop(); + } + + function mouseReleased() { + loop(); + } + +
+alt: |- + 113 pixel long line extending from top-left to bottom right of canvas. + horizontal line moves slowly from left. Loops but stops on mouse press. +chainable: false +--- + + +# noLoop diff --git a/src/content/reference/en/p5/noSmooth.mdx b/src/content/reference/en/p5/noSmooth.mdx new file mode 100644 index 0000000000..76a06d19f3 --- /dev/null +++ b/src/content/reference/en/p5/noSmooth.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noSmooth +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Draws all geometry with jagged (aliased) edges.

+ +

smooth() is active by default in 2D mode. It's + necessary to call + + noSmooth() to disable smoothing of geometry, + images, and fonts.

+ +

In WebGL mode, noSmooth() is active by default. + It's necessary + + to call smooth() to draw smooth (antialiased) + edges.

+line: 73 +itemtype: method +class: p5 +example: + - |- + +
+ + background(0); + noStroke(); + smooth(); + ellipse(30, 48, 36, 36); + noSmooth(); + ellipse(70, 48, 36, 36); + describe('Two pixelated white circles on a black background.'); + +
+chainable: true +--- + + +# noSmooth diff --git a/src/content/reference/en/p5/noStroke.mdx b/src/content/reference/en/p5/noStroke.mdx new file mode 100644 index 0000000000..3c8d2e3faf --- /dev/null +++ b/src/content/reference/en/p5/noStroke.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noStroke +module: Color +submodule: Setting +file: src/color/setting.js +description: | +

Disables drawing the stroke (outline). If both + noStroke() and + noFill() are called, nothing will be drawn to the + screen.

+line: 789 +itemtype: method +class: p5 +example: + - |- + +
+ + noStroke(); + square(20, 20, 60); + describe('A white square with no outline.'); + +
+ +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(0); + noStroke(); + fill(240, 150, 150); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + box(45, 45, 45); + describe('A pink cube with no edge outlines spinning on a black canvas.'); + } + +
+chainable: true +--- + + +# noStroke diff --git a/src/content/reference/en/p5/noTint.mdx b/src/content/reference/en/p5/noTint.mdx new file mode 100644 index 0000000000..84ea66b481 --- /dev/null +++ b/src/content/reference/en/p5/noTint.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noTint +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: | +

Removes the current tint set by tint() and restores + images to their original colors.

+line: 1223 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + function setup() { + tint('red'); + image(img, 0, 0); + noTint(); + image(img, 50, 0); + + describe('Two images of an umbrella and a ceiling side-by-side. The image on the left has a red tint.'); + } + +
+chainable: false +--- + + +# noTint diff --git a/src/content/reference/en/p5/noise.mdx b/src/content/reference/en/p5/noise.mdx new file mode 100644 index 0000000000..2729f4f5fd --- /dev/null +++ b/src/content/reference/en/p5/noise.mdx @@ -0,0 +1,222 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noise +module: Math +submodule: Noise +file: src/math/noise.js +description: > +

Returns random numbers that can be tuned to feel more organic. The values + + returned will always be between 0 and 1.

+ +

Values returned by random() and + + randomGaussian() can change by large + + amounts between function calls. By contrast, values returned by + noise() + + can be made "smooth". Calls to noise() with similar inputs will + produce + + similar outputs. noise() is used to create textures, motion, + shapes, + + terrains, and so on. Ken Perlin invented noise() while animating + the + + original Tron film in the 1980s.

+ +

noise() returns the same value for a given input while a + sketch is + + running. It produces different results each time a sketch runs. The + + noiseSeed() function can be used to generate + + the same sequence of Perlin noise values each time a sketch runs.

+ +

The character of the noise can be adjusted in two ways. The first way is to + + scale the inputs. noise() interprets inputs as coordinates. The + sequence + + of noise values will be smoother when the input coordinates are closer. The + + second way is to use the noiseDetail() + + function.

+ +

The version of noise() with one parameter computes noise + values in one + + dimension. This dimension can be thought of as space, as in + noise(x), or + + time, as in noise(t).

+ +

The version of noise() with two parameters computes noise + values in two + + dimensions. These dimensions can be thought of as space, as in + + noise(x, y), or space and time, as in noise(x, + t).

+ +

The version of noise() with three parameters computes noise + values in + + three dimensions. These dimensions can be thought of as space, as in + + noise(x, y, z), or space and time, as in noise(x, y, + t).

+line: 36 +params: + - name: x + description: | +

x-coordinate in noise space.

+ type: Number + - name: 'y' + description: | +

y-coordinate in noise space.

+ type: Number + optional: true + - name: z + description: | +

z-coordinate in noise space.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + let x = 100 * noise(0.005 * frameCount); + let y = 100 * noise(0.005 * frameCount + 10000); + + strokeWeight(5); + point(x, y); + + describe('A black dot moves randomly on a gray square.'); + } + +
+ +
+ + function draw() { + background(200); + + let noiseLevel = 100; + let noiseScale = 0.005; + // Scale input coordinate. + let nt = noiseScale * frameCount; + // Compute noise value. + let x = noiseLevel * noise(nt); + let y = noiseLevel * noise(nt + 10000); + // Render. + strokeWeight(5); + point(x, y); + + describe('A black dot moves randomly on a gray square.'); + } + +
+ +
+ + function draw() { + let noiseLevel = 100; + let noiseScale = 0.02; + // Scale input coordinate. + let x = frameCount; + let nx = noiseScale * x; + // Compute noise value. + let y = noiseLevel * noise(nx); + // Render. + line(x, 0, x, y); + + describe('A hilly terrain drawn in gray against a black sky.'); + } + +
+ +
+ + function draw() { + background(200); + + let noiseLevel = 100; + let noiseScale = 0.002; + for (let x = 0; x < width; x += 1) { + // Scale input coordinates. + let nx = noiseScale * x; + let nt = noiseScale * frameCount; + // Compute noise value. + let y = noiseLevel * noise(nx, nt); + // Render. + line(x, 0, x, y); + } + + describe('A calm sea drawn in gray against a black sky.'); + } + +
+ +
+ + let noiseLevel = 255; + let noiseScale = 0.01; + for (let y = 0; y < height; y += 1) { + for (let x = 0; x < width; x += 1) { + // Scale input coordinates. + let nx = noiseScale * x; + let ny = noiseScale * y; + // Compute noise value. + let c = noiseLevel * noise(nx, ny); + // Render. + stroke(c); + point(x, y); + } + } + + describe('A gray cloudy pattern.'); + +
+ +
+ + function draw() { + let noiseLevel = 255; + let noiseScale = 0.009; + for (let y = 0; y < height; y += 1) { + for (let x = 0; x < width; x += 1) { + // Scale input coordinates. + let nx = noiseScale * x; + let ny = noiseScale * y; + let nt = noiseScale * frameCount; + // Compute noise value. + let c = noiseLevel * noise(nx, ny, nt); + // Render. + stroke(c); + point(x, y); + } + } + + describe('A gray cloudy pattern that changes.'); + } + +
+return: + description: Perlin noise value at specified coordinates. + type: Number +chainable: false +--- + + +# noise diff --git a/src/content/reference/en/p5/noiseDetail.mdx b/src/content/reference/en/p5/noiseDetail.mdx new file mode 100644 index 0000000000..f6717a1812 --- /dev/null +++ b/src/content/reference/en/p5/noiseDetail.mdx @@ -0,0 +1,92 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noiseDetail +module: Math +submodule: Noise +file: src/math/noise.js +description: > +

Adjusts the character of the noise produced by the + + noise() function.

+ +

Perlin noise values are created by adding layers of noise together. The + + noise layers, called octaves, are similar to harmonics in music. Lower + + octaves contribute more to the output signal. They define the overall + + intensity of the noise. Higher octaves create finer-grained details.

+ +

By default, noise values are created by combining four octaves. Each higher + + octave contributes half as much (50% less) compared to its predecessor. + + noiseDetail() changes the number of octaves and the falloff + amount. For + + example, calling noiseDetail(6, 0.25) ensures that + + noise() will use six octaves. Each higher octave + + will contribute 25% as much (75% less) compared to its predecessor. Falloff + + values between 0 and 1 are valid. However, falloff values greater than 0.5 + + might result in noise values greater than 1.

+line: 277 +params: + - name: lod + description: | +

number of octaves to be used by the noise.

+ type: Number + - name: falloff + description: | +

falloff factor for each octave.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + let noiseLevel = 255; + + let noiseScale = 0.02; + + for (let y = 0; y < height; y += 1) { + for (let x = 0; x < width / 2; x += 1) { + // Scale input coordinates. + let nx = noiseScale * x; + let ny = noiseScale * y; + + // Compute noise value. + noiseDetail(6, 0.25); + let c = noiseLevel * noise(nx, ny); + // Render left side. + stroke(c); + point(x, y); + + // Compute noise value. + noiseDetail(4, 0.5); + c = noiseLevel * noise(nx, ny); + // Render right side. + stroke(c); + point(x + width / 2, y); + } + } + + + describe('Two gray cloudy patterns. The pattern on the right is cloudier + than the pattern on the left.'); + + + +
+chainable: false +--- + + +# noiseDetail diff --git a/src/content/reference/en/p5/noiseSeed.mdx b/src/content/reference/en/p5/noiseSeed.mdx new file mode 100644 index 0000000000..08a2019aa0 --- /dev/null +++ b/src/content/reference/en/p5/noiseSeed.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: noiseSeed +module: Math +submodule: Noise +file: src/math/noise.js +description: > +

Sets the seed value for noise(). By default, + + noise() produces different results each time + + a sketch is run. Calling noiseSeed() with a constant + + argument, such as noiseSeed(99), makes noise() + + produce the same results each time a sketch is run.

+line: 338 +params: + - name: seed + description: | +

seed value.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + noiseSeed(99); + background(255); + } + + function draw() { + let noiseLevel = 100; + let noiseScale = 0.005; + // Scale input coordinate. + let nt = noiseScale * frameCount; + // Compute noise value. + let x = noiseLevel * noise(nt); + // Render. + line(x, 0, x, height); + + describe('A black rectangle that grows randomly, first to the right and then to the left.'); + } + +
+chainable: false +--- + + +# noiseSeed diff --git a/src/content/reference/en/p5/norm.mdx b/src/content/reference/en/p5/norm.mdx new file mode 100644 index 0000000000..5635ba414e --- /dev/null +++ b/src/content/reference/en/p5/norm.mdx @@ -0,0 +1,59 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: norm +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Maps a number from one range to a value between 0 and 1.

+ +

For example, norm(2, 0, 10) returns 0.2. 2's position in the + original + + range [0, 10] is proportional to 0.2's position in the range [0, 1]. This + + is equivalent to calling map(2, 0, 10, 0, 1).

+ +

Numbers outside of the original range are not constrained between 0 and 1. + + Out-of-range values are often intentional and useful.

+line: 566 +params: + - name: value + description: | +

incoming value to be normalized.

+ type: Number + - name: start + description: | +

lower bound of the value's current range.

+ type: Number + - name: stop + description: | +

upper bound of the value's current range.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Set the range for RGB values from 0 to 1. + colorMode(RGB, 1); + + let r = norm(mouseX, 0, width); + background(r, 0, 0); + + describe('A square changes color from black to red as the mouse moves from left to right.'); + } + +
+return: + description: normalized number. + type: Number +chainable: false +--- + + +# norm diff --git a/src/content/reference/en/p5/normal.mdx b/src/content/reference/en/p5/normal.mdx new file mode 100644 index 0000000000..7a109df343 --- /dev/null +++ b/src/content/reference/en/p5/normal.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: NORMAL +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 601 +itemtype: property +class: p5 +chainable: false +--- + + +# NORMAL diff --git a/src/content/reference/en/p5/normalMaterial.mdx b/src/content/reference/en/p5/normalMaterial.mdx new file mode 100644 index 0000000000..490cbbc0a8 --- /dev/null +++ b/src/content/reference/en/p5/normalMaterial.mdx @@ -0,0 +1,40 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: normalMaterial +module: 3D +submodule: Material +file: src/webgl/material.js +description: | +

Sets the current material as a normal material.

+

A normal material is not affected by light. It is often used as + a placeholder material when debugging.

+

Surfaces facing the X-axis become red, those facing the Y-axis + become green, and those facing the Z-axis become blue.

+

You can view more materials in this + example.

+line: 824 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe('Sphere with normal material'); + } + + function draw() { + background(200); + normalMaterial(); + sphere(40); + } + +
+alt: Sphere with normal material +chainable: true +--- + + +# normalMaterial diff --git a/src/content/reference/en/p5/number.mdx b/src/content/reference/en/p5/number.mdx new file mode 100644 index 0000000000..11fe7de54e --- /dev/null +++ b/src/content/reference/en/p5/number.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: number +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

A number is one of the 7 primitive + data types in Javascript. + + A number can be a whole number or a decimal number.

+ +

The MDN + entry for number

+line: 331 +itemtype: property +class: p5 +example: + - |- + +
+ + let num = 46.5; + console.log(typeof num); // prints 'number' to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# number diff --git a/src/content/reference/en/p5/object.mdx b/src/content/reference/en/p5/object.mdx new file mode 100644 index 0000000000..dadba9e743 --- /dev/null +++ b/src/content/reference/en/p5/object.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: object +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

From MDN's + object basics: + An object is a collection of related data and/or + functionality (which usually consists of several variables and functions — + which are called properties and methods when they are inside objects.)

+line: 351 +itemtype: property +class: p5 +example: + - |2- + +
+ + let author = { + name: 'Ursula K Le Guin', + books: [ + 'The Left Hand of Darkness', + 'The Dispossessed', + 'A Wizard of Earthsea' + ] + }; + console.log(author.name); // prints 'Ursula K Le Guin' to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# object diff --git a/src/content/reference/en/p5/orbitControl.mdx b/src/content/reference/en/p5/orbitControl.mdx new file mode 100644 index 0000000000..f6739d222e --- /dev/null +++ b/src/content/reference/en/p5/orbitControl.mdx @@ -0,0 +1,100 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: orbitControl +module: 3D +submodule: Interaction +file: src/webgl/interaction.js +description: | +

Allows movement around a 3D sketch using a mouse or trackpad or touch. + Left-clicking and dragging or swipe motion will rotate the camera position + about the center of the sketch, right-clicking and dragging or multi-swipe + will pan the camera position without rotation, and using the mouse wheel + (scrolling) or pinch in/out will move the camera further or closer + from the center of the sketch. This function can be called with parameters + dictating sensitivity to mouse/touch movement along the X and Y axes. + Calling this function without parameters is equivalent to calling + orbitControl(1,1). To reverse direction of movement in either axis, + enter a negative number for sensitivity.

+line: 11 +params: + - name: sensitivityX + description: | +

sensitivity to mouse movement along X axis

+ type: Number + optional: true + - name: sensitivityY + description: | +

sensitivity to mouse movement along Y axis

+ type: Number + optional: true + - name: sensitivityZ + description: | +

sensitivity to scroll movement along Z axis

+ type: Number + optional: true + - name: options + description: > +

An optional object that can contain additional settings, + + disableTouchActions - Boolean, default value is true. + + Setting this to true makes mobile interactions smoother by preventing + + accidental interactions with the page while orbiting. But if you're + already + + doing it via css or want the default touch actions, consider setting it to + false. + + freeRotation - Boolean, default value is false. + + By default, horizontal movement of the mouse or touch pointer rotates the + camera + + around the y-axis, and vertical movement rotates the camera around the + x-axis. + + But if setting this option to true, the camera always rotates in the + direction + + the pointer is moving. For zoom and move, the behavior is the same + regardless of + + true/false.

+ type: Object + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + describe( + 'Camera orbits around a box when mouse is hold-clicked & then moved.' + ); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + function draw() { + background(200); + + // If you execute the line commented out instead of next line, the direction of rotation + // will be the direction the mouse or touch pointer moves, not around the X or Y axis. + orbitControl(); + // orbitControl(1, 1, 1, {freeRotation: true}); + + rotateY(0.5); + box(30, 50); + } + +
+alt: Camera orbits around a box when mouse is hold-clicked & then moved. +chainable: true +--- + + +# orbitControl diff --git a/src/content/reference/en/p5/ortho.mdx b/src/content/reference/en/p5/ortho.mdx new file mode 100644 index 0000000000..103f12991e --- /dev/null +++ b/src/content/reference/en/p5/ortho.mdx @@ -0,0 +1,101 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: ortho +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

Sets an orthographic projection for the current camera in a 3D sketch + + and defines a box-shaped viewing frustum within which objects are seen. + + In this projection, all objects with the same dimension appear the same + + size, regardless of whether they are near or far from the camera.

+ +

The parameters to this function specify the viewing frustum where + + left and right are the minimum and maximum x values, top and bottom are + + the minimum and maximum y values, and near and far are the minimum and + + maximum z values.

+ +

If no parameters are given, the following default is used: + + ortho(-width/2, width/2, -height/2, height/2, 0, max(width, height) + + 800).

+line: 196 +params: + - name: left + description: | +

camera frustum left plane

+ type: Number + optional: true + - name: right + description: | +

camera frustum right plane

+ type: Number + optional: true + - name: bottom + description: | +

camera frustum bottom plane

+ type: Number + optional: true + - name: top + description: | +

camera frustum top plane

+ type: Number + optional: true + - name: near + description: | +

camera frustum near plane

+ type: Number + optional: true + - name: far + description: | +

camera frustum far plane

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + //drag the mouse to look around! + //there's no vanishing point + function setup() { + createCanvas(100, 100, WEBGL); + ortho(); + describe( + 'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.' + ); + } + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateX(0.2); + rotateY(-0.2); + push(); + translate(-15, 0, sin(frameCount / 30) * 65); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 65); + box(30); + pop(); + } + +
+alt: >- + two 3D boxes move back and forth along same plane, rotating as mouse is + dragged. +chainable: true +--- + + +# ortho diff --git a/src/content/reference/en/p5/outputVolume.mdx b/src/content/reference/en/p5/outputVolume.mdx new file mode 100644 index 0000000000..470cd6a066 --- /dev/null +++ b/src/content/reference/en/p5/outputVolume.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: outputVolume +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

Scale the output of all sound in this sketch

+ Scaled between 0.0 (silence) and 1.0 (full volume). + 1.0 is the maximum amplitude of a digital sound, so multiplying + by greater than 1.0 may cause digital distortion. To + fade, provide a rampTime parameter. For more + complex fades, see the Envelope class. + +

Alternately, you can pass in a signal source such as an + oscillator to modulate the amplitude with an audio signal.

+

How This Works: When you load the p5.sound module, it + creates a single instance of p5sound. All sound objects in this + module output to p5sound before reaching your computer's output. + So if you change the amplitude of p5sound, it impacts all of the + sound in this module.

+ +

If no value is provided, returns a Web Audio API Gain Node

+line: 738 +params: + - name: volume + description: | +

Volume (amplitude) between 0.0 + and 1.0 or modulating signal/oscillator

+ type: Number|Object + - name: rampTime + description: | +

Fade for t seconds

+ type: Number + optional: true + - name: timeFromNow + description: | +

Schedule this event to happen at + t seconds in the future

+ type: Number + optional: true +itemtype: method +class: p5 +chainable: false +--- + + +# outputVolume diff --git a/src/content/reference/en/p5/p5.Camera.mdx b/src/content/reference/en/p5/p5.Camera.mdx new file mode 100644 index 0000000000..a9cb688bbc --- /dev/null +++ b/src/content/reference/en/p5/p5.Camera.mdx @@ -0,0 +1,119 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: p5.Camera +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

This class describes a camera for use in p5's + + + + WebGL mode. It contains camera position, orientation, and projection + + information necessary for rendering a 3D scene.

+ +

New p5.Camera objects can be made through the + + createCamera() function and controlled through + + the methods described below. A camera created in this way will use a default + + position in the scene and a default perspective projection until these + + properties are changed through the various methods available. It is possible + + to create multiple cameras, in which case the current camera + + can be set through the setCamera() method.

+ +

Note: + + The methods below operate in two coordinate systems: the 'world' coordinate + + system describe positions in terms of their relationship to the origin along + + the X, Y and Z axes whereas the camera's 'local' coordinate system + + describes positions from the camera's point of view: left-right, up-down, + + and forward-backward. The move() method, + + for instance, moves the camera along its own axes, whereas the + + setPosition() + + method sets the camera's position in world-space.

+ +

The camera object properties + + eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ + + which describes camera position, orientation, and projection + + are also accessible via the camera object generated using + + createCamera()

+line: 401 +params: + - name: rendererGL + description: | +

instance of WebGL renderer

+ type: RendererGL +example: + - |- + +
+ + let cam; + let delta = 0.01; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + cam = createCamera(); + cam.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + // set initial pan angle + cam.pan(-0.8); + describe( + 'camera view pans left and right across a series of rotating 3D boxes.' + ); + } + + function draw() { + background(200); + + // pan camera according to angle 'delta' + cam.pan(delta); + + // every 160 frames, switch direction + if (frameCount % 160 === 0) { + delta *= -1; + } + + rotateX(frameCount * 0.01); + translate(-100, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + } + +
+alt: camera view pans left and right across a series of rotating 3D boxes. +chainable: false +--- + + +# p5.Camera diff --git a/src/content/reference/en/p5/p5.Color.mdx b/src/content/reference/en/p5/p5.Color.mdx new file mode 100644 index 0000000000..4aeab46fb5 --- /dev/null +++ b/src/content/reference/en/p5/p5.Color.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Color +module: Color +submodule: Creating & Reading +file: src/color/p5.Color.js +description: > +

A class to describe a color. Each p5.Color object stores the + color mode + + and level maxes that were active during its construction. These values are + + used to interpret the arguments passed to the object's constructor. They + + also determine output formatting such as when + + saturation() is called.

+ +

Color is stored internally as an array of ideal RGBA values in floating + + point form, normalized from 0 to 1. These values are used to calculate the + + closest screen colors, which are RGBA levels from 0 to 255. Screen colors + + are sent to the renderer.

+ +

When different color representations are calculated, the results are cached + + for performance. These values are normalized, floating-point numbers.

+ +

color() is the recommended way to create an + instance + + of this class.

+isConstructor: true +line: 318 +params: + - name: pInst + description: | +

pointer to p5 instance.

+ type: P5 + optional: true + - name: vals + description: | +

an array containing the color values + for red, green, blue and alpha channel + or CSS color.

+ type: 'Number[]|String' +memberMethodPreviews: + toString: + description: | +

Returns the color formatted as a string. Doing so can be useful for + debugging, or for using p5.js with other libraries.

+ path: .././src/content/reference/en//p5.Color/toString + setRed: + description: | +

Sets the red component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+ path: .././src/content/reference/en//p5.Color/setRed + setGreen: + description: | +

Sets the green component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+ path: .././src/content/reference/en//p5.Color/setGreen + setBlue: + description: | +

Sets the blue component of a color. The range depends on the + colorMode(). In the default RGB mode it's + between 0 and 255.

+ path: .././src/content/reference/en//p5.Color/setBlue + setAlpha: + description: > +

Sets the alpha (transparency) value of a color. The range depends on + the + + colorMode(). In the default RGB mode it's + + between 0 and 255.

+ path: .././src/content/reference/en//p5.Color/setAlpha +--- + + +# p5.Color diff --git a/src/content/reference/en/p5/p5.Element.mdx b/src/content/reference/en/p5/p5.Element.mdx new file mode 100644 index 0000000000..3bc44e6442 --- /dev/null +++ b/src/content/reference/en/p5/p5.Element.mdx @@ -0,0 +1,434 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Element +module: DOM +submodule: DOM +file: src/core/p5.Element.js +description: > +

A class to describe an + + HTML element. + + Sketches can use many elements. Common elements include the drawing canvas, + + buttons, sliders, webcam feeds, and so on.

+ +

All elements share the methods of the p5.Element class. + They're created + + with functions such as createCanvas() and + + createButton().

+isConstructor: true +line: 9 +params: + - name: elt + description: | +

wrapped DOM element.

+ type: HTMLElement + - name: pInst + description: | +

pointer to p5 instance.

+ type: P5 + optional: true +memberMethodPreviews: + elt: + description: > +

Underlying + + HTMLElement + + object. Its properties and methods can be used directly.

+ path: .././src/content/reference/en//p5.Element/elt + parent: + description: > +

Attaches this element to a parent element.

+ +

For example, a <div></div> element may be used + as a box to + + hold two pieces of text, a header and a paragraph. The + + <div></div> is the parent element of both the + header and + + paragraph.

+ +

The parameter parent can have one of three types. + parent can be a + + string with the parent element's ID, as in + + myElement.parent('container'). It can also be another + + p5.Element object, as in + + myElement.parent(myDiv). Finally, parent can be + an HTMLElement + + object, as in myElement.parent(anotherElement).

+ +

Calling myElement.parent() without an argument returns + this element's + + parent.

+ path: .././src/content/reference/en//p5.Element/parent + id: + description: > +

Sets this element's ID using a given string.

+ +

Calling myElement.id() without an argument returns its ID + as a string.

+ path: .././src/content/reference/en//p5.Element/id + class: + description: > +

Adds a + + class attribute + + to the element.

+ +

Calling myElement.class() without an argument returns a + string with its current classes.

+ path: .././src/content/reference/en//p5.Element/class + mousePressed: + description: > +

Calls a function when the mouse is pressed over the element. + + Calling myElement.mousePressed(false) disables the + function.

+ +

Note: Some mobile browsers may also trigger this event when the element + + receives a quick tap.

+ path: .././src/content/reference/en//p5.Element/mousePressed + doubleClicked: + description: > +

Calls a function when the mouse is pressed twice over the element. + + Calling myElement.doubleClicked(false) disables the + function.

+ path: .././src/content/reference/en//p5.Element/doubleClicked + mouseWheel: + description: > +

Calls a function when the mouse wheel scrolls over th element.

+ +

The callback function, fxn, is passed an + event object. event has + + two numeric properties, deltaY and deltaX. + event.deltaY is + + negative if the mouse wheel rotates away from the user. It's positive if + + the mouse wheel rotates toward the user. event.deltaX is + positive if + + the mouse wheel moves to the right. It's negative if the mouse wheel moves + + to the left.

+ +

Calling myElement.mouseWheel(false) disables the + function.

+ path: .././src/content/reference/en//p5.Element/mouseWheel + mouseReleased: + description: | +

Calls a function when the mouse is released over the element. Calling + myElement.mouseReleased(false) disables the function.

+

Note: Some mobile browsers may also trigger this event when the element + receives a quick tap.

+ path: .././src/content/reference/en//p5.Element/mouseReleased + mouseClicked: + description: > +

Calls a function when the mouse is pressed and released over the + element. + + Calling myElement.mouseReleased(false) disables the + function.

+ +

Note: Some mobile browsers may also trigger this event when the element + + receives a quick tap.

+ path: .././src/content/reference/en//p5.Element/mouseClicked + mouseMoved: + description: | +

Calls a function when the mouse moves over the element. Calling + myElement.mouseMoved(false) disables the function.

+ path: .././src/content/reference/en//p5.Element/mouseMoved + mouseOver: + description: | +

Calls a function when the mouse moves onto the element. Calling + myElement.mouseOver(false) disables the function.

+ path: .././src/content/reference/en//p5.Element/mouseOver + mouseOut: + description: | +

Calls a function when the mouse moves off the element. Calling + myElement.mouseOut(false) disables the function.

+ path: .././src/content/reference/en//p5.Element/mouseOut + touchStarted: + description: | +

Calls a function when the element is touched. Calling + myElement.touchStarted(false) disables the function.

+

Note: Touch functions only work on mobile devices.

+ path: .././src/content/reference/en//p5.Element/touchStarted + touchMoved: + description: | +

Calls a function when the user touches the element and moves their + finger. Calling myElement.touchMoved(false) disables the + function.

+

Note: Touch functions only work on mobile devices.

+ path: .././src/content/reference/en//p5.Element/touchMoved + touchEnded: + description: | +

Calls a function when the user stops touching the element. Calling + myElement.touchMoved(false) disables the function.

+

Note: Touch functions only work on mobile devices.

+ path: .././src/content/reference/en//p5.Element/touchEnded + dragOver: + description: | +

Calls a function when a file is dragged over the element. Calling + myElement.dragOver(false) disables the function.

+ path: .././src/content/reference/en//p5.Element/dragOver + dragLeave: + description: | +

Calls a function when a file is dragged off the element. Calling + Calling myElement.dragLeave(false) disables the function.

+ path: .././src/content/reference/en//p5.Element/dragLeave + addClass: + description: | +

Adds specified class to the element.

+ path: .././src/content/reference/en//p5.Element/addClass + removeClass: + description: | +

Removes specified class from the element.

+ path: .././src/content/reference/en//p5.Element/removeClass + hasClass: + description: | +

Checks if specified class is already applied to element.

+ path: .././src/content/reference/en//p5.Element/hasClass + toggleClass: + description: | +

Toggles element class.

+ path: .././src/content/reference/en//p5.Element/toggleClass + child: + description: | +

Attaches the element as a child to the parent specified. + Accepts either a string ID, DOM node, or p5.Element. + If no argument is specified, an array of children DOM nodes is returned.

+ path: .././src/content/reference/en//p5.Element/child + center: + description: | +

Centers a p5.Element either vertically, horizontally, + or both, relative to its parent or according to + the body if the p5.Element has no parent. If no argument is passed + the p5.Element is aligned both vertically and horizontally.

+ path: .././src/content/reference/en//p5.Element/center + html: + description: | +

If an argument is given, sets the inner HTML of the element, + replacing any existing HTML. If true is included as a second + argument, HTML is appended instead of replacing existing HTML. + If no arguments are given, returns + the inner HTML of the element.

+ path: .././src/content/reference/en//p5.Element/html + position: + description: > +

Sets the position of the element. If no position type argument is + given, the + position will be relative to (0, 0) of the window. + Essentially, this sets position:absolute and left and top + properties of style. If an optional third argument specifying position type is given, + the x and y-coordinates will be interpreted based on the positioning scheme. + If no arguments given, the function returns the x and y position of the element. + found documentation on how to be more specific with object type + https://stackoverflow.com/questions/14714314/how-do-i-comment-object-literals-in-yuidoc

+ path: .././src/content/reference/en//p5.Element/position + style: + description: > +

Applies a style to an element by adding a + + CSS declaration.

+ +

The first parameter, property, is a string. If the name of + a style + + property is passed, as in myElement.style('color'), the + method returns + + the current value as a string or null if it hasn't been set. + If a + + property:style string is passed, as in + + myElement.style('color:deeppink'), the method sets + property to + + value.

+ +

The second parameter, value, is optional. It sets the + property's value. + + value can be a string, as in + + myElement.style('color', 'deeppink'), or a + + p5.Color object, as in + + myElement.style('color', myColor).

+ path: .././src/content/reference/en//p5.Element/style + attribute: + description: > +

Adds an + + attribute + + to the element. This method is useful for advanced tasks.

+ +

Most commonly-used attributes, such as id, can be set with + their + + dedicated methods. For example, nextButton.id('next') sets an + element's + + id attribute.

+ +

The first parameter, attr, is the attribute's name as a + string. Calling + + myElement.attribute('align') returns the attribute's current + value as a + + string or null if it hasn't been set.

+ +

The second parameter, value, is optional. It's a string + used to set the + + attribute's value. For example, calling + + myElement.attribute('align', 'center') sets the element's + horizontal + + alignment to center.

+ path: .././src/content/reference/en//p5.Element/attribute + removeAttribute: + description: > +

Removes an attribute from the element.

+ +

The parameter attr is the attribute's name as a string. + For example, + + calling myElement.removeAttribute('align') removes its + align + + attribute if it's been set.

+ path: .././src/content/reference/en//p5.Element/removeAttribute + value: + description: > +

Returns or sets the element's value.

+ +

Calling myElement.value() returns the element's current + value.

+ +

The parameter, value, is an optional number or string. If + provided, + + as in myElement.value(123), it's used to set the element's + value.

+ path: .././src/content/reference/en//p5.Element/value + show: + description: | +

Shows the current element.

+ path: .././src/content/reference/en//p5.Element/show + hide: + description: | +

Hides the current element.

+ path: .././src/content/reference/en//p5.Element/hide + size: + description: > +

Sets the element's width and height.

+ +

Calling myElement.size() without an argument returns the + element's size + + as an object with the properties width and + height. For example, + { width: 20, height: 10 }.

+

The first parameter, width, is optional. It's a number + used to set the + + element's width. Calling myElement.size(10)

+ +

The second parameter, 'height, is also optional. It's a number + used to set the element's height. For example, calling + myElement.size(20, 10)` sets the element's width to 20 pixels and + height + + to 10 pixels.

+ +

The constant AUTO can be used to adjust one dimension at a + time while + + maintaining the aspect ratio, which is width / height. For + example, + + consider an element that's 200 pixels wide and 100 pixels tall. Calling + + myElement.size(20, AUTO) sets the width to 20 pixels and + height to 10 + + pixels.

+ +

Note: In the case of elements that need to load data, such as images, + wait + + to call myElement.size() until after the data loads.

+ path: .././src/content/reference/en//p5.Element/size + remove: + description: | +

Removes the element, stops all audio/video streams, and removes all + callback functions.

+ path: .././src/content/reference/en//p5.Element/remove + drop: + description: > +

Sets a function to call when the user drops a file on the element.

+ +

The first parameter, callback, is a function to call once + the file loads. + + The callback function should have one parameter, file, that's + a + + p5.File object. If the user drops multiple files + on + + the element, callback, is called once for each file.

+ +

The second parameter, fxn, is a function to call when the + browser detects + + one or more dropped files. The callback function should have one + + parameter, event, that's a + + DragEvent.

+ path: .././src/content/reference/en//p5.Element/drop + draggable: + description: > +

Turns p5.Element into a draggable item. If an argument is given, it + will drag that p5.Element instead, ie. drag a entire GUI panel (parent + container) with the panel's title bar.

+ path: .././src/content/reference/en//p5.Element/draggable +--- + + +# p5.Element diff --git a/src/content/reference/en/p5/p5.File.mdx b/src/content/reference/en/p5/p5.File.mdx new file mode 100644 index 0000000000..119c3efc24 --- /dev/null +++ b/src/content/reference/en/p5/p5.File.mdx @@ -0,0 +1,69 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.File +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

A class to describe a file.

+

p5.File objects are used by + myElement.drop() and + created by + createFileInput.

+isConstructor: true +line: 4896 +params: + - name: file + description: | +

wrapped file.

+ type: File +memberMethodPreviews: + file: + description: > +

Underlying + + File + + object. All File properties and methods are accessible.

+ path: .././src/content/reference/en//p5.File/file + type: + description: > +

The file + + MIME type + + as a string. For example, 'image', 'text', and + so on.

+ path: .././src/content/reference/en//p5.File/type + subtype: + description: > +

The file subtype as a string. For example, a file with an + 'image' + + MIME type + + may have a subtype such as png or jpeg.

+ path: .././src/content/reference/en//p5.File/subtype + name: + description: | +

The file name as a string.

+ path: .././src/content/reference/en//p5.File/name + size: + description: | +

The number of bytes in the file.

+ path: .././src/content/reference/en//p5.File/size + data: + description: | +

A string containing either the file's image data, text contents, or + a parsed object in the case of JSON and + p5.XML objects.

+ path: .././src/content/reference/en//p5.File/data +--- + + +# p5.File diff --git a/src/content/reference/en/p5/p5.Font.mdx b/src/content/reference/en/p5/p5.Font.mdx new file mode 100644 index 0000000000..f8e6b4d295 --- /dev/null +++ b/src/content/reference/en/p5/p5.Font.mdx @@ -0,0 +1,94 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Font +module: Typography +submodule: Loading & Displaying +file: src/typography/p5.Font.js +description: | +

A class to describe fonts.

+isConstructor: true +line: 13 +params: + - name: pInst + description: | +

pointer to p5 instance.

+ type: P5 + optional: true +memberMethodPreviews: + font: + description: | +

Underlying + opentype.js + font object.

+ path: .././src/content/reference/en//p5.Font/font + textBounds: + description: > +

Returns the bounding box for a string of text written using this + + p5.Font.

+ +

The first parameter, str, is a string of text. The second + and third + + parameters, x and y, are the text's position. By + default, they set the + + coordinates of the bounding box's bottom-left corner. See + + textAlign() for more ways to align text.

+ +

The fourth parameter, fontSize, is optional. It sets the + font size used to + + determine the bounding box. By default, font.textBounds() + will use the + + current textSize().

+ path: .././src/content/reference/en//p5.Font/textBounds + textToPoints: + description: > +

Returns an array of points outlining a string of text written using + this + + p5.Font.

+ +

The first parameter, str, is a string of text. The second + and third + + parameters, x and y, are the text's position. By + default, they set the + + coordinates of the bounding box's bottom-left corner. See + + textAlign() for more ways to align text.

+ +

The fourth parameter, fontSize, is optional. It sets the + text's font + + size. By default, font.textToPoints() will use the current + + textSize().

+ +

The fifth parameter, options, is also optional. + font.textToPoints() + + expects an object with the following properties:

+ +

sampleFactor is the ratio of the text's path length to the + number of + + samples. It defaults to 0.1. Higher values produce more points along the + + path and are more precise.

+ +

simplifyThreshold removes collinear points if it's set to + a number other + + than 0. The value represents the threshold angle to use when determining + + whether two edges are collinear.

+ path: .././src/content/reference/en//p5.Font/textToPoints +--- + + +# p5.Font diff --git a/src/content/reference/en/p5/p5.Framebuffer.mdx b/src/content/reference/en/p5/p5.Framebuffer.mdx new file mode 100644 index 0000000000..c4bef62dca --- /dev/null +++ b/src/content/reference/en/p5/p5.Framebuffer.mdx @@ -0,0 +1,186 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Framebuffer +module: Rendering +submodule: '' +file: src/webgl/p5.Framebuffer.js +description: | +

An object that one can draw to and then read as a texture. While similar + to a p5.Graphics, using a p5.Framebuffer as a texture will generally run + much faster, as it lives within the same WebGL context as the canvas it + is created on. It only works in WebGL mode.

+isConstructor: true +line: 76 +params: + - name: target + description: | +

A p5 global instance or p5.Graphics

+ type: p5.Graphics|p5 + - name: settings + description: | +

A settings object

+ type: Object + optional: true +memberMethodPreviews: + pixels: + description: > +

A Uint8ClampedArray + + containing the values for all the pixels in the Framebuffer.

+ +

Like the main canvas pixels property, call + + loadPixels() before reading + + it, and call updatePixels() + + afterwards to update its data.

+ +

Note that updating pixels via this property will be slower than + + drawing to the framebuffer directly. + + Consider using a shader instead of looping over pixels.

+ path: .././src/content/reference/en//p5.Framebuffer/pixels + resize: + description: | +

Resizes the framebuffer to the given width and height.

+ path: .././src/content/reference/en//p5.Framebuffer/resize + pixelDensity: + description: | +

Gets or sets the pixel scaling for high pixel density displays. By + default, the density will match that of the canvas the framebuffer was + created on, which will match the display density.

+

Call this method with no arguments to get the current density, or pass + in a number to set the density.

+ path: .././src/content/reference/en//p5.Framebuffer/pixelDensity + autoSized: + description: > +

Gets or sets whether or not this framebuffer will automatically resize + + along with the canvas it's attached to in order to match its size.

+ +

Call this method with no arguments to see if it is currently + auto-sized, + + or pass in a boolean to set this property.

+ path: .././src/content/reference/en//p5.Framebuffer/autoSized + createCamera: + description: | +

Creates and returns a new + p5.FramebufferCamera to be used + while drawing to this framebuffer. The camera will be set as the + currently active camera.

+ path: .././src/content/reference/en//p5.Framebuffer/createCamera + remove: + description: | +

Removes the framebuffer and frees its resources.

+ path: .././src/content/reference/en//p5.Framebuffer/remove + begin: + description: | +

Begin drawing to this framebuffer. Subsequent drawing functions to the + canvas the framebuffer is attached to will not be immediately visible, and + will instead be drawn to the framebuffer's texture. Call + end() when finished to make draw + functions go right to the canvas again and to be able to read the + contents of the framebuffer's texture.

+ path: .././src/content/reference/en//p5.Framebuffer/begin + end: + description: | +

After having previously called + begin(), this method stops drawing + functions from going to the framebuffer's texture, allowing them to go + right to the canvas again. After this, one can read from the framebuffer's + texture.

+ path: .././src/content/reference/en//p5.Framebuffer/end + draw: + description: > +

Run a function while drawing to the framebuffer rather than to its + canvas. + + This is equivalent to calling framebuffer.begin(), running + the function, + + and then calling framebuffer.end(), but ensures that one + never + + accidentally forgets begin or end.

+ path: .././src/content/reference/en//p5.Framebuffer/draw + get: + description: > +

Get a region of pixels from the canvas in the form of a + + p5.Image, or a single pixel as an array of + + numbers.

+ +

Returns an array of [R,G,B,A] values for any pixel or grabs a section + of + + an image. If the Framebuffer has been set up to not store alpha values, + then + + only [R,G,B] will be returned. If no parameters are specified, the entire + + image is returned. + + Use the x and y parameters to get the value of one pixel. Get a section of + + the display window by specifying additional w and h parameters. When + + getting an image, the x and y parameters define the coordinates for the + + upper-left corner of the image, regardless of the current imageMode().

+ path: .././src/content/reference/en//p5.Framebuffer/get + color: + description: > +

A texture with the color information of the framebuffer. Pass this (or + the + + framebuffer itself) to texture() to draw it to + + the canvas, or pass it to a shader with + + setUniform() to read its data.

+ +

Since Framebuffers are controlled by WebGL, their y coordinates are + stored + + flipped compared to images and videos. When texturing with a framebuffer + + texture, you may want to flip vertically, e.g. with + + plane(framebuffer.width, -framebuffer.height).

+ path: .././src/content/reference/en//p5.Framebuffer/color + depth: + description: > +

A texture with the depth information of the framebuffer. If the + framebuffer + + was created with { depth: false } in its settings, then this + property will + + be undefined. Pass this to texture() to draw it + to + + the canvas, or pass it to a shader with + + setUniform() to read its data.

+ +

Since Framebuffers are controlled by WebGL, their y coordinates are + stored + + flipped compared to images and videos. When texturing with a framebuffer + + texture, you may want to flip vertically, e.g. with + + plane(framebuffer.width, -framebuffer.height).

+ path: .././src/content/reference/en//p5.Framebuffer/depth +--- + + +# p5.Framebuffer diff --git a/src/content/reference/en/p5/p5.Geometry.mdx b/src/content/reference/en/p5/p5.Geometry.mdx new file mode 100644 index 0000000000..c561a01090 --- /dev/null +++ b/src/content/reference/en/p5/p5.Geometry.mdx @@ -0,0 +1,89 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Geometry +module: Shape +submodule: 3D Primitives +file: src/webgl/p5.Geometry.js +description: | +

p5 Geometry class

+isConstructor: true +line: 13 +params: + - name: detailX + description: | +

number of vertices along the x-axis.

+ type: Integer + optional: true + - name: detailY + description: | +

number of vertices along the y-axis.

+ type: Integer + optional: true + - name: callback + description: | +

function to call upon object instantiation.

+ type: Function + optional: true +memberMethodPreviews: + clearColors: + description: > +

Removes the internal colors of p5.Geometry. + + Using clearColors(), you can use fill() to + supply new colors before drawing each shape. + + If clearColors() is not used, the shapes will use their + internal colors by ignoring fill().

+ path: .././src/content/reference/en//p5.Geometry/clearColors + flipU: + description: | +

Flips the U texture coordinates of the model.

+ path: .././src/content/reference/en//p5.Geometry/flipU + flipV: + description: | +

Flips the V texture coordinates of the model.

+ path: .././src/content/reference/en//p5.Geometry/flipV + computeFaces: + description: | +

computes faces for geometry objects based on the vertices.

+ path: .././src/content/reference/en//p5.Geometry/computeFaces + computeNormals: + description: > +

This function calculates normals for each face, where each vertex's + normal is the average of the normals of all faces it's connected to. + + i.e computes smooth normals per vertex as an average of each face.

+ +

When using FLAT shading, vertices are + disconnected/duplicated i.e each face has its own copy of vertices. + + When using SMOOTH shading, vertices are + connected/deduplicated i.e each face has its vertices shared with other + faces.

+ +

Options can include:

+ + + path: .././src/content/reference/en//p5.Geometry/computeNormals + averageNormals: + description: | +

Averages the vertex normals. Used in curved + surfaces

+ path: .././src/content/reference/en//p5.Geometry/averageNormals + averagePoleNormals: + description: | +

Averages pole normals. Used in spherical primitives

+ path: .././src/content/reference/en//p5.Geometry/averagePoleNormals + normalize: + description: | +

Modifies all vertices to be centered within the range -100 to 100.

+ path: .././src/content/reference/en//p5.Geometry/normalize +--- + + +# p5.Geometry diff --git a/src/content/reference/en/p5/p5.Graphics.mdx b/src/content/reference/en/p5/p5.Graphics.mdx new file mode 100644 index 0000000000..e494e7f7f5 --- /dev/null +++ b/src/content/reference/en/p5/p5.Graphics.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Graphics +module: Rendering +submodule: Rendering +file: src/core/p5.Graphics.js +description: | +

Thin wrapper around a renderer, to be used for creating a + graphics buffer object. Use this class if you need + to draw into an off-screen graphics buffer. The two parameters define the + width and height in pixels. The fields and methods for this class are + extensive, but mirror the normal drawing API for p5.

+isConstructor: true +line: 10 +params: + - name: w + description: | +

width

+ type: Number + - name: h + description: | +

height

+ type: Number + - name: renderer + description: | +

the renderer to use, either P2D or WEBGL

+ type: Constant + - name: pInst + description: | +

pointer to p5 instance

+ type: P5 + optional: true + - name: canvas + description: | +

existing html canvas element

+ type: HTMLCanvasElement + optional: true +memberMethodPreviews: + reset: + description: > +

Resets certain values such as those modified by functions in the + Transform category + + and in the Lights category that are not automatically reset + + with graphics buffer objects. Calling this in draw() will copy the behavior + + of the standard canvas.

+ path: .././src/content/reference/en//p5.Graphics/reset + remove: + description: | +

Removes a Graphics object from the page and frees any resources + associated with it.

+ path: .././src/content/reference/en//p5.Graphics/remove + createFramebuffer: + description: > +

Creates and returns a new p5.Framebuffer + + inside a p5.Graphics WebGL context.

+ +

This takes the same parameters as the global + + createFramebuffer function.

+ path: .././src/content/reference/en//p5.Graphics/createFramebuffer +--- + + +# p5.Graphics diff --git a/src/content/reference/en/p5/p5.Image.mdx b/src/content/reference/en/p5/p5.Image.mdx new file mode 100644 index 0000000000..f0f45501ce --- /dev/null +++ b/src/content/reference/en/p5/p5.Image.mdx @@ -0,0 +1,363 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Image +module: Image +submodule: Image +file: src/image/p5.Image.js +description: > +

A class to describe an image. Images are rectangular grids of pixels that + + can be displayed and modified.

+ +

Existing images can be loaded by calling + + loadImage(). Blank images can be created by + + calling createImage(). p5.Image + objects + + have methods for common tasks such as applying filters and modifying + + pixel values.

+isConstructor: true +line: 21 +params: + - name: width + description: '' + type: Number + - name: height + description: '' + type: Number +memberMethodPreviews: + width: + description: | +

Image width.

+ path: .././src/content/reference/en//p5.Image/width + height: + description: | +

Image height.

+ path: .././src/content/reference/en//p5.Image/height + pixels: + description: > +

An array containing the color of each pixel in the + + p5.Image object. Colors are stored as numbers + + representing red, green, blue, and alpha (RGBA) values. + img.pixels is a + + one-dimensional array for performance reasons.

+ +

Each pixel occupies four elements in the pixels array, one for each + + RGBA value. For example, the pixel at coordinates (0, 0) stores its + + RGBA values at img.pixels[0], img.pixels[1], + img.pixels[2], + + and img.pixels[3], respectively. The next pixel at + coordinates (1, 0) + + stores its RGBA values at img.pixels[4], + img.pixels[5], + + img.pixels[6], and img.pixels[7]. And so on. The + img.pixels array + + for a 100×100 p5.Image object has + + 100 × 100 × 4 = 40,000 elements.

+ +

Accessing the RGBA values for a pixel in the + + p5.Image object requires a little math as + + shown below. The img.loadPixels() + + method must be called before accessing the img.pixels array. + The + + img.updatePixels() method must be + + called after any changes are made.

+ path: .././src/content/reference/en//p5.Image/pixels + pixelDensity: + description: > +

Gets or sets the pixel density for high pixel density displays. By + default, + + the density will be set to 1.

+ +

Call this method with no arguments to get the default density, or pass + + in a number to set the density. If a non-positive number is provided, + + it defaults to 1.

+ path: .././src/content/reference/en//p5.Image/pixelDensity + loadPixels: + description: > +

Loads the current value of each pixel in the + + p5.Image object into the img.pixels + array. + + This method must be called before reading or modifying pixel values.

+ path: .././src/content/reference/en//p5.Image/loadPixels + updatePixels: + description: > +

Updates the canvas with the RGBA values in the + + img.pixels array.

+ +

img.updatePixels() only needs to be called after changing + values in + + the img.pixels array. Such changes can be + + made directly after calling + + img.loadPixels() or by calling + + img.set().

+ +

The optional parameters x, y, + width, and height define a + + subsection of the p5.Image object to update. + + Doing so can improve performance in some cases.

+ +

If the p5.Image object was loaded from a GIF, + + then calling img.updatePixels() will update the pixels in + current + + frame.

+ path: .././src/content/reference/en//p5.Image/updatePixels + get: + description: > +

Gets a pixel or a region of pixels from a + + p5.Image object.

+ +

img.get() is easy to use but it's not as fast as + + img.pixels. Use + + img.pixels to read many pixel values.

+ +

The version of img.get() with no parameters returns the + entire image.

+ +

The version of img.get() with two parameters interprets + them as + + coordinates. It returns an array with the [R, G, B, A] values + of the + + pixel at the given point.

+ +

The version of img.get() with four parameters interprets + them as + + coordinates and dimensions. It returns a subsection of the canvas as a + + p5.Image object. The first two parameters are + + the coordinates for the upper-left corner of the subsection. The last two + + parameters are the width and height of the subsection.

+ +

Use img.get() to work directly with + + p5.Image objects.

+ path: .././src/content/reference/en//p5.Image/get + set: + description: > +

Sets the color of one or more pixels within a + + p5.Image object.

+ +

img.set() is easy to use but it's not as fast as + + img.pixels. Use + + img.pixels to set many pixel values.

+ +

img.set() interprets the first two parameters as x- and + y-coordinates. It + + interprets the last parameter as a grayscale value, a [R, G, B, + A] pixel + + array, a p5.Color object, or another + + p5.Image object.

+ +

img.updatePixels() must be called + + after using img.set() for changes to appear.

+ path: .././src/content/reference/en//p5.Image/set + resize: + description: > +

Resizes the p5.Image object to a given + width + + and height. The image's original aspect ratio can be kept by + passing 0 + + for either width or height. For example, calling + img.resize(50, 0) + + on an image that was 500 × 300 pixels will resize it to + + 50 × 30 pixels.

+ path: .././src/content/reference/en//p5.Image/resize + copy: + description: | +

Copies pixels from a source p5.Image + to this one. Calling img.copy() will scale pixels from the source + region if it isn't the same size as the destination region.

+ path: .././src/content/reference/en//p5.Image/copy + mask: + description: | +

Masks part of an image from displaying by loading another + image and using its alpha channel as an alpha channel for + this image. Masks are cumulative, once applied to an image + object, they cannot be removed.

+ path: .././src/content/reference/en//p5.Image/mask + filter: + description: > +

Applies an image filter to the p5.Image + object. + + The preset options are:

+ +

INVERT + + Inverts the colors in the image. No parameter is used.

+ +

GRAY + + Converts the image to grayscale. No parameter is used.

+ +

THRESHOLD + + Converts the image to black and white. Pixels with a grayscale value + + above a given threshold are converted to white. The rest are converted to + + black. The threshold must be between 0.0 (black) and 1.0 (white). If no + + value is specified, 0.5 is used.

+ +

OPAQUE + + Sets the alpha channel to be entirely opaque. No parameter is used.

+ +

POSTERIZE + + Limits the number of colors in the image. Each color channel is limited to + + the number of colors specified. Values between 2 and 255 are valid, but + + results are most noticeable with lower values. The default value is 4.

+ +

BLUR + + Blurs the image. The level of blurring is specified by a blur radius. + Larger + + values increase the blur. The default value is 4. A gaussian blur is used + + in P2D mode. A box blur is used in WEBGL + mode.

+ +

ERODE + + Reduces the light areas. No parameter is used.

+ +

DILATE + + Increases the light areas. No parameter is used.

+ path: .././src/content/reference/en//p5.Image/filter + blend: + description: > +

Copies a region of pixels from another + + p5.Image object into this one. The + blendMode + + parameter blends the images' colors to create different effects.

+ path: .././src/content/reference/en//p5.Image/blend + save: + description: > +

Saves the p5.Image object to a file. + + The browser will either save the file immediately or prompt the user + + with a dialogue window.

+ +

By default, calling img.save() will save the image as + untitled.png.

+ +

Calling img.save() with one argument, as in + img.save('photo.png'), + + will set the image's filename and type together.

+ +

Calling img.save() with two arguments, as in + + image.save('photo', 'png'), will set the image's filename and + type + + separately.

+ +

The image will only be downloaded as an animated GIF if the + + p5.Image object was loaded from a GIF file. + + See saveGif() to create new GIFs.

+ path: .././src/content/reference/en//p5.Image/save + reset: + description: | +

Restarts an animated GIF at its first frame.

+ path: .././src/content/reference/en//p5.Image/reset + getCurrentFrame: + description: | +

Gets the index of the current frame in an animated GIF.

+ path: .././src/content/reference/en//p5.Image/getCurrentFrame + setFrame: + description: | +

Sets the current frame in an animated GIF.

+ path: .././src/content/reference/en//p5.Image/setFrame + numFrames: + description: | +

Returns the number of frames in an animated GIF.

+ path: .././src/content/reference/en//p5.Image/numFrames + play: + description: | +

Plays an animated GIF that was paused with + img.pause().

+ path: .././src/content/reference/en//p5.Image/play + pause: + description: | +

Pauses an animated GIF. The GIF can be resumed by calling + img.play().

+ path: .././src/content/reference/en//p5.Image/pause + delay: + description: > +

Changes the delay between frames in an animated GIF.

+ +

The second parameter, index, is optional. If provided, + only the frame + + at index will have its delay modified. All other frames will + keep + + their default delay.

+ path: .././src/content/reference/en//p5.Image/delay +--- + + +# p5.Image diff --git a/src/content/reference/en/p5/p5.MediaElement.mdx b/src/content/reference/en/p5/p5.MediaElement.mdx new file mode 100644 index 0000000000..3847f32298 --- /dev/null +++ b/src/content/reference/en/p5/p5.MediaElement.mdx @@ -0,0 +1,212 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.MediaElement +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

A class to handle audio and video.

+ +

p5.MediaElement extends p5.Element + with + + methods to handle audio and video. p5.MediaElement objects are + created by + + calling createVideo, + + createAudio, and + + createCapture.

+isConstructor: true +line: 3643 +params: + - name: elt + description: | +

DOM node that is wrapped

+ type: String +memberMethodPreviews: + src: + description: | +

Path to the media element's source as a string.

+ path: .././src/content/reference/en//p5.MediaElement/src + play: + description: | +

Play audio or video from a media element.

+ path: .././src/content/reference/en//p5.MediaElement/play + stop: + description: > +

Stops a media element and sets its current time to zero. Calling + + media.play() will restart playing audio/video from the + beginning.

+ path: .././src/content/reference/en//p5.MediaElement/stop + pause: + description: > +

Pauses a media element. Calling media.play() will resume + playing + + audio/video from the moment it paused.

+ path: .././src/content/reference/en//p5.MediaElement/pause + loop: + description: | +

Play the audio/video repeatedly in a loop.

+ path: .././src/content/reference/en//p5.MediaElement/loop + noLoop: + description: | +

Stops the audio/video from playing in a loop. It will stop when it + reaches the end.

+ path: .././src/content/reference/en//p5.MediaElement/noLoop + autoplay: + description: > +

Sets the audio/video to play once it's loaded.

+ +

The parameter, shouldAutoplay, is optional. Calling + + media.autoplay() without an argument causes the media to play + + automatically. If true is passed, as in + media.autoplay(true), the + + media will automatically play. If false is passed, as in + + media.autoPlay(false), it won't play automatically.

+ path: .././src/content/reference/en//p5.MediaElement/autoplay + volume: + description: > +

Manages the audio/video volume.

+ +

Calling media.volume() without an argument returns the + current volume + + as a number in the range 0 (off) to 1 (maximum).

+ +

The parameter, val, is optional. It's a number that sets + the volume + + from 0 (off) to 1 (maximum). For example, calling + media.volume(0.5) + + sets the volume to half of its maximum.

+ path: .././src/content/reference/en//p5.MediaElement/volume + speed: + description: > +

Manages the audio/video playback speed. Calling + media.speed() returns + + the current speed as a number.

+ +

The parameter, val, is optional. It's a number that sets + the playback + + speed. 1 plays the media at normal speed, 0.5 plays it at half speed, 2 + + plays it at double speed, and so on. -1 plays the media at normal speed + + in reverse.

+ +

Note: Not all browsers support backward playback. Even if they do, + + playback might not be smooth.

+ path: .././src/content/reference/en//p5.MediaElement/speed + time: + description: > +

Manages the media element's playback time. Calling + media.time() + + returns the number of seconds the audio/video has played. Time resets to + + 0 when the looping media restarts.

+ +

The parameter, time, is optional. It's a number that + specifies the + + time, in seconds, to jump to when playback begins.

+ path: .././src/content/reference/en//p5.MediaElement/time + duration: + description: | +

Returns the audio/video's duration in seconds.

+ path: .././src/content/reference/en//p5.MediaElement/duration + onended: + description: > +

Calls a function when the audio/video reaches the end of its playback + + The function won't be called if the media is looping.

+ +

The p5.MediaElement is passed as an argument to the + callback function.

+ path: .././src/content/reference/en//p5.MediaElement/onended + connect: + description: | +

Send the audio output of this element to a specified audioNode or + p5.sound object. If no element is provided, connects to p5's main + output. That connection is established when this method is first called. + All connections are removed by the .disconnect() method.

+

This method is meant to be used with the p5.sound.js addon library.

+ path: .././src/content/reference/en//p5.MediaElement/connect + disconnect: + description: | +

Disconnect all Web Audio routing, including to main output. + This is useful if you want to re-route the output through + audio effects, for example.

+ path: .././src/content/reference/en//p5.MediaElement/disconnect + showControls: + description: > +

Show the default + + HTMLMediaElement + + controls. These vary between web browser.

+ path: .././src/content/reference/en//p5.MediaElement/showControls + hideControls: + description: > +

Hide the default + + HTMLMediaElement + + controls.

+ path: .././src/content/reference/en//p5.MediaElement/hideControls + addCue: + description: > +

Schedules a function to call when the audio/video reaches a specific + time + + during its playback.

+ +

The first parameter, time, is the time, in seconds, when + the function + + should run. This value is passed to callback as its first + argument.

+ +

The second parameter, callback, is the function to call at + the specified + + cue time.

+ +

The third parameter, value, is optional and can be any + type of value. + + value is passed to callback.

+ +

Calling media.addCue() returns an ID as a string. This is + useful for + + removing the cue later.

+ path: .././src/content/reference/en//p5.MediaElement/addCue + removeCue: + description: | +

Remove a callback based on its ID.

+ path: .././src/content/reference/en//p5.MediaElement/removeCue + clearCues: + description: | +

Removes all functions scheduled with media.addCue().

+ path: .././src/content/reference/en//p5.MediaElement/clearCues +--- + + +# p5.MediaElement diff --git a/src/content/reference/en/p5/p5.NumberDict.mdx b/src/content/reference/en/p5/p5.NumberDict.mdx new file mode 100644 index 0000000000..c482265ed8 --- /dev/null +++ b/src/content/reference/en/p5/p5.NumberDict.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.NumberDict +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

A simple Dictionary class for Numbers.

+isConstructor: true +line: 415 +memberMethodPreviews: + add: + description: | +

Add the given number to the value currently stored at the given key. + The sum then replaces the value previously stored in the Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/add + sub: + description: > +

Subtract the given number from the value currently stored at the given + key. + + The difference then replaces the value previously stored in the + Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/sub + mult: + description: > +

Multiply the given number with the value currently stored at the given + key. + + The product then replaces the value previously stored in the + Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/mult + div: + description: > +

Divide the given number with the value currently stored at the given + key. + + The quotient then replaces the value previously stored in the + Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/div + minValue: + description: | +

Return the lowest number currently stored in the Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/minValue + maxValue: + description: | +

Return the highest number currently stored in the Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/maxValue + minKey: + description: | +

Return the lowest key currently used in the Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/minKey + maxKey: + description: | +

Return the highest key currently used in the Dictionary.

+ path: .././src/content/reference/en//p5.NumberDict/maxKey +--- + + +# p5.NumberDict diff --git a/src/content/reference/en/p5/p5.PrintWriter.mdx b/src/content/reference/en/p5/p5.PrintWriter.mdx new file mode 100644 index 0000000000..5c74183ded --- /dev/null +++ b/src/content/reference/en/p5/p5.PrintWriter.mdx @@ -0,0 +1,21 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: p5.PrintWriter +module: IO +submodule: Output +file: src/io/files.js +description: '' +line: 1188 +params: + - name: filename + description: '' + type: String + - name: extension + description: '' + type: String + optional: true +chainable: false +--- + + +# p5.PrintWriter diff --git a/src/content/reference/en/p5/p5.Renderer.mdx b/src/content/reference/en/p5/p5.Renderer.mdx new file mode 100644 index 0000000000..c5f1135589 --- /dev/null +++ b/src/content/reference/en/p5/p5.Renderer.mdx @@ -0,0 +1,31 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Renderer +module: Rendering +submodule: Rendering +file: src/core/p5.Renderer.js +description: | +

Main graphics and rendering context, as well as the base API + implementation for p5.js "core". To be used as the superclass for + Renderer2D and Renderer3D classes, respectively.

+isConstructor: true +line: 10 +params: + - name: elt + description: | +

DOM node that is wrapped

+ type: HTMLElement + - name: pInst + description: | +

pointer to p5 instance

+ type: P5 + optional: true + - name: isMainCanvas + description: | +

whether we're using it as main canvas

+ type: Boolean + optional: true +--- + + +# p5.Renderer diff --git a/src/content/reference/en/p5/p5.Shader.mdx b/src/content/reference/en/p5/p5.Shader.mdx new file mode 100644 index 0000000000..4115fa2917 --- /dev/null +++ b/src/content/reference/en/p5/p5.Shader.mdx @@ -0,0 +1,95 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Shader +module: 3D +submodule: Material +file: src/webgl/p5.Shader.js +description: | +

Shader class for WEBGL Mode

+isConstructor: true +line: 11 +params: + - name: renderer + description: | +

an instance of p5.RendererGL that + will provide the GL context for this new p5.Shader

+ type: p5.RendererGL + - name: vertSrc + description: | +

source code for the vertex shader (as a string)

+ type: String + - name: fragSrc + description: | +

source code for the fragment shader (as a string)

+ type: String +memberMethodPreviews: + copyToContext: + description: > +

Shaders belong to the main canvas or a p5.Graphics. Once they are + compiled, + + they can only be used in the context they were compiled on.

+ +

Use this method to make a new copy of a shader that gets compiled on a + + different context.

+ path: .././src/content/reference/en//p5.Shader/copyToContext + setUniform: + description: > +

Used to set the uniforms of a + + p5.Shader object.

+ +

Uniforms are used as a way to provide shader programs + + (which run on the GPU) with values from a sketch + + (which runs on the CPU).

+ +

Here are some examples of uniforms you can make:

+ + + path: .././src/content/reference/en//p5.Shader/setUniform +--- + + +# p5.Shader diff --git a/src/content/reference/en/p5/p5.StringDict.mdx b/src/content/reference/en/p5/p5.StringDict.mdx new file mode 100644 index 0000000000..d10d5b6077 --- /dev/null +++ b/src/content/reference/en/p5/p5.StringDict.mdx @@ -0,0 +1,14 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: p5.StringDict +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

A simple Dictionary class for Strings.

+line: 397 +chainable: false +--- + + +# p5.StringDict diff --git a/src/content/reference/en/p5/p5.Table.mdx b/src/content/reference/en/p5/p5.Table.mdx new file mode 100644 index 0000000000..4215034aeb --- /dev/null +++ b/src/content/reference/en/p5/p5.Table.mdx @@ -0,0 +1,207 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Table +module: IO +submodule: Table +file: src/io/p5.Table.js +description: > +

Table objects store data with multiple rows and + columns, much + + like in a traditional spreadsheet. Tables can be generated from + + scratch, dynamically, or using data from an existing file.

+isConstructor: true +line: 33 +params: + - name: rows + description: | +

An array of p5.TableRow objects

+ type: 'p5.TableRow[]' + optional: true +memberMethodPreviews: + columns: + description: > +

An array containing the names of the columns in the table, if the + "header" the table is + + loaded with the "header" parameter.

+ path: .././src/content/reference/en//p5.Table/columns + rows: + description: > +

An array containing the p5.TableRow objects + that make up the + + rows of the table. The same result as calling getRows()

+ path: .././src/content/reference/en//p5.Table/rows + addRow: + description: > +

Use addRow() to add a new row of data to a p5.Table object. By default, + + an empty row is created. Typically, you would store a reference to + + the new row in a TableRow object (see newRow in the example above), + + and then set individual values using set().

+ +

If a p5.TableRow object is included as a + parameter, then that row is + + duplicated and added to the table.

+ path: .././src/content/reference/en//p5.Table/addRow + removeRow: + description: | +

Removes a row from the table object.

+ path: .././src/content/reference/en//p5.Table/removeRow + getRow: + description: > +

Returns a reference to the specified p5.TableRow. The reference + + can then be used to get and set values of the selected row.

+ path: .././src/content/reference/en//p5.Table/getRow + getRows: + description: > +

Gets all rows from the table. Returns an array of p5.TableRows.

+ path: .././src/content/reference/en//p5.Table/getRows + findRow: + description: | +

Finds the first row in the Table that contains the value + provided, and returns a reference to that row. Even if + multiple rows are possible matches, only the first matching + row is returned. The column to search may be specified by + either its ID or title.

+ path: .././src/content/reference/en//p5.Table/findRow + findRows: + description: | +

Finds the rows in the Table that contain the value + provided, and returns references to those rows. Returns an + Array, so for must be used to iterate through all the rows, + as shown in the example above. The column to search may be + specified by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/findRows + matchRow: + description: | +

Finds the first row in the Table that matches the regular + expression provided, and returns a reference to that row. + Even if multiple rows are possible matches, only the first + matching row is returned. The column to search may be + specified by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/matchRow + matchRows: + description: | +

Finds the rows in the Table that match the regular expression provided, + and returns references to those rows. Returns an array, so for must be + used to iterate through all the rows, as shown in the example. The + column to search may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/matchRows + getColumn: + description: | +

Retrieves all values in the specified column, and returns them + as an array. The column may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/getColumn + clearRows: + description: | +

Removes all rows from a Table. While all rows are removed, + columns and column titles are maintained.

+ path: .././src/content/reference/en//p5.Table/clearRows + addColumn: + description: > +

Use addColumn() to add a new column to a + Table object. + + Typically, you will want to specify a title, so the column + + may be easily referenced later by name. (If no title is + + specified, the new column's title will be null.)

+ path: .././src/content/reference/en//p5.Table/addColumn + getColumnCount: + description: | +

Returns the total number of columns in a Table.

+ path: .././src/content/reference/en//p5.Table/getColumnCount + getRowCount: + description: | +

Returns the total number of rows in a Table.

+ path: .././src/content/reference/en//p5.Table/getRowCount + removeTokens: + description: | +

Removes any of the specified characters (or "tokens").

+

If no column is specified, then the values in all columns and + rows are processed. A specific column may be referenced by + either its ID or title.

+ path: .././src/content/reference/en//p5.Table/removeTokens + trim: + description: | +

Trims leading and trailing whitespace, such as spaces and tabs, + from String table values. If no column is specified, then the + values in all columns and rows are trimmed. A specific column + may be referenced by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/trim + removeColumn: + description: > +

Use removeColumn() to remove an + existing column from a Table + + object. The column to be removed may be identified by either + + its title (a String) or its index value (an int). + + removeColumn(0) would remove the first column, removeColumn(1) + + would remove the second column, and so on.

+ path: .././src/content/reference/en//p5.Table/removeColumn + set: + description: | +

Stores a value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/set + setNum: + description: | +

Stores a Float value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/setNum + setString: + description: | +

Stores a String value in the Table's specified row and column. + The row is specified by its ID, while the column may be specified + by either its ID or title.

+ path: .././src/content/reference/en//p5.Table/setString + get: + description: | +

Retrieves a value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+ path: .././src/content/reference/en//p5.Table/get + getNum: + description: | +

Retrieves a Float value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+ path: .././src/content/reference/en//p5.Table/getNum + getString: + description: | +

Retrieves a String value from the Table's specified row and column. + The row is specified by its ID, while the column may be specified by + either its ID or title.

+ path: .././src/content/reference/en//p5.Table/getString + getObject: + description: | +

Retrieves all table data and returns as an object. If a column name is + passed in, each row object will be stored with that attribute as its + title.

+ path: .././src/content/reference/en//p5.Table/getObject + getArray: + description: > +

Retrieves all table data and returns it as a multidimensional + array.

+ path: .././src/content/reference/en//p5.Table/getArray +--- + + +# p5.Table diff --git a/src/content/reference/en/p5/p5.TableRow.mdx b/src/content/reference/en/p5/p5.TableRow.mdx new file mode 100644 index 0000000000..7d28e84348 --- /dev/null +++ b/src/content/reference/en/p5/p5.TableRow.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.TableRow +module: IO +submodule: Table +file: src/io/p5.TableRow.js +description: | +

A TableRow object represents a single row of data values, + stored in columns, from a table.

+

A Table Row contains both an ordered array, and an unordered + JSON object.

+isConstructor: true +line: 9 +params: + - name: str + description: | +

optional: populate the row with a + string of values, separated by the + separator

+ type: String + optional: true + - name: separator + description: | +

comma separated values (csv) by default

+ type: String + optional: true +memberMethodPreviews: + set: + description: | +

Stores a value in the TableRow's specified column. + The column may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.TableRow/set + setNum: + description: | +

Stores a Float value in the TableRow's specified column. + The column may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.TableRow/setNum + setString: + description: | +

Stores a String value in the TableRow's specified column. + The column may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.TableRow/setString + get: + description: | +

Retrieves a value from the TableRow's specified column. + The column may be specified by either its ID or title.

+ path: .././src/content/reference/en//p5.TableRow/get + getNum: + description: | +

Retrieves a Float value from the TableRow's specified + column. The column may be specified by either its ID or + title.

+ path: .././src/content/reference/en//p5.TableRow/getNum + getString: + description: | +

Retrieves an String value from the TableRow's specified + column. The column may be specified by either its ID or + title.

+ path: .././src/content/reference/en//p5.TableRow/getString +--- + + +# p5.TableRow diff --git a/src/content/reference/en/p5/p5.TypedDict.mdx b/src/content/reference/en/p5/p5.TypedDict.mdx new file mode 100644 index 0000000000..3cf7b096d4 --- /dev/null +++ b/src/content/reference/en/p5/p5.TypedDict.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.TypedDict +module: Data +submodule: Dictionary +file: src/data/p5.TypedDict.js +description: | +

Base class for all p5.Dictionary types. Specifically + typed Dictionary classes inherit from this class.

+isConstructor: true +line: 82 +memberMethodPreviews: + size: + description: > +

Returns the number of key-value pairs currently stored in the + Dictionary.

+ path: .././src/content/reference/en//p5.TypedDict/size + hasKey: + description: | +

Returns true if the given key exists in the Dictionary, + otherwise returns false.

+ path: .././src/content/reference/en//p5.TypedDict/hasKey + get: + description: | +

Returns the value stored at the given key.

+ path: .././src/content/reference/en//p5.TypedDict/get + set: + description: > +

Updates the value associated with the given key in case it already + exists + + in the Dictionary. Otherwise a new key-value pair is added.

+ path: .././src/content/reference/en//p5.TypedDict/set + create: + description: | +

Creates a new key-value pair in the Dictionary.

+ path: .././src/content/reference/en//p5.TypedDict/create + clear: + description: | +

Removes all previously stored key-value pairs from the Dictionary.

+ path: .././src/content/reference/en//p5.TypedDict/clear + remove: + description: > +

Removes the key-value pair stored at the given key from the + Dictionary.

+ path: .././src/content/reference/en//p5.TypedDict/remove + print: + description: > +

Logs the set of items currently stored in the Dictionary to the + console.

+ path: .././src/content/reference/en//p5.TypedDict/print + saveTable: + description: | +

Converts the Dictionary into a CSV file for local download.

+ path: .././src/content/reference/en//p5.TypedDict/saveTable + saveJSON: + description: | +

Converts the Dictionary into a JSON file for local download.

+ path: .././src/content/reference/en//p5.TypedDict/saveJSON +--- + + +# p5.TypedDict diff --git a/src/content/reference/en/p5/p5.Vector.mdx b/src/content/reference/en/p5/p5.Vector.mdx new file mode 100644 index 0000000000..4a5d2e4636 --- /dev/null +++ b/src/content/reference/en/p5/p5.Vector.mdx @@ -0,0 +1,470 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.Vector +module: Math +submodule: Vector +file: src/math/p5.Vector.js +description: > +

A class to describe a two or three-dimensional vector. A vector is like an + + arrow pointing in space. Vectors have both magnitude (length) and + + direction.

+ +

p5.Vector objects are often used to program motion because + they simplify + + the math. For example, a moving ball has a position and a velocity. + + Position describes where the ball is in space. The ball's position vector + + extends from the origin to the ball's center. Velocity describes the ball's + + speed and the direction it's moving. If the ball is moving straight up, its + + velocity vector points straight up. Adding the ball's velocity vector to + + its position vector moves it, as in pos.add(vel). Vector math + relies on + + methods inside the p5.Vector class.

+isConstructor: true +line: 34 +params: + - name: x + description: | +

x component of the vector.

+ type: Number + optional: true + - name: 'y' + description: | +

y component of the vector.

+ type: Number + optional: true + - name: z + description: | +

z component of the vector.

+ type: Number + optional: true +memberMethodPreviews: + x: + description: | +

The x component of the vector

+ path: .././src/content/reference/en//p5.Vector/x + 'y': + description: | +

The y component of the vector

+ path: .././src/content/reference/en//p5.Vector/y + z: + description: | +

The z component of the vector

+ path: .././src/content/reference/en//p5.Vector/z + toString: + description: | +

Returns a string representation of a vector. This method is useful for + printing vectors to the console while debugging.

+ path: .././src/content/reference/en//p5.Vector/toString + set: + description: > +

Sets the x, y, and z components + of the vector using separate numbers, + + a p5.Vector object, or an array of numbers. + + Calling set() with no arguments sets the vector's components + to 0.

+ path: .././src/content/reference/en//p5.Vector/set + copy: + description: | +

Returns a copy of the p5.Vector object.

+ path: .././src/content/reference/en//p5.Vector/copy + add: + description: > +

Adds to a vector's x, y, and z + components using separate numbers, + + another p5.Vector object, or an array of + numbers. + + Calling add() with no arguments has no effect.

+ +

The static version of add(), as in p5.Vector.add(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+ path: .././src/content/reference/en//p5.Vector/add + rem: + description: > +

Performs modulo (remainder) division with a vector's x, + y, and z + + components using separate numbers, another + + p5.Vector object, or an array of numbers.

+ +

The static version of rem() as in p5.Vector.rem(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+ path: .././src/content/reference/en//p5.Vector/rem + sub: + description: > +

Subtracts from a vector's x, y, and + z components using separate + + numbers, another p5.Vector object, or an array + of + + numbers. Calling sub() with no arguments has no effect.

+ +

The static version of sub(), as in p5.Vector.sub(v2, + v1), returns a new + + p5.Vector object and doesn't change the + + originals.

+ path: .././src/content/reference/en//p5.Vector/sub + mult: + description: > +

Multiplies a vector's x, y, and + z components by the same number, + + separate numbers, the components of another + + p5.Vector object, or an array of numbers. + Calling + + mult() with no arguments has no effect.

+ +

The static version of mult(), as in + p5.Vector.mult(v, 2), returns a new + + p5.Vector object and doesn't change the + + originals.

+ path: .././src/content/reference/en//p5.Vector/mult + div: + description: > +

Divides a vector's x, y, and z + components by the same number, + + separate numbers, the components of another + + p5.Vector object, or an array of numbers. + Calling + + div() with no arguments has no effect.

+ +

The static version of div(), as in p5.Vector.div(v, + 2), returns a new + + p5.Vector object and doesn't change the + + originals.

+ path: .././src/content/reference/en//p5.Vector/div + mag: + description: | +

Returns the magnitude (length) of the vector.

+ path: .././src/content/reference/en//p5.Vector/mag + magSq: + description: | +

Returns the magnitude (length) of the vector squared.

+ path: .././src/content/reference/en//p5.Vector/magSq + dot: + description: > +

Returns the dot product of two vectors. The dot product is a number + that + + describes the overlap between two vectors. Visually, the dot product can + be + + thought of as the "shadow" one vector casts on another. The dot product's + + magnitude is largest when two vectors point in the same or opposite + + directions. Its magnitude is 0 when two vectors form a right angle.

+ +

The version of dot() with one parameter interprets it as + another + + p5.Vector object.

+ +

The version of dot() with multiple parameters interprets + them as the + + x, y, and z components of another + vector.

+ +

The static version of dot(), as in p5.Vector.dot(v1, + v2), is the same + + as calling v1.dot(v2).

+ path: .././src/content/reference/en//p5.Vector/dot + cross: + description: > +

Returns the cross product of two vectors. The cross product is a vector + + that points straight out of the plane created by two vectors. The cross + + product's magnitude is the area of the parallelogram formed by the + original + + two vectors.

+ +

The static version of cross(), as in + p5.Vector.cross(v1, v2), is the same + + as calling v1.cross(v2).

+ path: .././src/content/reference/en//p5.Vector/cross + dist: + description: > +

Returns the distance between two points represented by vectors. A + point's + + coordinates can be thought of as a vector's components.

+ +

The static version of dist(), as in + p5.Vector.dist(v1, v2), is the same + + as calling v1.dist(v2).

+ +

Use dist() to calculate the distance between + points + + using coordinates as in dist(x1, y1, x2, y2).

+ path: .././src/content/reference/en//p5.Vector/dist + normalize: + description: > +

Scales the components of a p5.Vector object + so + + that its magnitude is 1.

+ +

The static version of normalize(), as in + p5.Vector.normalize(v), + + returns a new p5.Vector object and doesn't + change + + the original.

+ path: .././src/content/reference/en//p5.Vector/normalize + limit: + description: > +

Limits a vector's magnitude to a maximum value.

+ +

The static version of limit(), as in + p5.Vector.limit(v, 5), returns a + + new p5.Vector object and doesn't change the + + original.

+ path: .././src/content/reference/en//p5.Vector/limit + setMag: + description: > +

Sets a vector's magnitude to a given value.

+ +

The static version of setMag(), as in + p5.Vector.setMag(v, 10), returns + + a new p5.Vector object and doesn't change the + + original.

+ path: .././src/content/reference/en//p5.Vector/setMag + heading: + description: > +

Calculates the angle a 2D vector makes with the positive x-axis. Angles + + increase in the clockwise direction.

+ +

If the vector was created with + + createVector(), heading() + returns angles + + in the units of the current angleMode().

+ +

The static version of heading(), as in + p5.Vector.heading(v), works the + + same way.

+ path: .././src/content/reference/en//p5.Vector/heading + setHeading: + description: > +

Rotates a 2D vector to a specific angle without changing its magnitude. + + By convention, the positive x-axis has an angle of 0. Angles increase in + + the clockwise direction.

+ +

If the vector was created with + + createVector(), setHeading() + uses + + the units of the current angleMode().

+ path: .././src/content/reference/en//p5.Vector/setHeading + rotate: + description: > +

Rotates a 2D vector by an angle without changing its magnitude. + + By convention, the positive x-axis has an angle of 0. Angles increase in + + the clockwise direction.

+ +

If the vector was created with + + createVector(), rotate() uses + + the units of the current angleMode().

+ +

The static version of rotate(), as in + p5.Vector.rotate(v, PI), + + returns a new p5.Vector object and doesn't + change + + the original.

+ path: .././src/content/reference/en//p5.Vector/rotate + angleBetween: + description: > +

Returns the angle between two vectors. The angles returned are signed, + + which means that v1.angleBetween(v2) === + -v2.angleBetween(v1).

+ +

If the vector was created with + + createVector(), + angleBetween() returns + + angles in the units of the current + + angleMode().

+ path: .././src/content/reference/en//p5.Vector/angleBetween + lerp: + description: > +

Calculates new x, y, and z + components that are proportionally the + + same distance between two vectors. The amt parameter is the + amount to + + interpolate between the old vector and the new vector. 0.0 keeps all + + components equal to the old vector's, 0.5 is halfway between, and 1.0 sets + + all components equal to the new vector's.

+ +

The static version of lerp(), as in + p5.Vector.lerp(v0, v1, 0.5), + + returns a new p5.Vector object and doesn't + change + + the original.

+ path: .././src/content/reference/en//p5.Vector/lerp + slerp: + description: > +

Calculates a new heading and magnitude that are between two vectors. + The + + amt parameter is the amount to interpolate between the old + vector and + + the new vector. 0.0 keeps the heading and magnitude equal to the old + + vector's, 0.5 sets them halfway between, and 1.0 sets the heading and + + magnitude equal to the new vector's.

+ +

slerp() differs from lerp() + because + + it interpolates magnitude. Calling v0.slerp(v1, 0.5) sets + v0's + + magnitude to a value halfway between its original magnitude and + v1's. + + Calling v0.lerp(v1, 0.5) makes no such guarantee.

+ +

The static version of slerp(), as in + p5.Vector.slerp(v0, v1, 0.5), + + returns a new p5.Vector object and doesn't + change + + the original.

+ path: .././src/content/reference/en//p5.Vector/slerp + reflect: + description: > +

Reflects a vector about a line in 2D or a plane in 3D. The orientation + of + + the line or plane is described by a normal vector that points away from + the + + shape.

+ +

The static version of reflect(), as in + p5.Vector.reflect(v, n), + + returns a new p5.Vector object and doesn't + change + + the original.

+ path: .././src/content/reference/en//p5.Vector/reflect + array: + description: | +

Returns the vector's components as an array of numbers.

+ path: .././src/content/reference/en//p5.Vector/array + equals: + description: > +

Returns true if the vector's components are all the same + as another + + vector's and false if not.

+ +

The version of equals() with one parameter interprets it + as another + + p5.Vector object.

+ +

The version of equals() with multiple parameters + interprets them as the + + components of another vector. Any missing parameters are assigned the + value + + 0.

+ +

The static version of equals(), as in + p5.Vector.equals(v0, v1), + + interprets both parameters as p5.Vector + objects.

+ path: .././src/content/reference/en//p5.Vector/equals + fromAngle: + description: | +

Make a new 2D vector from an angle.

+ path: .././src/content/reference/en//p5.Vector/fromAngle + fromAngles: + description: | +

Make a new 3D vector from a pair of ISO spherical angles.

+ path: .././src/content/reference/en//p5.Vector/fromAngles + random2D: + description: | +

Make a new 2D unit vector with a random heading.

+ path: .././src/content/reference/en//p5.Vector/random2D + random3D: + description: | +

Make a new 3D unit vector with a random heading.

+ path: .././src/content/reference/en//p5.Vector/random3D +--- + + +# p5.Vector diff --git a/src/content/reference/en/p5/p5.XML.mdx b/src/content/reference/en/p5/p5.XML.mdx new file mode 100644 index 0000000000..ade08f60d8 --- /dev/null +++ b/src/content/reference/en/p5/p5.XML.mdx @@ -0,0 +1,141 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5.XML +module: IO +submodule: Input +file: src/io/p5.XML.js +description: > +

XML is a representation of an XML object, able to parse XML code. Use + + loadXML() to load external XML files and create XML + objects.

+isConstructor: true +line: 9 +memberMethodPreviews: + getParent: + description: | +

Gets a copy of the element's parent. Returns the parent as another + p5.XML object.

+ path: .././src/content/reference/en//p5.XML/getParent + getName: + description: | +

Gets the element's full name, which is returned as a String.

+ path: .././src/content/reference/en//p5.XML/getName + setName: + description: | +

Sets the element's name, which is specified as a String.

+ path: .././src/content/reference/en//p5.XML/setName + hasChildren: + description: > +

Checks whether or not the element has any children, and returns the + result + + as a boolean.

+ path: .././src/content/reference/en//p5.XML/hasChildren + listChildren: + description: > +

Get the names of all of the element's children, and returns the names + as an + + array of Strings. This is the same as looping through and calling getName() + + on each child element individually.

+ path: .././src/content/reference/en//p5.XML/listChildren + getChildren: + description: > +

Returns all of the element's children as an array of p5.XML objects. When + + the name parameter is specified, then it will return all children that + match + + that name.

+ path: .././src/content/reference/en//p5.XML/getChildren + getChild: + description: > +

Returns the first of the element's children that matches the name + parameter + + or the child of the given index.It returns undefined if no matching + + child is found.

+ path: .././src/content/reference/en//p5.XML/getChild + addChild: + description: > +

Appends a new child to the element. The child can be specified with + + either a String, which will be used as the new tag's name, or as a + + reference to an existing p5.XML object. + + A reference to the newly created child is returned as an p5.XML object.

+ path: .././src/content/reference/en//p5.XML/addChild + removeChild: + description: | +

Removes the element specified by name or index.

+ path: .././src/content/reference/en//p5.XML/removeChild + getAttributeCount: + description: > +

Counts the specified element's number of attributes, returned as an + Number.

+ path: .././src/content/reference/en//p5.XML/getAttributeCount + listAttributes: + description: | +

Gets all of the specified element's attributes, and returns them as an + array of Strings.

+ path: .././src/content/reference/en//p5.XML/listAttributes + hasAttribute: + description: | +

Checks whether or not an element has the specified attribute.

+ path: .././src/content/reference/en//p5.XML/hasAttribute + getNum: + description: > +

Returns an attribute value of the element as an Number. If the + defaultValue + + parameter is specified and the attribute doesn't exist, then defaultValue + + is returned. If no defaultValue is specified and the attribute doesn't + + exist, the value 0 is returned.

+ path: .././src/content/reference/en//p5.XML/getNum + getString: + description: > +

Returns an attribute value of the element as an String. If the + defaultValue + + parameter is specified and the attribute doesn't exist, then defaultValue + + is returned. If no defaultValue is specified and the attribute doesn't + + exist, null is returned.

+ path: .././src/content/reference/en//p5.XML/getString + setAttribute: + description: > +

Sets the content of an element's attribute. The first parameter + specifies + + the attribute name, while the second specifies the new content.

+ path: .././src/content/reference/en//p5.XML/setAttribute + getContent: + description: | +

Returns the content of an element. If there is no such content, + defaultValue is returned if specified, otherwise null is returned.

+ path: .././src/content/reference/en//p5.XML/getContent + setContent: + description: | +

Sets the element's content.

+ path: .././src/content/reference/en//p5.XML/setContent + serialize: + description: > +

Serializes the element into a string. This function is useful for + preparing + + the content to be sent over a http request or saved to file.

+ path: .././src/content/reference/en//p5.XML/serialize +--- + + +# p5.XML diff --git a/src/content/reference/en/p5/p5.mdx b/src/content/reference/en/p5/p5.mdx new file mode 100644 index 0000000000..6ded003e42 --- /dev/null +++ b/src/content/reference/en/p5/p5.mdx @@ -0,0 +1,39 @@ +--- +layout: '@layouts/reference/ClassReferenceLayout.astro' +title: p5 +module: IO +submodule: Output +file: src/core/main.js +description: | +

This is the p5 instance constructor.

+

A p5 instance holds all the properties and methods related to + a p5 sketch. It expects an incoming sketch closure and it can also + take an optional node parameter for attaching the generated p5 canvas + to a node. The sketch closure takes the newly created p5 instance as + its sole argument and may optionally set preload(), + setup(), and/or + draw() properties on it for running a sketch.

+

A p5 sketch can run in "global" or "instance" mode: + "global" - all properties and methods are attached to the window + "instance" - all properties and methods are bound to this p5 object

+isConstructor: true +line: 12 +params: + - name: sketch + description: | +

a closure that can set optional preload(), + setup(), and/or draw() properties on the + given p5 instance

+ type: Function(p5) + - name: node + description: | +

element to attach canvas to

+ type: HTMLElement + optional: true +return: + description: a p5 instance + type: P5 +--- + + +# p5 diff --git a/src/content/reference/en/p5/pAccelerationX.mdx b/src/content/reference/en/p5/pAccelerationX.mdx new file mode 100644 index 0000000000..8bc35b01b4 --- /dev/null +++ b/src/content/reference/en/p5/pAccelerationX.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pAccelerationX +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pAccelerationX always contains the acceleration of the + device along the x axis in the frame previous to the current frame. Value + is represented as meters per second squared.

+line: 90 +itemtype: property +class: p5 +chainable: false +--- + + +# pAccelerationX diff --git a/src/content/reference/en/p5/pAccelerationY.mdx b/src/content/reference/en/p5/pAccelerationY.mdx new file mode 100644 index 0000000000..186ffade2e --- /dev/null +++ b/src/content/reference/en/p5/pAccelerationY.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pAccelerationY +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pAccelerationY always contains the acceleration of the + device along the y axis in the frame previous to the current frame. Value + is represented as meters per second squared.

+line: 100 +itemtype: property +class: p5 +chainable: false +--- + + +# pAccelerationY diff --git a/src/content/reference/en/p5/pAccelerationZ.mdx b/src/content/reference/en/p5/pAccelerationZ.mdx new file mode 100644 index 0000000000..eeca60bc33 --- /dev/null +++ b/src/content/reference/en/p5/pAccelerationZ.mdx @@ -0,0 +1,18 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pAccelerationZ +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pAccelerationZ always contains the acceleration of the + device along the z axis in the frame previous to the current frame. Value + is represented as meters per second squared.

+line: 110 +itemtype: property +class: p5 +chainable: false +--- + + +# pAccelerationZ diff --git a/src/content/reference/en/p5/pRotationX.mdx b/src/content/reference/en/p5/pRotationX.mdx new file mode 100644 index 0000000000..eeefadaf5d --- /dev/null +++ b/src/content/reference/en/p5/pRotationX.mdx @@ -0,0 +1,53 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pRotationX +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pRotationX always contains the rotation of the + device along the x axis in the frame previous to the current frame. + If the sketch angleMode() is set to DEGREES, + the value will be -180 to 180. If it is set to RADIANS, the value will + be -PI to PI.

+

pRotationX can also be used with rotationX to determine the rotate + direction of the device along the X-axis.

+line: 234 +itemtype: property +class: p5 +example: + - |- + +
+ + // A simple if statement looking at whether + // rotationX - pRotationX < 0 is true or not will be + // sufficient for determining the rotate direction + // in most cases. + + // Some extra logic is needed to account for cases where + // the angles wrap around. + let rotateDirection = 'clockwise'; + + // Simple range conversion to make things simpler. + // This is not absolutely necessary but the logic + // will be different in that case. + + let rX = rotationX + 180; + let pRX = pRotationX + 180; + + if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) { + rotateDirection = 'clockwise'; + } else if (rX - pRX < 0 || rX - pRX > 270) { + rotateDirection = 'counter-clockwise'; + } + + print(rotateDirection); + describe('no image to display.'); + +
+chainable: false +--- + + +# pRotationX diff --git a/src/content/reference/en/p5/pRotationY.mdx b/src/content/reference/en/p5/pRotationY.mdx new file mode 100644 index 0000000000..427c08f33a --- /dev/null +++ b/src/content/reference/en/p5/pRotationY.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pRotationY +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pRotationY always contains the rotation of the + device along the y axis in the frame previous to the current frame. + If the sketch angleMode() is set to DEGREES, + the value will be -90 to 90. If it is set to RADIANS, the value will + be -PI/2 to PI/2.

+

pRotationY can also be used with rotationY to determine the rotate + direction of the device along the Y-axis.

+line: 278 +itemtype: property +class: p5 +example: + - |- + +
+ + // A simple if statement looking at whether + // rotationY - pRotationY < 0 is true or not will be + // sufficient for determining the rotate direction + // in most cases. + + // Some extra logic is needed to account for cases where + // the angles wrap around. + let rotateDirection = 'clockwise'; + + // Simple range conversion to make things simpler. + // This is not absolutely necessary but the logic + // will be different in that case. + + let rY = rotationY + 180; + let pRY = pRotationY + 180; + + if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) { + rotateDirection = 'clockwise'; + } else if (rY - pRY < 0 || rY - pRY > 270) { + rotateDirection = 'counter-clockwise'; + } + print(rotateDirection); + describe('no image to display.'); + +
+chainable: false +--- + + +# pRotationY diff --git a/src/content/reference/en/p5/pRotationZ.mdx b/src/content/reference/en/p5/pRotationZ.mdx new file mode 100644 index 0000000000..8413cdf9ac --- /dev/null +++ b/src/content/reference/en/p5/pRotationZ.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pRotationZ +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable pRotationZ always contains the rotation of the + device along the z axis in the frame previous to the current frame. + If the sketch angleMode() is set to DEGREES, + the value will be 0 to 360. If it is set to RADIANS, the value will + be 0 to 2*PI.

+

pRotationZ can also be used with rotationZ to determine the rotate + direction of the device along the Z-axis.

+line: 321 +itemtype: property +class: p5 +example: + - |- + +
+ + // A simple if statement looking at whether + // rotationZ - pRotationZ < 0 is true or not will be + // sufficient for determining the rotate direction + // in most cases. + + // Some extra logic is needed to account for cases where + // the angles wrap around. + let rotateDirection = 'clockwise'; + + if ( + (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) || + rotationZ - pRotationZ < -270 + ) { + rotateDirection = 'clockwise'; + } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) { + rotateDirection = 'counter-clockwise'; + } + print(rotateDirection); + describe('no image to display.'); + +
+chainable: false +--- + + +# pRotationZ diff --git a/src/content/reference/en/p5/perspective.mdx b/src/content/reference/en/p5/perspective.mdx new file mode 100644 index 0000000000..f649f4ff6a --- /dev/null +++ b/src/content/reference/en/p5/perspective.mdx @@ -0,0 +1,125 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: perspective +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: > +

Sets a perspective projection for the current camera in a 3D sketch. + + This projection represents depth through foreshortening: objects + + that are close to the camera appear their actual size while those + + that are further away from the camera appear smaller.

+ +

The parameters to this function define the viewing frustum + + (the truncated pyramid within which objects are seen by the camera) through + + vertical field of view, aspect ratio (usually width/height), and near and far + + clipping planes.

+ +

If no parameters are given, the default values are used as:

+ + + +

If you prefer a fixed field of view, follow these steps:

+ +
    + +
  1. Choose your desired field of view angle (fovy). This is how + wide the camera can see.
  2. + +
  3. To ensure that you can see the entire width across horizontally and height + across vertically, place the camera a distance of (height / 2) / + tan(fovy / 2) back from its subject.
  4. + +
  5. Call perspective with the chosen field of view, canvas aspect ratio, and + near/far values: + + perspective(fovy, width / height, cameraDistance / 10, cameraDistance * + 10);
  6. + +
+line: 121 +params: + - name: fovy + description: | +

camera frustum vertical field of view, + from bottom to top of view, in angleMode units

+ type: Number + optional: true + - name: aspect + description: | +

camera frustum aspect ratio

+ type: Number + optional: true + - name: near + description: | +

frustum near plane length

+ type: Number + optional: true + - name: far + description: | +

frustum far plane length

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + //drag the mouse to look around! + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI / 3.0, width / height, 0.1, 500); + describe( + 'two colored 3D boxes move back and forth, rotating as mouse is dragged.' + ); + } + function draw() { + background(200); + orbitControl(); + normalMaterial(); + + rotateX(-0.3); + rotateY(-0.2); + translate(0, 0, -50); + + push(); + translate(-15, 0, sin(frameCount / 30) * 65); + box(30); + pop(); + push(); + translate(15, 0, sin(frameCount / 30 + PI) * 65); + box(30); + pop(); + } + +
+alt: 'two colored 3D boxes move back and forth, rotating as mouse is dragged.' +chainable: true +--- + + +# perspective diff --git a/src/content/reference/en/p5/pixelDensity.mdx b/src/content/reference/en/p5/pixelDensity.mdx new file mode 100644 index 0000000000..e99e0c9309 --- /dev/null +++ b/src/content/reference/en/p5/pixelDensity.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixelDensity +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Sets the pixel scaling for high pixel density displays.

+ +

By default, the pixel density is set to match display density. Calling + + pixelDensity(1) turn this off.

+ +

Calling pixelDensity() without an argument returns the current + pixel + + density.

+line: 943 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Set the pixel density to 1. + pixelDensity(1); + + // Create a canvas and draw + // a circle. + createCanvas(100, 100); + background(200); + circle(50, 50, 70); + + describe('A fuzzy white circle on a gray canvas.'); + } + +
+ +
+ + function setup() { + // Set the pixel density to 3. + pixelDensity(3); + + // Create a canvas, paint the + // background, and draw a + // circle. + createCanvas(100, 100); + background(200); + circle(50, 50, 70); + + describe('A sharp white circle on a gray canvas.'); + } + +
+chainable: true +--- + + +# pixelDensity diff --git a/src/content/reference/en/p5/pixels.mdx b/src/content/reference/en/p5/pixels.mdx new file mode 100644 index 0000000000..27d12f3e4f --- /dev/null +++ b/src/content/reference/en/p5/pixels.mdx @@ -0,0 +1,124 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pixels +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

An array containing the color of each pixel on the canvas. Colors are + + stored as numbers representing red, green, blue, and alpha (RGBA) values. + + pixels is a one-dimensional array for performance reasons.

+ +

Each pixel occupies four elements in the pixels array, one for + each RGBA + + value. For example, the pixel at coordinates (0, 0) stores its RGBA values + + at pixels[0], pixels[1], pixels[2], and + pixels[3], respectively. + + The next pixel at coordinates (1, 0) stores its RGBA values at + pixels[4], + + pixels[5], pixels[6], and pixels[7]. + And so on. The pixels array + + for a 100×100 canvas has 100 × 100 × 4 = 40,000 elements.

+ +

Some displays use several smaller pixels to set the color at a single + + point. The pixelDensity() function returns + + the pixel density of the canvas. High density displays often have a + + pixelDensity() of 2. On such a display, the + + pixels array for a 100×100 canvas has 200 × 200 × 4 = + + 160,000 elements.

+ +

Accessing the RGBA values for a point on the canvas requires a little math + + as shown below. The loadPixels() function + + must be called before accessing the pixels array. The + + updatePixels() function must be called + + after any changes are made.

+line: 12 +itemtype: property +class: p5 +example: + - |- + +
+ + loadPixels(); + let x = 50; + let y = 50; + let d = pixelDensity(); + for (let i = 0; i < d; i += 1) { + for (let j = 0; j < d; j += 1) { + let index = 4 * ((y * d + j) * width * d + (x * d + i)); + // Red. + pixels[index] = 0; + // Green. + pixels[index + 1] = 0; + // Blue. + pixels[index + 2] = 0; + // Alpha. + pixels[index + 3] = 255; + } + } + updatePixels(); + + describe('A black dot in the middle of a gray rectangle.'); + +
+ +
+ + loadPixels(); + let d = pixelDensity(); + let halfImage = 4 * (d * width) * (d * height / 2); + for (let i = 0; i < halfImage; i += 4) { + // Red. + pixels[i] = 255; + // Green. + pixels[i + 1] = 0; + // Blue. + pixels[i + 2] = 0; + // Alpha. + pixels[i + 3] = 255; + } + updatePixels(); + + describe('A red rectangle drawn above a gray rectangle.'); + +
+ +
+ + let pink = color(255, 102, 204); + loadPixels(); + let d = pixelDensity(); + let halfImage = 4 * (d * width) * (d * height / 2); + for (let i = 0; i < halfImage; i += 4) { + pixels[i] = red(pink); + pixels[i + 1] = green(pink); + pixels[i + 2] = blue(pink); + pixels[i + 3] = alpha(pink); + } + updatePixels(); + + describe('A pink rectangle drawn above a gray rectangle.'); + +
+chainable: false +--- + + +# pixels diff --git a/src/content/reference/en/p5/plane.mdx b/src/content/reference/en/p5/plane.mdx new file mode 100644 index 0000000000..f0036de11d --- /dev/null +++ b/src/content/reference/en/p5/plane.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: plane +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: | +

Draw a plane with given a width and height

+line: 183 +params: + - name: width + description: | +

width of the plane

+ type: Number + optional: true + - name: height + description: | +

height of the plane

+ type: Number + optional: true + - name: detailX + description: | +

Optional number of triangle + subdivisions in x-dimension

+ type: Integer + optional: true + - name: detailY + description: | +

Optional number of triangle + subdivisions in y-dimension

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a plane + // with width 50 and height 50 + function setup() { + createCanvas(100, 100, WEBGL); + describe('a white plane with black wireframe lines'); + } + + function draw() { + background(200); + plane(50, 50); + } + +
+alt: |- + Nothing displayed on canvas + Rotating interior view of a box with sides that change color. + 3d red and green gradient. + Rotating interior view of a cylinder with sides that change color. + Rotating view of a cylinder with sides that change color. + 3d red and green gradient. + rotating view of a multi-colored cylinder with concave sides. +chainable: true +--- + + +# plane diff --git a/src/content/reference/en/p5/pmouseX.mdx b/src/content/reference/en/p5/pmouseX.mdx new file mode 100644 index 0000000000..1663629938 --- /dev/null +++ b/src/content/reference/en/p5/pmouseX.mdx @@ -0,0 +1,45 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pmouseX +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The system variable pmouseX always contains the horizontal position of + + the mouse or finger in the frame previous to the current frame, relative to + + (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and + + (-width/2, -height/2) for WebGL. Note: pmouseX will be reset to the current + mouseX + + value at the start of each touch event.

+line: 128 +itemtype: property +class: p5 +example: + - |- + +
+ + // Move the mouse across the canvas to leave a trail + function setup() { + //slow down the frameRate to make it more visible + frameRate(10); + } + + function draw() { + background(244, 248, 252); + line(mouseX, mouseY, pmouseX, pmouseY); + print(pmouseX + ' -> ' + mouseX); + describe(`line trail is created from cursor movements. + faster movement make longer line.`); + } + +
+chainable: false +--- + + +# pmouseX diff --git a/src/content/reference/en/p5/pmouseY.mdx b/src/content/reference/en/p5/pmouseY.mdx new file mode 100644 index 0000000000..45fcab06e7 --- /dev/null +++ b/src/content/reference/en/p5/pmouseY.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pmouseY +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The system variable pmouseY always contains the vertical position of + + the mouse or finger in the frame previous to the current frame, relative to + + (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and + + (-width/2, -height/2) for WebGL. Note: pmouseY will be reset to the current + mouseY + + value at the start of each touch event.

+line: 159 +itemtype: property +class: p5 +example: + - |- + +
+ + function draw() { + background(237, 34, 93); + fill(0); + //draw a square only if the mouse is not moving + if (mouseY === pmouseY && mouseX === pmouseX) { + rect(20, 20, 60, 60); + } + + print(pmouseY + ' -> ' + mouseY); + describe(`60-by-60 black rect center, fuchsia background. + rect flickers on mouse movement`); + } + +
+chainable: false +--- + + +# pmouseY diff --git a/src/content/reference/en/p5/point.mdx b/src/content/reference/en/p5/point.mdx new file mode 100644 index 0000000000..8f18af13a0 --- /dev/null +++ b/src/content/reference/en/p5/point.mdx @@ -0,0 +1,80 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: point +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws a point, a single coordinate in space. Its default size is one pixel. + The first two + + parameters are the point's x- and y-coordinates, respectively. To color a + point, use + + the stroke() function. To change its size, use the + + strokeWeight() function.

+ +

The version of point() with three parameters allows the point + to be drawn in 3D + + space. Doing so requires adding the WEBGL argument to + + createCanvas().

+ +

The version of point() with one parameter allows the point's location to be + set with + + a p5.Vector object.

+line: 416 +itemtype: method +class: p5 +example: + - | + +
+ + point(30, 20); + point(85, 20); + point(85, 75); + point(30, 75); + describe( + 'Four small, black points drawn on a gray canvas. The points form the corners of a square.' + ); + +
+ +
+ + point(30, 20); + point(85, 20); + stroke('purple'); + strokeWeight(10); + point(85, 75); + point(30, 75); + describe( + 'Four points drawn on a gray canvas. Two are black and two are purple. The points form the corners of a square.' + ); + +
+ +
+ + let a = createVector(10, 10); + point(a); + let b = createVector(10, 20); + point(b); + let c = createVector(20, 10); + point(c); + let d = createVector(20, 20); + point(d); + describe( + 'Four small, black points drawn on a gray canvas. The points form the corners of a square.' + ); + +
+chainable: true +--- + + +# point diff --git a/src/content/reference/en/p5/pointLight.mdx b/src/content/reference/en/p5/pointLight.mdx new file mode 100644 index 0000000000..c3dcbeddd6 --- /dev/null +++ b/src/content/reference/en/p5/pointLight.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pointLight +module: 3D +submodule: Lights +file: src/webgl/light.js +description: | +

Creates a point light with the given color and position.

+

A point light emits light from a single point in all directions. + Because the light is emitted from a specific point (position), + it has a different effect when it is positioned farther vs. nearer + an object.

+

A maximum of 5 point lights can be active at once.

+

Note: lights need to be called (whether directly or indirectly) + within draw() to remain persistent in a looping program. + Placing them in setup() will cause them to only have an effect + the first time through the loop.

+line: 373 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe( + 'scene with sphere and point light. The position of the light is controlled with the mouse position.' + ); + } + function draw() { + background(0); + // move your mouse to change light position + let locX = mouseX - width / 2; + let locY = mouseY - height / 2; + // to set the light position, + // think of the world's coordinate as: + // -width/2,-height/2 ----------- width/2,-height/2 + // | | + // | 0,0 | + // | | + // -width/2,height/2 ----------- width/2,height/2 + pointLight(250, 250, 250, locX, locY, 50); + noStroke(); + sphere(40); + } + +
+alt: |- + scene with sphere and point light. The position of + the light is controlled with the mouse position. +chainable: true +--- + + +# pointLight diff --git a/src/content/reference/en/p5/pop.mdx b/src/content/reference/en/p5/pop.mdx new file mode 100644 index 0000000000..c36da18ede --- /dev/null +++ b/src/content/reference/en/p5/pop.mdx @@ -0,0 +1,148 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pop +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

The push() function saves the current drawing style + + settings and transformations, while pop() restores + + these settings. Note that these functions are always used together. They allow + + you to change the style and transformation settings and later return to what + + you had. When a new state is started with push(), it + + builds on the current style and transform information. The push() + + and pop() functions can be embedded to provide more + + control. (See the second example for a demonstration.)

+ +

push() stores information related to the current + transformation state + + and style settings controlled by the following functions: + + fill(), + + noFill(), + + noStroke(), + + stroke(), + + tint(), + + noTint(), + + strokeWeight(), + + strokeCap(), + + strokeJoin(), + + imageMode(), + + rectMode(), + + ellipseMode(), + + colorMode(), + + textAlign(), + + textFont(), + + textSize(), + + textLeading(), + + applyMatrix(), + + resetMatrix(), + + rotate(), + + scale(), + + shearX(), + + shearY(), + + translate(), + + noiseSeed().

+ +

In WEBGL mode additional style settings are stored. These are controlled by + + the following functions: + + setCamera(), + + ambientLight(), + + directionalLight(), + + pointLight(), + + texture(), + + specularMaterial(), + + shininess(), + + normalMaterial() and + + shader().

+line: 290 +itemtype: method +class: p5 +example: + - |- + +
+ + ellipse(0, 50, 33, 33); // Left circle + + push(); // Start a new drawing state + translate(50, 0); + strokeWeight(10); + fill(204, 153, 0); + ellipse(0, 50, 33, 33); // Middle circle + pop(); // Restore original state + + ellipse(100, 50, 33, 33); // Right circle + +
+ +
+ + ellipse(0, 50, 33, 33); // Left circle + + push(); // Start a new drawing state + strokeWeight(10); + fill(204, 153, 0); + ellipse(33, 50, 33, 33); // Left-middle circle + + push(); // Start another new drawing state + stroke(0, 102, 153); + ellipse(66, 50, 33, 33); // Right-middle circle + pop(); // Restore previous state + + pop(); // Restore original state + + ellipse(100, 50, 33, 33); // Right circle + +
+alt: |- + Gold ellipse + thick black outline @center 2 white ellipses on left and right. + 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. +chainable: false +--- + + +# pop diff --git a/src/content/reference/en/p5/pow.mdx b/src/content/reference/en/p5/pow.mdx new file mode 100644 index 0000000000..3e881e8f78 --- /dev/null +++ b/src/content/reference/en/p5/pow.mdx @@ -0,0 +1,67 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pow +module: Math +submodule: Calculation +file: src/math/calculation.js +description: | +

Calculates exponential expressions such as 2^3.

+

For example, pow(2, 3) is equivalent to the expression + 2 × 2 × 2. pow(2, -3) is equivalent to 1 ÷ + (2 × 2 × 2).

+line: 601 +params: + - name: 'n' + description: | +

base of the exponential expression.

+ type: Number + - name: e + description: | +

power by which to raise the base.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + let base = 3; + + + let d = pow(base, 1); + + circle(10, 10, d); + + + d = pow(base, 2); + + circle(20, 20, d); + + + d = pow(base, 3); + + circle(40, 40, d); + + + d = pow(base, 4); + + circle(80, 80, d); + + + describe('A series of circles that grow exponentially from top left to + bottom right.'); + + + +
+return: + description: n^e. + type: Number +chainable: false +--- + + +# pow diff --git a/src/content/reference/en/p5/preload.mdx b/src/content/reference/en/p5/preload.mdx new file mode 100644 index 0000000000..c6a61dd401 --- /dev/null +++ b/src/content/reference/en/p5/preload.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: preload +module: Structure +submodule: Structure +file: src/core/main.js +description: > +

Called directly before setup(), the preload() function is used to handle + + asynchronous loading of external files in a blocking way. If a preload + + function is defined, setup() will wait until any load + calls within have + + finished. Nothing besides load calls (loadImage, + loadJSON, loadFont, + + loadStrings, etc.) should be inside the preload + function. If asynchronous + + loading is preferred, the load methods can instead be called in setup() + + or anywhere else with the use of a callback parameter.

+ +

By default the text "loading..." will be displayed. To make your own + + loading page, include an HTML element with id "p5_loading" in your + + page. More information here.

+line: 41 +itemtype: method +class: p5 +example: + - |- + +
+ let img; + let c; + function preload() { + // preload() runs once + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + // setup() waits until preload() is done + img.loadPixels(); + // get color of middle pixel + c = img.get(img.width / 2, img.height / 2); + } + + function draw() { + background(c); + image(img, 25, 25, 50, 50); + } +
+alt: nothing displayed +chainable: false +--- + + +# preload diff --git a/src/content/reference/en/p5/print.mdx b/src/content/reference/en/p5/print.mdx new file mode 100644 index 0000000000..481618e51c --- /dev/null +++ b/src/content/reference/en/p5/print.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: print +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

Displays text in the web browser's console.

+ +

print() is helpful for printing values while debugging. Each + call to + + print() creates a new line of text.

+ +

Note: Call print('\n') to print a blank line. Calling + print() without + + an argument opens the browser's dialog for printing documents.

+line: 21 +params: + - name: contents + description: | +

content to print to the console.

+ type: Any +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Prints "hello, world" to the console. + print('hello, world'); + } + +
+ +
+ + function setup() { + let name = 'ada'; + // Prints "hello, ada" to the console. + print(`hello, ${name}`); + } + +
+chainable: false +--- + + +# print diff --git a/src/content/reference/en/p5/push.mdx b/src/content/reference/en/p5/push.mdx new file mode 100644 index 0000000000..e1d237cb38 --- /dev/null +++ b/src/content/reference/en/p5/push.mdx @@ -0,0 +1,148 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: push +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

The push() function saves the current drawing style + + settings and transformations, while pop() restores + these + + settings. Note that these functions are always used together. They allow you + to + + change the style and transformation settings and later return to what you had. + + When a new state is started with push(), it builds on + + the current style and transform information. The push() + + and pop() functions can be embedded to provide more + + control. (See the second example for a demonstration.)

+ +

push() stores information related to the current + transformation state + + and style settings controlled by the following functions: + + fill(), + + noFill(), + + noStroke(), + + stroke(), + + tint(), + + noTint(), + + strokeWeight(), + + strokeCap(), + + strokeJoin(), + + imageMode(), + + rectMode(), + + ellipseMode(), + + colorMode(), + + textAlign(), + + textFont(), + + textSize(), + + textLeading(), + + applyMatrix(), + + resetMatrix(), + + rotate(), + + scale(), + + shearX(), + + shearY(), + + translate(), + + noiseSeed().

+ +

In WEBGL mode additional style settings are stored. These are controlled by + the + + following functions: setCamera(), + + ambientLight(), + + directionalLight(), + + pointLight(), texture(), + + specularMaterial(), + + shininess(), + + normalMaterial() + + and shader().

+line: 192 +itemtype: method +class: p5 +example: + - |- + +
+ + ellipse(0, 50, 33, 33); // Left circle + + push(); // Start a new drawing state + strokeWeight(10); + fill(204, 153, 0); + translate(50, 0); + ellipse(0, 50, 33, 33); // Middle circle + pop(); // Restore original state + + ellipse(100, 50, 33, 33); // Right circle + +
+ +
+ + ellipse(0, 50, 33, 33); // Left circle + + push(); // Start a new drawing state + strokeWeight(10); + fill(204, 153, 0); + ellipse(33, 50, 33, 33); // Left-middle circle + + push(); // Start another new drawing state + stroke(0, 102, 153); + ellipse(66, 50, 33, 33); // Right-middle circle + pop(); // Restore previous state + + pop(); // Restore original state + + ellipse(100, 50, 33, 33); // Right circle + +
+alt: |- + Gold ellipse + thick black outline @center 2 white ellipses on left and right. + 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. +chainable: false +--- + + +# push diff --git a/src/content/reference/en/p5/pwinMouseX.mdx b/src/content/reference/en/p5/pwinMouseX.mdx new file mode 100644 index 0000000000..d67bebd7a6 --- /dev/null +++ b/src/content/reference/en/p5/pwinMouseX.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pwinMouseX +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable pwinMouseX always contains the horizontal position + of the mouse in the frame previous to the current frame, relative to + (0, 0) of the window. Note: pwinMouseX will be reset to the current winMouseX + value at the start of each touch event.

+line: 263 +itemtype: property +class: p5 +example: + - |- + +
+ + let myCanvas; + + function setup() { + //use a variable to store a pointer to the canvas + myCanvas = createCanvas(100, 100); + noStroke(); + fill(237, 34, 93); + } + + function draw() { + clear(); + //the difference between previous and + //current x position is the horizontal mouse speed + let speed = abs(winMouseX - pwinMouseX); + //change the size of the circle + //according to the horizontal speed + ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); + //move the canvas to the mouse position + myCanvas.position(winMouseX + 1, winMouseY + 1); + describe(`fuchsia ellipse moves with mouse x and y. + Grows and shrinks with mouse speed`); + } + +
+chainable: false +--- + + +# pwinMouseX diff --git a/src/content/reference/en/p5/pwinMouseY.mdx b/src/content/reference/en/p5/pwinMouseY.mdx new file mode 100644 index 0000000000..ab517c501b --- /dev/null +++ b/src/content/reference/en/p5/pwinMouseY.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: pwinMouseY +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable pwinMouseY always contains the vertical position of + the mouse in the frame previous to the current frame, relative to (0, 0) + of the window. Note: pwinMouseY will be reset to the current winMouseY + value at the start of each touch event.

+line: 302 +itemtype: property +class: p5 +example: + - |- + +
+ + let myCanvas; + + function setup() { + //use a variable to store a pointer to the canvas + myCanvas = createCanvas(100, 100); + noStroke(); + fill(237, 34, 93); + } + + function draw() { + clear(); + //the difference between previous and + //current y position is the vertical mouse speed + let speed = abs(winMouseY - pwinMouseY); + //change the size of the circle + //according to the vertical speed + ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); + //move the canvas to the mouse position + myCanvas.position(winMouseX + 1, winMouseY + 1); + describe(`fuchsia ellipse moves with mouse x and y. + Grows and shrinks with mouse speed`); + } + +
+chainable: false +--- + + +# pwinMouseY diff --git a/src/content/reference/en/p5/quad.mdx b/src/content/reference/en/p5/quad.mdx new file mode 100644 index 0000000000..a790abc073 --- /dev/null +++ b/src/content/reference/en/p5/quad.mdx @@ -0,0 +1,64 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: quad +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws a quad to the canvas. A quad is a quadrilateral, a four-sided + + polygon. Some examples of quads include rectangles, squares, rhombuses, + + and trapezoids. The first pair of parameters (x1,y1) + sets the quad's + + first point. The following pairs of parameters set the coordinates for + + its next three points. Parameters should proceed clockwise or + + counter-clockwise around the shape.

+ +

The version of quad() with twelve parameters allows the quad + to be drawn + + in 3D space. Doing so requires adding the WEBGL argument to + + createCanvas().

+line: 507 +itemtype: method +class: p5 +example: + - |- + +
+ + quad(20, 20, 80, 20, 80, 80, 20, 80); + describe('A white square with a black outline drawn on a gray canvas.'); + +
+ +
+ + quad(20, 30, 80, 30, 80, 70, 20, 70); + describe('A white rectangle with a black outline drawn on a gray canvas.'); + +
+ +
+ + quad(50, 62, 86, 50, 50, 38, 14, 50); + describe('A white rhombus with a black outline drawn on a gray canvas.'); + +
+ +
+ + quad(20, 50, 80, 30, 80, 70, 20, 70); + describe('A white trapezoid with a black outline drawn on a gray canvas.'); + +
+chainable: true +--- + + +# quad diff --git a/src/content/reference/en/p5/quadraticVertex.mdx b/src/content/reference/en/p5/quadraticVertex.mdx new file mode 100644 index 0000000000..92b896e416 --- /dev/null +++ b/src/content/reference/en/p5/quadraticVertex.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: quadraticVertex +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

Specifies vertex coordinates for quadratic Bezier curves. Each call to + + quadraticVertex() defines the position of one control points and one + + anchor point of a Bezier curve, adding a new segment to a line or shape. + + The first time quadraticVertex() is used within a beginShape() call, it + + must be prefaced with a call to vertex() to set the + first anchor point. + + For WebGL mode quadraticVertex() can be used in 2D as well as 3D mode. + + 2D mode expects 4 parameters, while 3D mode expects 6 parameters + + (including z coordinates).

+ +

This function must be used between beginShape() and endShape() + + and only when there is no MODE or POINTS parameter specified to + + beginShape().

+line: 772 +itemtype: method +class: p5 +example: + - |- + +
+ + strokeWeight(5); + point(20, 20); + point(80, 20); + point(50, 50); + + noFill(); + strokeWeight(1); + beginShape(); + vertex(20, 20); + quadraticVertex(80, 20, 50, 50); + endShape(); + +
+ +
+ + strokeWeight(5); + point(20, 20); + point(80, 20); + point(50, 50); + + point(20, 80); + point(80, 80); + point(80, 60); + + noFill(); + strokeWeight(1); + beginShape(); + vertex(20, 20); + quadraticVertex(80, 20, 50, 50); + quadraticVertex(20, 80, 80, 80); + vertex(80, 60); + endShape(); + +
+alt: |- + arched-shaped black line with 4 pixel thick stroke weight. + backwards s-shaped black line with 4 pixel thick stroke weight. +chainable: true +--- + + +# quadraticVertex diff --git a/src/content/reference/en/p5/random.mdx b/src/content/reference/en/p5/random.mdx new file mode 100644 index 0000000000..43110099e4 --- /dev/null +++ b/src/content/reference/en/p5/random.mdx @@ -0,0 +1,20 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: random +module: Math +submodule: Random +file: src/math/random.js +description: "

Returns a random number or a random element from an array.

\n

random() follows uniform distribution, which means that all outcomes are\nequally likely. When random() is used to generate numbers, all\nnumbers in the output range are equally likely to be returned. When\nrandom() is used to select elements from an array, all elements are\nequally likely to be chosen.

\n

By default, random() produces different results each time a sketch runs.\nThe randomSeed() function can be used to\ngenerate the same sequence of numbers or choices each time a sketch runs.

\n

The version of random() with no parameters returns a random number from 0\nup to but not including 1.

\n

The version of random() with one parameter works one of two ways. If the\nargument passed is a number, random() returns a random number from 0 up\nto but not including the number. For example, calling random(5) returns\nvalues between 0 and 5. If the argument passed is an array, random()\nreturns a random element from that array. For example, calling\nrandom(['\U0001F981', '\U0001F42F', '\U0001F43B']) returns either a lion, tiger, or bear emoji.

\n

The version of random() with two parameters returns a random number from\na given range. The arguments passed set the range's lower and upper bounds.\nFor example, calling random(-5, 10.2) returns values from -5 up to but\nnot including 10.2.

\n" +line: 70 +itemtype: method +class: p5 +example: + - "\n
\n\nlet x = random(width);\nlet y = random(height);\n\nstrokeWeight(5);\npoint(x, y);\n\ndescribe('A black dot appears in a random position on a gray square.');\n\n
\n\n
\n\nlet animals = ['\U0001F981', '\U0001F42F', '\U0001F43B'];\nlet animal = random(animals);\ntext(animal, 50, 50);\n\ndescribe('An animal face is displayed at random. Either a lion, tiger, or bear.');\n\n
\n\n
\n\nfunction draw() {\n background(200);\n\n frameRate(5);\n let x = random(width);\n let y = random(height);\n\n strokeWeight(5);\n point(x, y);\n\n describe('A black dot moves around randomly on a gray square.');\n}\n\n
\n\n
\n\nfunction draw() {\n background(200);\n\n frameRate(5);\n let x = random(45, 55);\n let y = random(45, 55);\n\n strokeWeight(5);\n point(x, y);\n\n describe('A black dot moves around randomly in the middle of a gray square.');\n}\n\n
" +return: + description: random number. + type: Number +chainable: false +--- + + +# random diff --git a/src/content/reference/en/p5/randomGaussian.mdx b/src/content/reference/en/p5/randomGaussian.mdx new file mode 100644 index 0000000000..ae2ca0d542 --- /dev/null +++ b/src/content/reference/en/p5/randomGaussian.mdx @@ -0,0 +1,93 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: randomGaussian +module: Math +submodule: Random +file: src/math/random.js +description: > +

Returns a random number fitting a Gaussian, or normal, distribution. Normal + + distributions look like bell curves when plotted. Values from a normal + + distribution cluster around a central value called the mean. The cluster's + + standard deviation describes its spread.

+ +

By default, randomGaussian() produces different results each + time a + + sketch runs. The randomSeed() function can be + + used to generate the same sequence of numbers each time a sketch runs.

+ +

There's no minimum or maximum value that randomGaussian() + might return. + + Values far from the mean are very unlikely and values near the mean are + + very likely.

+ +

The version of randomGaussian() with no parameters returns + values with a + + mean of 0 and standard deviation of 1.

+ +

The version of randomGaussian() with one parameter interprets + the + + argument passed as the mean. The standard deviation is 1.

+ +

The version of randomGaussian() with two parameters interprets + the first + + argument passed as the mean and the second as the standard deviation.

+line: 193 +params: + - name: mean + description: | +

mean.

+ type: Number + optional: true + - name: sd + description: | +

standard deviation.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + noStroke(); + fill(0, 10); + + // Uniform distribution. + let x = random(width); + let y = 25; + circle(x, y, 5); + + // Gaussian distribution with sd = 1. + x = randomGaussian(50); + y = 50; + circle(x, y, 5); + + // Gaussian distribution with sd = 10. + x = randomGaussian(50, 10); + y = 75; + circle(x, y, 5); + + describe('Three horizontal black lines are filled in randomly. The top line spans entire canvas. The middle line is very short. The bottom line spans two-thirds of the canvas.'); + } + +
+return: + description: random number. + type: Number +chainable: false +--- + + +# randomGaussian diff --git a/src/content/reference/en/p5/randomSeed.mdx b/src/content/reference/en/p5/randomSeed.mdx new file mode 100644 index 0000000000..d70dcdc98b --- /dev/null +++ b/src/content/reference/en/p5/randomSeed.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: randomSeed +module: Math +submodule: Random +file: src/math/random.js +description: > +

Sets the seed value for random() and + + randomGaussian(). By default, + + random() and + + randomGaussian() produce different + + results each time a sketch is run. Calling randomSeed() with a + constant + + argument, such as randomSeed(99), makes these functions produce + the same + + results each time a sketch is run.

+line: 37 +params: + - name: seed + description: | +

seed value.

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + let x = random(width); + + let y = random(height); + + circle(x, y, 10); + + + randomSeed(99); + + x = random(width); + + y = random(height); + + fill(0); + + circle(x, y, 10); + + + describe('A white circle appears at a random position. A black circle + appears at (27.4, 25.8).'); + + + +
+chainable: false +--- + + +# randomSeed diff --git a/src/content/reference/en/p5/rect.mdx b/src/content/reference/en/p5/rect.mdx new file mode 100644 index 0000000000..0b611819a7 --- /dev/null +++ b/src/content/reference/en/p5/rect.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rect +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws a rectangle to the canvas. A rectangle is a four-sided polygon with + + every angle at ninety degrees. By default, the first two parameters set the + + location of the rectangle's upper-left corner. The third and fourth set the + + shape's the width and height, respectively. The way these parameters are + + interpreted may be changed with the rectMode() + + function.

+ +

The version of rect() with five parameters creates a rounded + rectangle. The + + fifth parameter is used as the radius value for all four corners.

+ +

The version of rect() with eight parameters also creates a + rounded rectangle. + + When using eight parameters, the latter four set the radius of the arc at + + each corner separately. The radii start with the top-left corner and move + + clockwise around the rectangle. If any of these parameters are omitted, they + + are set to the value of the last specified corner radius.

+line: 603 +itemtype: method +class: p5 +example: + - > + +
+ + + + rect(30, 20, 55, 55); + + describe('A white rectangle with a black outline on a gray canvas.'); + + + +
+ + +
+ + + + rect(30, 20, 55, 55, 20); + + describe( + 'A white rectangle with a black outline and round edges on a gray canvas.' + ); + + + +
+ + +
+ + + + rect(30, 20, 55, 55, 20, 15, 10, 5); + + describe('A white rectangle with a black outline and round edges of + different radii.'); + + + +
+chainable: true +--- + + +# rect diff --git a/src/content/reference/en/p5/rectMode.mdx b/src/content/reference/en/p5/rectMode.mdx new file mode 100644 index 0000000000..c1670b7fd6 --- /dev/null +++ b/src/content/reference/en/p5/rectMode.mdx @@ -0,0 +1,108 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rectMode +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Modifies the location from which rectangles and squares are drawn. By + default, + + the first two parameters are the x- and y-coordinates of the shape's + upper-left + + corner. The next parameters are its width and height. This is equivalent to + + calling rectMode(CORNER).

+ +

rectMode(CORNERS) also uses the first two parameters as the + location of one of + + the corners. The third and fourth parameters are the location of the opposite + + corner.

+ +

rectMode(CENTER) uses the first two parameters as the x- and + y-coordinates of + + the shape's center. The next parameters are its width and height.

+ +

rectMode(RADIUS) also uses the first two parameters as the x- + and y-coordinates + + of the shape's center. The next parameters are half of the shape's width and + + height.

+ +

The argument passed to rectMode() must be written in ALL CAPS + because the + + constants CENTER, RADIUS, CORNER, and + CORNERS are defined this way. + + JavaScript is a case-sensitive language.

+line: 108 +params: + - name: mode + description: | +

either CORNER, CORNERS, CENTER, or RADIUS

+ type: Constant +itemtype: method +class: p5 +example: + - >- + +
+ + + + rectMode(CORNER); + + fill(255); + + rect(25, 25, 50, 50); + + + rectMode(CORNERS); + + fill(100); + + rect(25, 25, 50, 50); + + + describe('A small gray square drawn at the top-left corner of a white + square.'); + + + +
+ + +
+ + + + rectMode(RADIUS); + + fill(255); + + rect(50, 50, 30, 30); + + + rectMode(CENTER); + + fill(100); + + rect(50, 50, 30, 30); + + + describe('A small gray square drawn at the center of a white square.'); + + + +
+chainable: true +--- + + +# rectMode diff --git a/src/content/reference/en/p5/red.mdx b/src/content/reference/en/p5/red.mdx new file mode 100644 index 0000000000..1b0d9a4a3d --- /dev/null +++ b/src/content/reference/en/p5/red.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: red +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the red value from a + p5.Color object, array of color components, or + CSS color string.

+line: 505 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - |- + +
+ + const c = color(255, 204, 0); + fill(c); + rect(15, 20, 35, 60); + // Sets 'redValue' to 255. + const redValue = red(c); + fill(redValue, 0, 0); + rect(50, 20, 35, 60); + describe( + 'Two rectangles with black edges. The rectangle on the left is yellow and the one on the right is red.' + ); + +
+return: + description: the red value. + type: Number +chainable: false +--- + + +# red diff --git a/src/content/reference/en/p5/redraw.mdx b/src/content/reference/en/p5/redraw.mdx new file mode 100644 index 0000000000..ff1e42a8bf --- /dev/null +++ b/src/content/reference/en/p5/redraw.mdx @@ -0,0 +1,96 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: redraw +module: Structure +submodule: Structure +file: src/core/structure.js +description: > +

Executes the code within draw() one time. This + + function allows the program to update the display window only when necessary, + + for example when an event registered by mousePressed() + + or keyPressed() occurs.

+ +

In structuring a program, it only makes sense to call redraw() + + within events such as mousePressed(). This + + is because redraw() does not run + + draw() immediately (it only sets a flag that indicates + + an update is needed).

+ +

The redraw() function does not work properly when + + called inside draw().To enable/disable animations, + + use loop() and noLoop().

+ +

In addition you can set the number of redraws per method call. Just + + add an integer as single parameter for the number of redraws.

+line: 391 +params: + - name: 'n' + description: | +

Redraw for n-times. The default value is 1.

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ let x = 0; + + function setup() { + createCanvas(100, 100); + noLoop(); + } + + function draw() { + background(204); + line(x, 0, x, height); + } + + function mousePressed() { + x += 1; + redraw(); + } + +
+ +
+ + let x = 0; + + function setup() { + createCanvas(100, 100); + noLoop(); + } + + function draw() { + background(204); + x += 1; + line(x, 0, x, height); + } + + function mousePressed() { + redraw(5); + } + +
+alt: |- + black line on far left of canvas + black line on far left of canvas +chainable: false +--- + + +# redraw diff --git a/src/content/reference/en/p5/removeElements.mdx b/src/content/reference/en/p5/removeElements.mdx new file mode 100644 index 0000000000..f00eb8946f --- /dev/null +++ b/src/content/reference/en/p5/removeElements.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeElements +module: DOM +submodule: DOM +file: src/dom/dom.js +description: | +

Removes all elements created by p5.js, including any event handlers. + There are two exceptions: + canvas elements created by createCanvas + and p5.Render objects created by + createGraphics.

+line: 240 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + + // Create a paragraph element and place + // it in the middle of the canvas. + let p = createP('p5*js'); + p.position(25, 25); + + describe('A gray square with the text "p5*js" written in its center. The text disappears when the mouse is pressed.'); + } + + function mousePressed() { + removeElements(); + } + +
+ +
+ + let slider; + + function setup() { + createCanvas(100, 100); + + // Create a paragraph element and place + // it at the top of the canvas. + let p = createP('p5*js'); + p.position(25, 25); + + // Create a slider element and place it + // beneath the canvas. + slider = createSlider(0, 255, 200); + slider.position(0, 100); + + describe('A gray square with the text "p5*js" written in its center and a range slider beneath it. The square changes color when the slider is moved. The text and slider disappear when the square is double-clicked.'); + } + + function draw() { + // Use the slider value to change the background color. + let g = slider.value(); + background(g); + } + + function doubleClicked() { + removeElements(); + } + +
+chainable: false +--- + + +# removeElements diff --git a/src/content/reference/en/p5/removeItem.mdx b/src/content/reference/en/p5/removeItem.mdx new file mode 100644 index 0000000000..410a77f8c4 --- /dev/null +++ b/src/content/reference/en/p5/removeItem.mdx @@ -0,0 +1,33 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: removeItem +module: Data +submodule: LocalStorage +file: src/data/local_storage.js +description: | +

Removes an item that was stored with storeItem()

+line: 201 +params: + - name: key + description: '' + type: String +itemtype: method +class: p5 +example: + - |2- + +
+ + function setup() { + let myVar = 10; + storeItem('myVar', myVar); + print(getItem('myVar')); // logs 10 to the console + removeItem('myVar'); + print(getItem('myVar')); // logs null to the console + } +
+chainable: false +--- + + +# removeItem diff --git a/src/content/reference/en/p5/requestPointerLock.mdx b/src/content/reference/en/p5/requestPointerLock.mdx new file mode 100644 index 0000000000..b015f9d38a --- /dev/null +++ b/src/content/reference/en/p5/requestPointerLock.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: requestPointerLock +module: Events +submodule: Mouse +file: src/events/mouse.js +description: > +

The function requestPointerLock() + + locks the pointer to its current position and makes it invisible. + + Use movedX and movedY to + get the difference the mouse was moved since + + the last call of draw. + + Note that not all browsers support this feature. + + This enables you to create experiences that aren't limited by the mouse moving + out of the screen + + even if it is repeatedly moved into one direction. + + For example, a first person perspective experience.

+line: 960 +itemtype: method +class: p5 +example: + - |- + +
+ + let cam; + function setup() { + createCanvas(100, 100, WEBGL); + requestPointerLock(); + cam = createCamera(); + } + + function draw() { + background(255); + cam.pan(-movedX * 0.001); + cam.tilt(movedY * 0.001); + sphere(25); + describe(`3D scene moves according to mouse mouse movement in a + first person perspective`); + } + +
+chainable: false +--- + + +# requestPointerLock diff --git a/src/content/reference/en/p5/resetMatrix.mdx b/src/content/reference/en/p5/resetMatrix.mdx new file mode 100644 index 0000000000..023f873f6b --- /dev/null +++ b/src/content/reference/en/p5/resetMatrix.mdx @@ -0,0 +1,30 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resetMatrix +module: Transform +submodule: Transform +file: src/core/transform.js +description: | +

Replaces the current matrix with the identity matrix.

+line: 197 +itemtype: method +class: p5 +example: + - |- + +
+ + translate(50, 50); + applyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0); + rect(0, 0, 20, 20); + // Note that the translate is also reset. + resetMatrix(); + rect(0, 0, 20, 20); + +
+alt: A rotated rectangle in the center with another at the top left corner +chainable: true +--- + + +# resetMatrix diff --git a/src/content/reference/en/p5/resetShader.mdx b/src/content/reference/en/p5/resetShader.mdx new file mode 100644 index 0000000000..5deec6fa7b --- /dev/null +++ b/src/content/reference/en/p5/resetShader.mdx @@ -0,0 +1,98 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resetShader +module: 3D +submodule: Material +file: src/webgl/material.js +description: | +

Restores the default shaders. Code that runs after resetShader() + will not be affected by the shader previously set by + shader()

+line: 440 +itemtype: method +class: p5 +example: + - |- + +
+ + // This variable will hold our shader object + let shaderProgram; + + // This variable will hold our vertex shader source code + let vertSrc = ` + attribute vec3 aPosition; + attribute vec2 aTexCoord; + uniform mat4 uProjectionMatrix; + uniform mat4 uModelViewMatrix; + varying vec2 vTexCoord; + + void main() { + vTexCoord = aTexCoord; + vec4 position = vec4(aPosition, 1.0); + gl_Position = uProjectionMatrix * uModelViewMatrix * position; + } + `; + + // This variable will hold our fragment shader source code + let fragSrc = ` + precision mediump float; + + varying vec2 vTexCoord; + + void main() { + vec2 uv = vTexCoord; + vec3 color = vec3(uv.x, uv.y, min(uv.x + uv.y, 1.0)); + gl_FragColor = vec4(color, 1.0); + } + `; + + function setup() { + // Shaders require WEBGL mode to work + createCanvas(100, 100, WEBGL); + + // Create our shader + shaderProgram = createShader(vertSrc, fragSrc); + + describe( + 'Two rotating cubes. The left one is painted using a custom (user-defined) shader, while the right one is painted using the default fill shader.' + ); + } + + function draw() { + // Clear the scene + background(200); + + // Draw a box using our shader + // shader() sets the active shader with our shader + shader(shaderProgram); + push(); + translate(-width / 4, 0, 0); + rotateX(millis() * 0.00025); + rotateY(millis() * 0.0005); + box(width / 4); + pop(); + + // Draw a box using the default fill shader + // resetShader() restores the default fill shader + resetShader(); + fill(255, 0, 0); + push(); + translate(width / 4, 0, 0); + rotateX(millis() * 0.00025); + rotateY(millis() * 0.0005); + box(width / 4); + pop(); + } + +
+alt: >- + Two rotating cubes. The left one is painted using a custom (user-defined) + shader, + + while the right one is painted using the default fill shader. +chainable: true +--- + + +# resetShader diff --git a/src/content/reference/en/p5/resizeCanvas.mdx b/src/content/reference/en/p5/resizeCanvas.mdx new file mode 100644 index 0000000000..d7dee94813 --- /dev/null +++ b/src/content/reference/en/p5/resizeCanvas.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: resizeCanvas +module: Rendering +submodule: Rendering +file: src/core/rendering.js +description: | +

Resizes the canvas to given width and height. The canvas will be cleared + and draw will be called immediately, allowing the sketch to re-render itself + in the resized canvas.

+line: 162 +params: + - name: w + description: | +

width of the canvas

+ type: Number + - name: h + description: | +

height of the canvas

+ type: Number + - name: noRedraw + description: | +

don't redraw the canvas immediately

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + createCanvas(windowWidth, windowHeight); + } + + function draw() { + background(0, 100, 200); + } + + function windowResized() { + resizeCanvas(windowWidth, windowHeight); + } +
+alt: No image displayed. +chainable: false +--- + + +# resizeCanvas diff --git a/src/content/reference/en/p5/reverse.mdx b/src/content/reference/en/p5/reverse.mdx new file mode 100644 index 0000000000..504bb02efc --- /dev/null +++ b/src/content/reference/en/p5/reverse.mdx @@ -0,0 +1,36 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: reverse +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Reverses the order of an array, maps to Array.reverse()

+line: 141 +params: + - name: list + description: | +

Array to reverse

+ type: Array +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let myArray = ['A', 'B', 'C']; + print(myArray); // ['A','B','C'] + + reverse(myArray); + print(myArray); // ['C','B','A'] + } +
+return: + description: the reversed list + type: Array +chainable: false +--- + + +# reverse diff --git a/src/content/reference/en/p5/rotate.mdx b/src/content/reference/en/p5/rotate.mdx new file mode 100644 index 0000000000..ecff92e35f --- /dev/null +++ b/src/content/reference/en/p5/rotate.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotate +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Rotates a shape by the amount specified by the angle parameter. This + + function accounts for angleMode, so angles + + can be entered in either RADIANS or DEGREES.

+ +

Objects are always rotated around their relative position to the + + origin and positive numbers rotate objects in a clockwise direction. + + Transformations apply to everything that happens after and subsequent + + calls to the function accumulate the effect. For example, calling + + rotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI). + + All transformations are reset when draw() begins + again.

+ +

Technically, rotate() multiplies the current + transformation matrix + + by a rotation matrix. This function can be further controlled by + + push() and pop().

+line: 222 +params: + - name: angle + description: | +

the angle of rotation, specified in radians + or degrees, depending on current angleMode

+ type: Number + - name: axis + description: | +

(in 3d) the axis to rotate around

+ type: 'p5.Vector|Number[]' + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + translate(width / 2, height / 2); + rotate(PI / 3.0); + rect(-26, -26, 52, 52); + +
+alt: white 52×52 rect with black outline at center rotated counter 45 degrees +chainable: true +--- + + +# rotate diff --git a/src/content/reference/en/p5/rotateX.mdx b/src/content/reference/en/p5/rotateX.mdx new file mode 100644 index 0000000000..2c3840ba01 --- /dev/null +++ b/src/content/reference/en/p5/rotateX.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotateX +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Rotates a shape around X axis by the amount specified in angle parameter. + + The angles can be entered in either RADIANS or DEGREES.

+ +

Objects are always rotated around their relative position to the + + origin and positive numbers rotate objects in a clockwise direction. + + All transformations are reset when draw() begins + again.

+line: 261 +params: + - name: angle + description: | +

the angle of rotation, specified in radians + or degrees, depending on current angleMode

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + function draw() { + background(255); + rotateX(millis() / 1000); + box(); + } + +
+alt: 3d box rotating around the x axis. +chainable: true +--- + + +# rotateX diff --git a/src/content/reference/en/p5/rotateY.mdx b/src/content/reference/en/p5/rotateY.mdx new file mode 100644 index 0000000000..df18425b3f --- /dev/null +++ b/src/content/reference/en/p5/rotateY.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotateY +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Rotates a shape around Y axis by the amount specified in angle parameter. + + The angles can be entered in either RADIANS or DEGREES.

+ +

Objects are always rotated around their relative position to the + + origin and positive numbers rotate objects in a clockwise direction. + + All transformations are reset when draw() begins + again.

+line: 299 +params: + - name: angle + description: | +

the angle of rotation, specified in radians + or degrees, depending on current angleMode

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + function draw() { + background(255); + rotateY(millis() / 1000); + box(); + } + +
+alt: 3d box rotating around the y axis. +chainable: true +--- + + +# rotateY diff --git a/src/content/reference/en/p5/rotateZ.mdx b/src/content/reference/en/p5/rotateZ.mdx new file mode 100644 index 0000000000..af3a8b5e3c --- /dev/null +++ b/src/content/reference/en/p5/rotateZ.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotateZ +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Rotates a shape around Z axis by the amount specified in angle parameter. + + The angles can be entered in either RADIANS or DEGREES.

+ +

This method works in WEBGL mode only.

+ +

Objects are always rotated around their relative position to the + + origin and positive numbers rotate objects in a clockwise direction. + + All transformations are reset when draw() begins + again.

+line: 337 +params: + - name: angle + description: | +

the angle of rotation, specified in radians + or degrees, depending on current angleMode

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + } + function draw() { + background(255); + rotateZ(millis() / 1000); + box(); + } + +
+alt: 3d box rotating around the z axis. +chainable: true +--- + + +# rotateZ diff --git a/src/content/reference/en/p5/rotationX.mdx b/src/content/reference/en/p5/rotationX.mdx new file mode 100644 index 0000000000..342dc5ea97 --- /dev/null +++ b/src/content/reference/en/p5/rotationX.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotationX +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable rotationX always contains the rotation of the + device along the x axis. If the sketch + angleMode() is set to DEGREES, the value will be -180 to 180. If + it is set to RADIANS, the value will be -PI to PI.

+

Note: The order the rotations are called is important, ie. if used + together, it must be called in the order Z-X-Y or there might be + unexpected behaviour.

+line: 131 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(200); + //rotateZ(radians(rotationZ)); + rotateX(radians(rotationX)); + //rotateY(radians(rotationY)); + box(200, 200, 200); + describe(`red horizontal line right, green vertical line bottom. + black background.`); + } + +
+chainable: false +--- + + +# rotationX diff --git a/src/content/reference/en/p5/rotationY.mdx b/src/content/reference/en/p5/rotationY.mdx new file mode 100644 index 0000000000..17d65bc370 --- /dev/null +++ b/src/content/reference/en/p5/rotationY.mdx @@ -0,0 +1,42 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotationY +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable rotationY always contains the rotation of the + device along the y axis. If the sketch + angleMode() is set to DEGREES, the value will be -90 to 90. If + it is set to RADIANS, the value will be -PI/2 to PI/2.

+

Note: The order the rotations are called is important, ie. if used + together, it must be called in the order Z-X-Y or there might be + unexpected behaviour.

+line: 164 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(200); + //rotateZ(radians(rotationZ)); + //rotateX(radians(rotationX)); + rotateY(radians(rotationY)); + box(200, 200, 200); + describe(`red horizontal line right, green vertical line bottom. + black background.`); + } + +
+chainable: false +--- + + +# rotationY diff --git a/src/content/reference/en/p5/rotationZ.mdx b/src/content/reference/en/p5/rotationZ.mdx new file mode 100644 index 0000000000..c99ce6ad63 --- /dev/null +++ b/src/content/reference/en/p5/rotationZ.mdx @@ -0,0 +1,44 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: rotationZ +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: | +

The system variable rotationZ always contains the rotation of the + device along the z axis. If the sketch + angleMode() is set to DEGREES, the value will be 0 to 360. If + it is set to RADIANS, the value will be 0 to 2*PI.

+

Unlike rotationX and rotationY, this variable is available for devices + with a built-in compass only.

+

Note: The order the rotations are called is important, ie. if used + together, it must be called in the order Z-X-Y or there might be + unexpected behaviour.

+line: 197 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(200); + rotateZ(radians(rotationZ)); + //rotateX(radians(rotationX)); + //rotateY(radians(rotationY)); + box(200, 200, 200); + describe(`red horizontal line right, green vertical line bottom. + black background.`); + } + +
+chainable: false +--- + + +# rotationZ diff --git a/src/content/reference/en/p5/sampleRate.mdx b/src/content/reference/en/p5/sampleRate.mdx new file mode 100644 index 0000000000..17c3490619 --- /dev/null +++ b/src/content/reference/en/p5/sampleRate.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sampleRate +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Returns a number representing the sample rate, in samples per second, + of all sound objects in this audio context. It is determined by the + sampling rate of your operating system's sound card, and it is not + currently possile to change. + It is often 44100, or twice the range of human hearing.

+line: 811 +itemtype: method +class: p5 +return: + description: samplerate samples per second + type: Number +chainable: false +--- + + +# sampleRate diff --git a/src/content/reference/en/p5/saturation.mdx b/src/content/reference/en/p5/saturation.mdx new file mode 100644 index 0000000000..950aad7798 --- /dev/null +++ b/src/content/reference/en/p5/saturation.mdx @@ -0,0 +1,49 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saturation +module: Color +submodule: Creating & Reading +file: src/color/creating_reading.js +description: | +

Extracts the saturation value from a + p5.Color object, array of color components, or + CSS color string.

+

Saturation is scaled differently in HSB and HSL. By default, this function + returns the HSL saturation. If the colorMode() + is set to HSB, it returns the HSB saturation.

+line: 535 +params: + - name: color + description: | +

p5.Color object, array of + color components, or CSS color string.

+ type: 'p5.Color|Number[]|String' +itemtype: method +class: p5 +example: + - |- + +
+ + noStroke(); + colorMode(HSB, 255); + const c = color(0, 126, 255); + fill(c); + rect(15, 20, 35, 60); + // Sets 'satValue' to 126. + const satValue = saturation(c); + fill(satValue); + rect(50, 20, 35, 60); + describe( + 'Two rectangles. The rectangle on the left is deep pink and the one on the right is gray.' + ); + +
+return: + description: the saturation value + type: Number +chainable: false +--- + + +# saturation diff --git a/src/content/reference/en/p5/save.mdx b/src/content/reference/en/p5/save.mdx new file mode 100644 index 0000000000..3f22294ff6 --- /dev/null +++ b/src/content/reference/en/p5/save.mdx @@ -0,0 +1,121 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: save +module: IO +submodule: Output +file: src/io/files.js +description: | +

Saves a given element(image, text, json, csv, wav, or html) to the client's + computer. The first parameter can be a pointer to element we want to save. + The element can be one of p5.Element,an Array of + Strings, an Array of JSON, a JSON object, a p5.Table + , a p5.Image, or a p5.SoundFile (requires + p5.sound). The second parameter is a filename (including extension).The + third parameter is for options specific to this type of object. This method + will save a file that fits the given parameters. + If it is called without specifying an element, by default it will save the + whole canvas as an image file. You can optionally specify a filename as + the first parameter in such a case. + Note that it is not recommended to + call this method within draw, as it will open a new save dialog on every + render.

+line: 1381 +params: + - name: objectOrFilename + description: | +

If filename is provided, will + save canvas as an image with + either png or jpg extension + depending on the filename. + If object is provided, will + save depending on the object + and filename (see examples + above).

+ type: Object|String + optional: true + - name: filename + description: | +

If an object is provided as the first + parameter, then the second parameter + indicates the filename, + and should include an appropriate + file extension (see examples above).

+ type: String + optional: true + - name: options + description: | +

Additional options depend on + filetype. For example, when saving JSON, + true indicates that the + output will be optimized for filesize, + rather than readability.

+ type: Boolean|String + optional: true +itemtype: method +class: p5 +example: + - |2- + +
+ // Saves the canvas as an image + cnv = createCanvas(300, 300); + save(cnv, 'myCanvas.jpg'); + + // Saves the canvas as an image by default + save('myCanvas.jpg'); + describe('An example for saving a canvas as an image.'); +
+ +
+ // Saves p5.Image as an image + img = createImage(10, 10); + save(img, 'myImage.png'); + describe('An example for saving a p5.Image element as an image.'); +
+ +
+ // Saves p5.Renderer object as an image + obj = createGraphics(100, 100); + save(obj, 'myObject.png'); + describe('An example for saving a p5.Renderer element.'); +
+ +
+ let myTable = new p5.Table(); + // Saves table as html file + save(myTable, 'myTable.html'); + + // Comma Separated Values + save(myTable, 'myTable.csv'); + + // Tab Separated Values + save(myTable, 'myTable.tsv'); + + describe(`An example showing how to save a table in formats of + HTML, CSV and TSV.`); +
+ +
+ let myJSON = { a: 1, b: true }; + + // Saves pretty JSON + save(myJSON, 'my.json'); + + // Optimizes JSON filesize + save(myJSON, 'my.json', true); + + describe('An example for saving JSON to a txt file with some extra arguments.'); +
+ +
+ // Saves array of strings to text file with line breaks after each item + let arrayOfStrings = ['a', 'b']; + save(arrayOfStrings, 'my.txt'); + describe(`An example for saving an array of strings to text file + with line breaks.`); +
+chainable: false +--- + + +# save diff --git a/src/content/reference/en/p5/saveCanvas.mdx b/src/content/reference/en/p5/saveCanvas.mdx new file mode 100644 index 0000000000..603c6a6655 --- /dev/null +++ b/src/content/reference/en/p5/saveCanvas.mdx @@ -0,0 +1,79 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveCanvas +module: Image +submodule: Image +file: src/image/image.js +description: | +

Saves the current canvas as an image. The browser will either save the + file immediately or prompt the user with a dialogue window.

+line: 97 +itemtype: method +class: p5 +example: + - |2- + +
+ + function setup() { + createCanvas(100, 100); + background(255); + saveCanvas(); + } + +
+ +
+ + function setup() { + createCanvas(100, 100); + background(255); + saveCanvas('myCanvas.jpg'); + } + +
+ +
+ + function setup() { + createCanvas(100, 100); + background(255); + saveCanvas('myCanvas', 'jpg'); + } + +
+ +
+ + function setup() { + let cnv = createCanvas(100, 100); + background(255); + saveCanvas(cnv); + } + +
+ +
+ + function setup() { + let cnv = createCanvas(100, 100); + background(255); + saveCanvas(cnv, 'myCanvas.jpg'); + } + +
+ +
+ + function setup() { + let cnv = createCanvas(100, 100); + background(255); + saveCanvas(cnv, 'myCanvas', 'jpg'); + } + +
+chainable: false +--- + + +# saveCanvas diff --git a/src/content/reference/en/p5/saveFrames.mdx b/src/content/reference/en/p5/saveFrames.mdx new file mode 100644 index 0000000000..5f5cb77467 --- /dev/null +++ b/src/content/reference/en/p5/saveFrames.mdx @@ -0,0 +1,127 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveFrames +module: Image +submodule: Image +file: src/image/image.js +description: > +

Captures a sequence of frames from the canvas that can be used to create a + + movie. Frames are downloaded as individual image files by default.

+ +

The first parameter, filename, sets the prefix for the file + names. For + + example, setting the prefix to 'frame' would generate the image + files + + frame0.png, frame1.png, and so on. The second + parameter, extension, + + sets the file type to either 'png' or 'jpg'.

+ +

The third parameter, duration, sets the duration to record in + seconds. + + The maximum duration is 15 seconds. The fourth parameter, + framerate, sets + + the number of frames to record per second. The maximum frame rate value is + + 22. Limits are placed on duration and framerate to + avoid using too much + + memory. Recording large canvases can easily crash sketches or even web + + browsers.

+ +

The fifth parameter, callback, is optional. If a function is + passed, + + image files won't be saved by default. The callback function can be used + + to process an array containing the data for each captured frame. The array + + of image data contains a sequence of objects with three properties for each + + frame: imageData, filename, and + extension.

+line: 460 +params: + - name: filename + description: | +

prefix of file name.

+ type: String + - name: extension + description: | +

file extension, either 'jpg' or 'png'.

+ type: String + - name: duration + description: > +

duration in seconds to record. This parameter will be constrained to be + less or equal to 15.

+ type: Number + - name: framerate + description: > +

number of frames to save per second. This parameter will be constrained + to be less or equal to 22.

+ type: Number + - name: callback + description: | +

callback function that will be executed + to handle the image data. This function + should accept an array as argument. The + array will contain the specified number of + frames of objects. Each object has three + properties: imageData, filename, and extension.

+ type: Function(Array) + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + let r = frameCount % 255; + let g = 50; + let b = 100; + background(r, g, b); + + describe('A square repeatedly changes color from blue to pink.'); + } + + function keyPressed() { + if (key === 's') { + saveFrames('frame', 'png', 1, 5); + } + } + +
+ +
+ + function draw() { + let r = frameCount % 255; + let g = 50; + let b = 100; + background(r, g, b); + + describe('A square repeatedly changes color from blue to pink.'); + } + + function mousePressed() { + saveFrames('frame', 'png', 1, 5, data => { + // Prints an array of objects containing raw image data, + // filenames, and extensions. + print(data); + }); + } + +
+chainable: false +--- + + +# saveFrames diff --git a/src/content/reference/en/p5/saveGif.mdx b/src/content/reference/en/p5/saveGif.mdx new file mode 100644 index 0000000000..7a486e6a6e --- /dev/null +++ b/src/content/reference/en/p5/saveGif.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveGif +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: > +

Generates a gif from a sketch and saves it to a file. + saveGif() may be + + called in setup() or at any point while a sketch + + is running.

+ +

The first parameter, fileName, sets the gif's file name. The + second + + parameter, duration, sets the gif's duration in seconds.

+ +

The third parameter, options, is optional. If an object is + passed, + + saveGif() will use its properties to customize the gif. + saveGif() + + recognizes the properties delay, units, + silent, + + notificationDuration, and notificationID.

+line: 188 +params: + - name: filename + description: | +

file name of gif.

+ type: String + - name: duration + description: | +

duration in seconds to capture from the sketch.

+ type: Number + - name: options + description: | +

an object that can contain five more properties: + delay, a Number specifying how much time to wait before recording; + units, a String that can be either 'seconds' or 'frames'. By default it's 'seconds’; + silent, a Boolean that defines presence of progress notifications. By default it’s false; + notificationDuration, a Number that defines how long in seconds the final notification + will live. By default it's 0, meaning the notification will never be removed; + notificationID, a String that specifies the id of the notification's DOM element. By default it’s 'progressBar’.

+ type: Object + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + let c = frameCount % 255; + fill(c); + circle(50, 50, 25); + + describe('A circle drawn in the middle of a gray square. The circle changes color from black to white, then repeats.'); + } + + function keyPressed() { + if (key === 's') { + saveGif('mySketch', 5); + } + } + +
+chainable: false +--- + + +# saveGif diff --git a/src/content/reference/en/p5/saveJSON.mdx b/src/content/reference/en/p5/saveJSON.mdx new file mode 100644 index 0000000000..4d26337c46 --- /dev/null +++ b/src/content/reference/en/p5/saveJSON.mdx @@ -0,0 +1,63 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveJSON +module: IO +submodule: Output +file: src/io/files.js +description: | +

Writes the contents of an Array or a JSON object to a .json file. + The file saving process and location of the saved file will + vary between web browsers.

+line: 1525 +params: + - name: json + description: '' + type: Array|Object + - name: filename + description: '' + type: String + - name: optimize + description: | +

If true, removes line breaks + and spaces from the output + file to optimize filesize + (but not readability).

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |2- + +
+ let json = {}; // new JSON Object + + json.id = 0; + json.species = 'Panthera leo'; + json.name = 'Lion'; + + function setup() { + createCanvas(100, 100); + background(200); + text('click here to save', 10, 10, 70, 80); + describe('no image displayed'); + } + + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + saveJSON(json, 'lion.json'); + } + } + + // saves the following to a file called "lion.json": + // { + // "id": 0, + // "species": "Panthera leo", + // "name": "Lion" + // } +
+chainable: false +--- + + +# saveJSON diff --git a/src/content/reference/en/p5/saveSound.mdx b/src/content/reference/en/p5/saveSound.mdx new file mode 100644 index 0000000000..0f11877f05 --- /dev/null +++ b/src/content/reference/en/p5/saveSound.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveSound +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

Save a p5.SoundFile as a .wav file. The browser will prompt the user + + to download the file to their device. + + For uploading audio to a server, use + + p5.SoundFile.saveBlob.

+line: 1145 +params: + - name: soundFile + description: | +

p5.SoundFile that you wish to save

+ type: p5.SoundFile + - name: fileName + description: | +

name of the resulting .wav file.

+ type: String +itemtype: method +class: p5 +chainable: false +--- + + +# saveSound diff --git a/src/content/reference/en/p5/saveStrings.mdx b/src/content/reference/en/p5/saveStrings.mdx new file mode 100644 index 0000000000..9ebb1b1811 --- /dev/null +++ b/src/content/reference/en/p5/saveStrings.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveStrings +module: IO +submodule: Output +file: src/io/files.js +description: | +

Writes an array of Strings to a text file, one line per String. + The file saving process and location of the saved file will + vary between web browsers.

+line: 1580 +params: + - name: list + description: | +

string array to be written

+ type: 'String[]' + - name: filename + description: | +

filename for output

+ type: String + - name: extension + description: | +

the filename's extension

+ type: String + optional: true + - name: isCRLF + description: | +

if true, change line-break to CRLF

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |2- + +
+ let words = 'apple bear cat dog'; + + // .split() outputs an Array + let list = split(words, ' '); + + function setup() { + createCanvas(100, 100); + background(200); + text('click here to save', 10, 10, 70, 80); + describe('no image displayed'); + } + + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + saveStrings(list, 'nouns.txt'); + } + } + + // Saves the following to a file called 'nouns.txt': + // + // apple + // bear + // cat + // dog +
+chainable: false +--- + + +# saveStrings diff --git a/src/content/reference/en/p5/saveTable.mdx b/src/content/reference/en/p5/saveTable.mdx new file mode 100644 index 0000000000..c9f0ccd221 --- /dev/null +++ b/src/content/reference/en/p5/saveTable.mdx @@ -0,0 +1,67 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: saveTable +module: IO +submodule: Output +file: src/io/files.js +description: > +

Writes the contents of a Table object to a file. + Defaults to a + + text file with comma-separated-values ('csv') but can also + + use tab separation ('tsv'), or generate an HTML table ('html'). + + The file saving process and location of the saved file will + + vary between web browsers.

+line: 1642 +params: + - name: Table + description: | +

the Table object to save to a file

+ type: p5.Table + - name: filename + description: | +

the filename to which the Table should be saved

+ type: String + - name: options + description: | +

can be one of "tsv", "csv", or "html"

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ let table; + + function setup() { + table = new p5.Table(); + + table.addColumn('id'); + table.addColumn('species'); + table.addColumn('name'); + + let newRow = table.addRow(); + newRow.setNum('id', table.getRowCount() - 1); + newRow.setString('species', 'Panthera leo'); + newRow.setString('name', 'Lion'); + + // To save, un-comment next line then click 'run' + // saveTable(table, 'new.csv'); + + describe('no image displayed'); + } + + // Saves the following to a file called 'new.csv': + // id,species,name + // 0,Panthera leo,Lion +
+chainable: false +--- + + +# saveTable diff --git a/src/content/reference/en/p5/scale.mdx b/src/content/reference/en/p5/scale.mdx new file mode 100644 index 0000000000..a5a3ee9df0 --- /dev/null +++ b/src/content/reference/en/p5/scale.mdx @@ -0,0 +1,60 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: scale +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Increases or decreases the size of a shape by expanding or contracting + + vertices. Objects always scale from their relative origin to the + + coordinate system. Scale values are specified as decimal percentages. + + For example, the function call scale(2.0) increases the dimension of a + + shape by 200%.

+ +

Transformations apply to everything that happens after and subsequent + + calls to the function multiply the effect. For example, calling scale(2.0) + + and then scale(1.5) is the same as scale(3.0). If scale() is called + + within draw(), the transformation is reset when the + loop begins again.

+ +

Using this function with the z parameter is only available in WEBGL mode. + + This function can be further controlled with push() + and pop().

+line: 377 +itemtype: method +class: p5 +example: + - |- + +
+ + rect(30, 20, 50, 50); + scale(0.5); + rect(30, 20, 50, 50); + +
+ +
+ + rect(30, 20, 50, 50); + scale(0.5, 1.3); + rect(30, 20, 50, 50); + +
+alt: |- + white 52×52 rect with black outline at center rotated counter 45 degrees + 2 white rects with black outline- 1 50×50 at center. other 25×65 bottom left +chainable: true +--- + + +# scale diff --git a/src/content/reference/en/p5/second.mdx b/src/content/reference/en/p5/second.mdx new file mode 100644 index 0000000000..4d73110ab0 --- /dev/null +++ b/src/content/reference/en/p5/second.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: second +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The second() function + + returns the current second as a value from 0 - 59.

+line: 112 +itemtype: method +class: p5 +example: + - |- + +
+ + let s = second(); + text('Current second: \n' + s, 5, 50); + describe('Current second is displayed'); + +
+return: + description: the current second + type: Integer +chainable: false +--- + + +# second diff --git a/src/content/reference/en/p5/select.mdx b/src/content/reference/en/p5/select.mdx new file mode 100644 index 0000000000..d830a01fe3 --- /dev/null +++ b/src/content/reference/en/p5/select.mdx @@ -0,0 +1,106 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: select +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Searches the page for the first element that matches the given + + CSS selector string. + + The string can be an ID, class, tag name, or a combination. + select() + + returns a p5.Element object if it finds a match + + and null otherwise.

+ +

The second parameter, container, is optional. It specifies a + container to + + search within. container can be CSS selector string, a + + p5.Element object, or an + + HTMLElement object.

+line: 21 +params: + - name: selectors + description: | +

CSS selector string of element to search for.

+ type: String + - name: container + description: | +

CSS selector string, p5.Element, or + HTMLElement to search within.

+ type: String|p5.Element|HTMLElement + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100); + background(200); + + // Select the canvas by its tag. + let cnv = select('canvas'); + cnv.style('border', '5px deeppink dashed'); + + describe('A gray square with a dashed pink border.'); + } + +
+ +
+ + function setup() { + let cnv = createCanvas(100, 100); + // Add a class attribute to the canvas. + cnv.class('pinkborder'); + + background(200); + + // Select the canvas by its class. + cnv = select('.pinkborder'); + // Style its border. + cnv.style('border', '5px deeppink dashed'); + + describe('A gray square with a dashed pink border.'); + } + +
+ +
+ + function setup() { + let cnv = createCanvas(100, 100); + // Set the canvas ID. + cnv.id('mycanvas'); + + background(200); + + // Select the canvas by its ID. + cnv = select('#mycanvas'); + // Style its border. + cnv.style('border', '5px deeppink dashed'); + + describe('A gray square with a dashed pink border.'); + } + +
+return: + description: p5.Element containing the element. + type: p5.Element|null +chainable: false +--- + + +# select diff --git a/src/content/reference/en/p5/selectAll.mdx b/src/content/reference/en/p5/selectAll.mdx new file mode 100644 index 0000000000..4c483f5cc4 --- /dev/null +++ b/src/content/reference/en/p5/selectAll.mdx @@ -0,0 +1,111 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: selectAll +module: DOM +submodule: DOM +file: src/dom/dom.js +description: > +

Searches the page for all elements that matches the given + + CSS selector string. + + The string can be an ID, class, tag name, or a combination. + selectAll() + + returns an array of p5.Element objects if it + + finds any matches and an empty array otherwise.

+ +

The second parameter, container, is optional. It specifies a + container to + + search within. container can be CSS selector string, a + + p5.Element object, or an + + HTMLElement object.

+line: 103 +params: + - name: selectors + description: | +

CSS selector string of element to search for.

+ type: String + - name: container + description: | +

CSS selector string, p5.Element, or + HTMLElement to search within.

+ type: String|p5.Element|HTMLElement + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Create three buttons. + createButton('1'); + createButton('2'); + createButton('3'); + + // Select the buttons by their tag. + let buttons = selectAll('button'); + + // Position the buttons. + for (let i = 0; i < 3; i += 1) { + buttons[i].position(0, i * 30); + } + + describe('Three buttons stacked vertically. The buttons are labeled, "1", "2", and "3".'); + } + +
+ +
+ + function setup() { + // Create three buttons and position them. + let b1 = createButton('1'); + b1.position(0, 0); + let b2 = createButton('2'); + b2.position(0, 30); + let b3 = createButton('3'); + b3.position(0, 60); + + // Add a class attribute to each button. + b1.class('btn'); + b2.class('btn btn-pink'); + b3.class('btn'); + + // Select the buttons by their class. + let buttons = selectAll('.btn'); + let pinkButtons = selectAll('.btn-pink'); + + // Style the selected buttons. + buttons.forEach(btn => { + btn.style('font-family', 'Comic Sans MS'); + }); + + pinkButtons.forEach(btn => { + btn.style('background', 'deeppink'); + btn.style('color', 'white'); + }); + + describe('Three buttons stacked vertically. The buttons are labeled, "1", "2", and "3". Buttons "1" and "3" are gray. Button "2" is pink.'); + } + +
+return: + description: >- + array of p5.Elements containing any elements + found. + type: 'p5.Element[]' +chainable: false +--- + + +# selectAll diff --git a/src/content/reference/en/p5/set.mdx b/src/content/reference/en/p5/set.mdx new file mode 100644 index 0000000000..5622e48922 --- /dev/null +++ b/src/content/reference/en/p5/set.mdx @@ -0,0 +1,148 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: set +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Sets the color of a pixel or draws an image to the canvas.

+ +

set() is easy to use but it's not as fast as + + pixels. Use pixels + + to set many pixel values.

+ +

set() interprets the first two parameters as x- and + y-coordinates. It + + interprets the last parameter as a grayscale value, a [R, G, B, + A] pixel + + array, a p5.Color object, or a + + p5.Image object. If an image is passed, the first + + two parameters set the coordinates for the image's upper-left corner, + + regardless of the current imageMode().

+ +

updatePixels() must be called after using + + set() for changes to appear.

+line: 801 +params: + - name: x + description: | +

x-coordinate of the pixel.

+ type: Number + - name: 'y' + description: | +

y-coordinate of the pixel.

+ type: Number + - name: c + description: | +

grayscale value | pixel array | + p5.Color object | p5.Image to copy.

+ type: 'Number|Number[]|Object' +itemtype: method +class: p5 +example: + - >- + +
+ + + + set(30, 20, 0); + + set(85, 20, 0); + + set(85, 75, 0); + + set(30, 75, 0); + + updatePixels(); + + + describe('Four black dots arranged in a square drawn on a gray + background.'); + + + +
+ + +
+ + + + let black = color(0); + + set(30, 20, black); + + set(85, 20, black); + + set(85, 75, black); + + set(30, 75, black); + + updatePixels(); + + + describe('Four black dots arranged in a square drawn on a gray + background.'); + + + +
+ + +
+ + + + for (let x = 0; x < width; x += 1) { + for (let y = 0; y < height; y += 1) { + let c = map(x, 0, width, 0, 255); + set(x, y, c); + } + } + + updatePixels(); + + + describe('A horiztonal color gradient from black to white.'); + + + +
+ + +
+ + + + let img; + + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + + function setup() { + set(0, 0, img); + updatePixels(); + + describe('An image of a mountain landscape.'); + } + + + +
+chainable: false +--- + + +# set diff --git a/src/content/reference/en/p5/setAttributes.mdx b/src/content/reference/en/p5/setAttributes.mdx new file mode 100644 index 0000000000..10ceb406f0 --- /dev/null +++ b/src/content/reference/en/p5/setAttributes.mdx @@ -0,0 +1,143 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setAttributes +module: Rendering +submodule: Rendering +file: src/webgl/p5.RendererGL.js +description: | +

Set attributes for the WebGL Drawing context. + This is a way of adjusting how the WebGL + renderer works to fine-tune the display and performance.

+

Note that this will reinitialize the drawing context + if called after the WebGL canvas is made.

+

If an object is passed as the parameter, all attributes + not declared in the object will be set to defaults.

+

The available attributes are: +
+ alpha - indicates if the canvas contains an alpha buffer + default is true

+

depth - indicates whether the drawing buffer has a depth buffer + of at least 16 bits - default is true

+

stencil - indicates whether the drawing buffer has a stencil buffer + of at least 8 bits

+

antialias - indicates whether or not to perform anti-aliasing + default is false (true in Safari)

+

premultipliedAlpha - indicates that the page compositor will assume + the drawing buffer contains colors with pre-multiplied alpha + default is true

+

preserveDrawingBuffer - if true the buffers will not be cleared and + and will preserve their values until cleared or overwritten by author + (note that p5 clears automatically on draw loop) + default is true

+

perPixelLighting - if true, per-pixel lighting will be used in the + lighting shader otherwise per-vertex lighting is used. + default is true.

+

version - either 1 or 2, to specify which WebGL version to ask for. By + default, WebGL 2 will be requested. If WebGL2 is not available, it will + fall back to WebGL 1. You can check what version is used with by looking at + the global webglVersion property.

+line: 112 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(255); + push(); + rotateZ(frameCount * 0.02); + rotateX(frameCount * 0.02); + rotateY(frameCount * 0.02); + fill(0, 0, 0); + box(50); + pop(); + } + +
+
+ Now with the antialias attribute set to true. +
+
+ + function setup() { + setAttributes('antialias', true); + createCanvas(100, 100, WEBGL); + } + + function draw() { + background(255); + push(); + rotateZ(frameCount * 0.02); + rotateX(frameCount * 0.02); + rotateY(frameCount * 0.02); + fill(0, 0, 0); + box(50); + pop(); + } + +
+ +
+ + // press the mouse button to disable perPixelLighting + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + fill(255); + } + + let lights = [ + { c: '#f00', t: 1.12, p: 1.91, r: 0.2 }, + { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 }, + { c: '#00f', t: 1.37, p: 1.57, r: 0.2 }, + { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 }, + { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 }, + { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 } + ]; + + function draw() { + let t = millis() / 1000 + 1000; + background(0); + directionalLight(color('#222'), 1, 1, 1); + + for (let i = 0; i < lights.length; i++) { + let light = lights[i]; + pointLight( + color(light.c), + p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r) + ); + } + + specularMaterial(255); + sphere(width * 0.1); + + rotateX(t * 0.77); + rotateY(t * 0.83); + rotateZ(t * 0.91); + torus(width * 0.3, width * 0.07, 24, 10); + } + + function mousePressed() { + setAttributes('perPixelLighting', false); + noStroke(); + fill(255); + } + function mouseReleased() { + setAttributes('perPixelLighting', true); + noStroke(); + fill(255); + } + +
+alt: a rotating cube with smoother edges +chainable: false +--- + + +# setAttributes diff --git a/src/content/reference/en/p5/setBPM.mdx b/src/content/reference/en/p5/setBPM.mdx new file mode 100644 index 0000000000..1412b36ef3 --- /dev/null +++ b/src/content/reference/en/p5/setBPM.mdx @@ -0,0 +1,26 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setBPM +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

Set the global tempo, in beats per minute, for all + p5.Parts. This method will impact all active p5.Parts.

+line: 9084 +params: + - name: BPM + description: | +

Beats Per Minute

+ type: Number + - name: rampTime + description: | +

Seconds from now

+ type: Number +itemtype: method +class: p5 +chainable: false +--- + + +# setBPM diff --git a/src/content/reference/en/p5/setCamera.mdx b/src/content/reference/en/p5/setCamera.mdx new file mode 100644 index 0000000000..323e31b46e --- /dev/null +++ b/src/content/reference/en/p5/setCamera.mdx @@ -0,0 +1,93 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setCamera +module: 3D +submodule: Camera +file: src/webgl/p5.Camera.js +description: | +

Sets the current (active) camera of a 3D sketch. + Allows for switching between multiple cameras.

+line: 2222 +params: + - name: cam + description: | +

p5.Camera object

+ type: p5.Camera +itemtype: method +class: p5 +example: + - |- + +
+ + let cam1, cam2; + let currentCamera; + + function setup() { + createCanvas(100, 100, WEBGL); + normalMaterial(); + + cam1 = createCamera(); + cam1.camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + cam1.perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + cam2 = createCamera(); + cam2.setPosition(30, 0, 50); + cam2.lookAt(0, 0, 0); + cam2.ortho(-50, 50, -50, 50, 0, 200); + + // set variable for previously active camera: + currentCamera = 1; + + describe( + 'Canvas switches between two camera views, each showing a series of spinning 3D boxes.' + ); + } + + function draw() { + background(200); + + // every 100 frames, switch between the two cameras + if (frameCount % 100 === 0) { + if (currentCamera === 1) { + setCamera(cam1); + currentCamera = 0; + } else { + setCamera(cam2); + currentCamera = 1; + } + } + + // camera 1: + cam1.lookAt(0, 0, 0); + cam1.setPosition(sin(frameCount / 60) * 200, 0, 100); + + drawBoxes(); + } + + function drawBoxes() { + rotateX(frameCount * 0.01); + translate(-100, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + translate(35, 0, 0); + box(20); + } + +
+alt: |- + Canvas switches between two camera views, each showing a series of spinning + 3D boxes. +chainable: false +--- + + +# setCamera diff --git a/src/content/reference/en/p5/setMoveThreshold.mdx b/src/content/reference/en/p5/setMoveThreshold.mdx new file mode 100644 index 0000000000..04738dd964 --- /dev/null +++ b/src/content/reference/en/p5/setMoveThreshold.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setMoveThreshold +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The setMoveThreshold() function is used + to set the movement threshold for + + the deviceMoved() function. The default + threshold is set to 0.5.

+line: 417 +params: + - name: value + description: | +

The threshold value

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // You will need to move the device incrementally further + // the closer the square's color gets to white in order to change the value. + + let value = 0; + let threshold = 0.5; + function setup() { + setMoveThreshold(threshold); + } + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device moves`); + } + function deviceMoved() { + value = value + 5; + threshold = threshold + 0.1; + if (value > 255) { + value = 0; + threshold = 30; + } + setMoveThreshold(threshold); + } + +
+chainable: false +--- + + +# setMoveThreshold diff --git a/src/content/reference/en/p5/setShakeThreshold.mdx b/src/content/reference/en/p5/setShakeThreshold.mdx new file mode 100644 index 0000000000..8c15afd499 --- /dev/null +++ b/src/content/reference/en/p5/setShakeThreshold.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setShakeThreshold +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

The setShakeThreshold() function is + used to set the movement threshold for + + the deviceShaken() function. The default + threshold is set to 30.

+line: 459 +params: + - name: value + description: | +

The threshold value

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // You will need to shake the device more firmly + // the closer the box's fill gets to white in order to change the value. + + let value = 0; + let threshold = 30; + function setup() { + setShakeThreshold(threshold); + } + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device is being shaked`); + } + function deviceMoved() { + value = value + 5; + threshold = threshold + 5; + if (value > 255) { + value = 0; + threshold = 30; + } + setShakeThreshold(threshold); + } + +
+chainable: false +--- + + +# setShakeThreshold diff --git a/src/content/reference/en/p5/setup.mdx b/src/content/reference/en/p5/setup.mdx new file mode 100644 index 0000000000..f186b19656 --- /dev/null +++ b/src/content/reference/en/p5/setup.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: setup +module: Structure +submodule: Structure +file: src/core/main.js +description: > +

The setup() function is called once when the + program starts. It's used to + + define initial environment properties such as screen size and background + + color and to load media such as images and fonts as the program starts. + + There can only be one setup() function for each + program and it shouldn't + + be called again after its initial execution.

+ +

Note: Variables declared within setup() are not + accessible within other + + functions, including draw().

+line: 82 +itemtype: method +class: p5 +example: + - |- + +
+ let a = 0; + + function setup() { + background(0); + noStroke(); + fill(102); + } + + function draw() { + rect(a++ % width, 10, 2, 80); + } +
+alt: nothing displayed +chainable: false +--- + + +# setup diff --git a/src/content/reference/en/p5/shader.mdx b/src/content/reference/en/p5/shader.mdx new file mode 100644 index 0000000000..b550cd022d --- /dev/null +++ b/src/content/reference/en/p5/shader.mdx @@ -0,0 +1,134 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shader +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the p5.Shader object to + + be used to render subsequent shapes.

+ +

Shaders can alter the positioning of shapes drawn with them. + + To ensure consistency in rendering, it's recommended to use the vertex shader + in the createShader example.

+ +

Custom shaders can be created using the + + createShader() and + + loadShader() functions.

+ +

Use resetShader() to + + restore the default shaders.

+ +

Additional Information: + + The shader will be used for:

+ + + +

Note, shaders can only be used in WEBGL mode.

+line: 331 +params: + - name: s + description: | +

the p5.Shader object + to use for rendering shapes.

+ type: p5.Shader +itemtype: method +class: p5 +example: + - |- + +
+ + // Click within the image to toggle + // the shader used by the quad shape + // Note: for an alternative approach to the same example, + // involving changing uniforms please refer to: + // https://p5js.org/reference/#/p5.Shader/setUniform + + let redGreen; + let orangeBlue; + let showRedGreen = false; + + function preload() { + // note that we are using two instances + // of the same vertex and fragment shaders + redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + + // initialize the colors for redGreen shader + shader(redGreen); + redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]); + redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]); + + // initialize the colors for orangeBlue shader + shader(orangeBlue); + orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]); + orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]); + + noStroke(); + + describe( + 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.' + ); + } + + function draw() { + // update the offset values for each shader, + // moving orangeBlue in vertical and redGreen + // in horizontal direction + orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]); + redGreen.setUniform('offset', [sin(millis() / 2000), 1]); + + if (showRedGreen === true) { + shader(redGreen); + } else { + shader(orangeBlue); + } + quad(-1, -1, 1, -1, 1, 1, -1, 1); + } + + function mouseClicked() { + showRedGreen = !showRedGreen; + } + +
+alt: >- + canvas toggles between a circular gradient of orange and blue vertically. and + a circular gradient of red and green moving horizontally when mouse is + clicked/pressed. +chainable: true +--- + + +# shader diff --git a/src/content/reference/en/p5/shearX.mdx b/src/content/reference/en/p5/shearX.mdx new file mode 100644 index 0000000000..702923b022 --- /dev/null +++ b/src/content/reference/en/p5/shearX.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shearX +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Shears a shape around the x-axis by the amount specified by the angle + + parameter. Angles should be specified in the current angleMode. + + Objects are always sheared around their relative position to the origin + + and positive numbers shear objects in a clockwise direction.

+ +

Transformations apply to everything that happens after and subsequent + + calls to the function accumulates the effect. For example, calling + + shearX(PI/2) and then shearX(PI/2) is the same as shearX(PI). + + If shearX() is called within the draw(), + + the transformation is reset when the loop begins again.

+ +

Technically, shearX() multiplies the current + + transformation matrix by a rotation matrix. This function can be further + + controlled by the push() and pop() functions.

+line: 451 +params: + - name: angle + description: | +

angle of shear specified in radians or degrees, + depending on current angleMode

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + translate(width / 4, height / 4); + shearX(PI / 4.0); + rect(0, 0, 30, 30); + +
+alt: white irregular quadrilateral with black outline at top middle. +chainable: true +--- + + +# shearX diff --git a/src/content/reference/en/p5/shearY.mdx b/src/content/reference/en/p5/shearY.mdx new file mode 100644 index 0000000000..9ddfa4707b --- /dev/null +++ b/src/content/reference/en/p5/shearY.mdx @@ -0,0 +1,57 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shearY +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Shears a shape around the y-axis the amount specified by the angle + + parameter. Angles should be specified in the current angleMode. Objects + + are always sheared around their relative position to the origin and + + positive numbers shear objects in a clockwise direction.

+ +

Transformations apply to everything that happens after and subsequent + + calls to the function accumulates the effect. For example, calling + + shearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If + + shearY() is called within the draw(), the transformation is reset when + + the loop begins again.

+ +

Technically, shearY() multiplies the current + transformation matrix by a + + rotation matrix. This function can be further controlled by the + + push() and pop() functions.

+line: 490 +params: + - name: angle + description: | +

angle of shear specified in radians or degrees, + depending on current angleMode

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + translate(width / 4, height / 4); + shearY(PI / 4.0); + rect(0, 0, 30, 30); + +
+alt: white irregular quadrilateral with black outline at middle bottom. +chainable: true +--- + + +# shearY diff --git a/src/content/reference/en/p5/shininess.mdx b/src/content/reference/en/p5/shininess.mdx new file mode 100644 index 0000000000..464719e430 --- /dev/null +++ b/src/content/reference/en/p5/shininess.mdx @@ -0,0 +1,50 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shininess +module: 3D +submodule: Material +file: src/webgl/material.js +description: | +

Sets the amount of gloss ("shininess") of a + specularMaterial().

+

The default and minimum value is 1.

+line: 1139 +params: + - name: shine + description: | +

degree of shininess

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe('two spheres, one more shiny than the other'); + } + function draw() { + background(0); + noStroke(); + let locX = mouseX - width / 2; + let locY = mouseY - height / 2; + ambientLight(60, 60, 60); + pointLight(255, 255, 255, locX, locY, 50); + specularMaterial(250); + translate(-25, 0, 0); + shininess(1); + sphere(20); + translate(50, 0, 0); + shininess(20); + sphere(20); + } + +
+alt: 'two spheres, one more shiny than the other' +chainable: true +--- + + +# shininess diff --git a/src/content/reference/en/p5/shorten.mdx b/src/content/reference/en/p5/shorten.mdx new file mode 100644 index 0000000000..4222778426 --- /dev/null +++ b/src/content/reference/en/p5/shorten.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shorten +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Decreases an array by one element and returns the shortened array, + maps to Array.pop().

+line: 161 +params: + - name: list + description: | +

Array to shorten

+ type: Array +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let myArray = ['A', 'B', 'C']; + print(myArray); // ['A', 'B', 'C'] + let newArray = shorten(myArray); + print(myArray); // ['A','B','C'] + print(newArray); // ['A','B'] + } +
+return: + description: shortened Array + type: Array +chainable: false +--- + + +# shorten diff --git a/src/content/reference/en/p5/shuffle.mdx b/src/content/reference/en/p5/shuffle.mdx new file mode 100644 index 0000000000..b6917177bd --- /dev/null +++ b/src/content/reference/en/p5/shuffle.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: shuffle +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Randomizes the order of the elements of an array. Implements + + Fisher-Yates Shuffle Algorithm.

+line: 185 +params: + - name: array + description: | +

Array to shuffle

+ type: Array + - name: bool + description: | +

modify passed array

+ type: Boolean + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let regularArr = ['ABC', 'def', createVector(), TAU, Math.E]; + print(regularArr); + shuffle(regularArr, true); // force modifications to passed array + print(regularArr); + + // By default shuffle() returns a shuffled cloned array: + let newArr = shuffle(regularArr); + print(regularArr); + print(newArr); + } +
+return: + description: shuffled Array + type: Array +chainable: false +--- + + +# shuffle diff --git a/src/content/reference/en/p5/sin.mdx b/src/content/reference/en/p5/sin.mdx new file mode 100644 index 0000000000..7dd481c4d8 --- /dev/null +++ b/src/content/reference/en/p5/sin.mdx @@ -0,0 +1,74 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sin +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

Calculates the sine of an angle. sin() is useful for many + geometric tasks + + in creative coding. The values returned oscillate between -1 and 1 as the + + input angle increases. sin() takes into account the current + + angleMode.

+line: 239 +params: + - name: angle + description: | +

the angle.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + background(200); + + let t = frameCount; + let x = 50; + let y = 30 * sin(t * 0.05) + 50; + line(x, 50, x, y); + circle(x, y, 20); + + describe('A white ball on a string oscillates up and down.'); + } + +
+ +
+ + function draw() { + let x = frameCount; + let y = 30 * sin(x * 0.1) + 50; + point(x, y); + + describe('A series of black dots form a wave pattern.'); + } + +
+ +
+ + function draw() { + let t = frameCount; + let x = 30 * cos(t * 0.1) + 50; + let y = 10 * sin(t * 0.2) + 50; + point(x, y); + + describe('A series of black dots form an infinity symbol.'); + } + +
+return: + description: sine of the angle. + type: Number +chainable: false +--- + + +# sin diff --git a/src/content/reference/en/p5/smooth.mdx b/src/content/reference/en/p5/smooth.mdx new file mode 100644 index 0000000000..f7742c5928 --- /dev/null +++ b/src/content/reference/en/p5/smooth.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SMOOTH +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 718 +itemtype: property +class: p5 +chainable: false +--- + + +# SMOOTH diff --git a/src/content/reference/en/p5/sort.mdx b/src/content/reference/en/p5/sort.mdx new file mode 100644 index 0000000000..ff5f338c7d --- /dev/null +++ b/src/content/reference/en/p5/sort.mdx @@ -0,0 +1,56 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sort +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Sorts an array of numbers from smallest to largest, or puts an array of + words in alphabetical order. The original array is not modified; a + re-ordered array is returned. The count parameter states the number of + elements to sort. For example, if there are 12 elements in an array and + count is set to 5, only the first 5 elements in the array will be sorted.

+line: 227 +params: + - name: list + description: | +

Array to sort

+ type: Array + - name: count + description: | +

number of elements to sort, starting from 0

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let words = ['banana', 'apple', 'pear', 'lime']; + print(words); // ['banana', 'apple', 'pear', 'lime'] + let count = 4; // length of array + + words = sort(words, count); + print(words); // ['apple', 'banana', 'lime', 'pear'] + } +
+
+ function setup() { + let numbers = [2, 6, 1, 5, 14, 9, 8, 12]; + print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12] + let count = 5; // Less than the length of the array + + numbers = sort(numbers, count); + print(numbers); // [1,2,5,6,14,9,8,12] + } +
+return: + description: the sorted list + type: Array +chainable: false +--- + + +# sort diff --git a/src/content/reference/en/p5/soundFormats.mdx b/src/content/reference/en/p5/soundFormats.mdx new file mode 100644 index 0000000000..549cd255ea --- /dev/null +++ b/src/content/reference/en/p5/soundFormats.mdx @@ -0,0 +1,48 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: soundFormats +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: | +

List the SoundFile formats that you will include. LoadSound + will search your directory for these extensions, and will pick + a format that is compatable with the client's web browser. + Here is a free online file + converter.

+line: 925 +params: + - name: formats + description: | +

i.e. 'mp3', 'wav', 'ogg'

+ type: String + optional: true + multiple: true +itemtype: method +class: p5 +example: + - |- + +
+ function preload() { + // set the global sound formats + soundFormats('mp3', 'ogg'); + + // load either beatbox.mp3, or .ogg, depending on browser + mySound = loadSound('assets/beatbox.mp3'); + } + + function setup() { + let cnv = createCanvas(100, 100); + background(220); + text('sound loaded! tap to play', 10, 20, width - 20); + cnv.mousePressed(function() { + mySound.play(); + }); + } +
+chainable: false +--- + + +# soundFormats diff --git a/src/content/reference/en/p5/soundOut.mdx b/src/content/reference/en/p5/soundOut.mdx new file mode 100644 index 0000000000..fbb10b6924 --- /dev/null +++ b/src/content/reference/en/p5/soundOut.mdx @@ -0,0 +1,23 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: soundOut +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: > +

p5.soundOut is the p5.sound final output bus. It sends output + to + + the destination of this window's web audio context. It contains + + Web Audio API nodes including a dyanmicsCompressor (.limiter), + + and Gain Nodes for .input and .output.

+line: 782 +itemtype: property +class: p5 +chainable: false +--- + + +# soundOut diff --git a/src/content/reference/en/p5/specularColor.mdx b/src/content/reference/en/p5/specularColor.mdx new file mode 100644 index 0000000000..13882f09de --- /dev/null +++ b/src/content/reference/en/p5/specularColor.mdx @@ -0,0 +1,85 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: specularColor +module: 3D +submodule: Lights +file: src/webgl/light.js +description: > +

Sets the color of the specular highlight of a non-ambient light + + (i.e. all lights except ambientLight()).

+ +

specularColor() affects only the lights which are created after + + it in the code.

+ +

This function is used in combination with + + specularMaterial(). + + If a geometry does not use specularMaterial(), this function + + will have no effect.

+ +

The default color is white (255, 255, 255), which is used if + + specularColor() is not explicitly called.

+ +

Note: specularColor is equivalent to the Processing function + + lightSpecular.

+line: 134 +itemtype: method +class: p5 +example: + - |- + +
+ + let setRedSpecularColor = true; + + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + describe( + 'Sphere with specular highlight. Clicking the mouse toggles the specular highlight color between red and the default white.' + ); + } + + function draw() { + background(0); + + ambientLight(60); + + // add a point light to showcase specular color + // -- use mouse location to position the light + let lightPosX = mouseX - width / 2; + let lightPosY = mouseY - height / 2; + // -- set the light's specular color + if (setRedSpecularColor) { + specularColor(255, 0, 0); // red specular highlight + } + // -- create the light + pointLight(200, 200, 200, lightPosX, lightPosY, 50); // white light + + // use specular material with high shininess + specularMaterial(150); + shininess(50); + + sphere(30, 64, 64); + } + + function mouseClicked() { + setRedSpecularColor = !setRedSpecularColor; + } + +
+alt: |- + Sphere with specular highlight. Clicking the mouse toggles the + specular highlight color between red and the default white. +chainable: true +--- + + +# specularColor diff --git a/src/content/reference/en/p5/specularMaterial.mdx b/src/content/reference/en/p5/specularMaterial.mdx new file mode 100644 index 0000000000..565709ff71 --- /dev/null +++ b/src/content/reference/en/p5/specularMaterial.mdx @@ -0,0 +1,71 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: specularMaterial +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the specular color of the material.

+ +

A specular material is reflective (shiny). The shininess can be + + controlled by the shininess() function.

+ +

Like ambientMaterial(), + + the specularMaterial() color is the color the object will reflect + + under ambientLight(). + + However unlike ambientMaterial(), for all other types of lights + + (directionalLight(), + + pointLight(), + + spotLight()), + + a specular material will reflect the color of the light + source. + + This is what gives it its "shiny" appearance.

+ +

You can view more materials in this + + example.

+line: 1053 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + noStroke(); + describe('torus with specular material'); + } + + function draw() { + background(0); + + ambientLight(60); + + // add point light to showcase specular material + let locX = mouseX - width / 2; + let locY = mouseY - height / 2; + pointLight(255, 255, 255, locX, locY, 50); + + specularMaterial(250); + shininess(50); + torus(30, 10, 64, 64); + } + +
+alt: torus with specular material +chainable: true +--- + + +# specularMaterial diff --git a/src/content/reference/en/p5/sphere.mdx b/src/content/reference/en/p5/sphere.mdx new file mode 100644 index 0000000000..0ae6faa143 --- /dev/null +++ b/src/content/reference/en/p5/sphere.mdx @@ -0,0 +1,104 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sphere +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Draw a sphere with given radius.

+ +

DetailX and detailY determines the number of subdivisions in the + x-dimension + + and the y-dimension of a sphere. More subdivisions make the sphere seem + + smoother. The recommended maximum values are both 24. Using a value greater + + than 24 may cause a warning or slow down the browser.

+line: 389 +params: + - name: radius + description: | +

radius of circle

+ type: Number + optional: true + - name: detailX + description: | +

optional number of subdivisions in x-dimension

+ type: Integer + optional: true + - name: detailY + description: | +

optional number of subdivisions in y-dimension

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a sphere with radius 40 + function setup() { + createCanvas(100, 100, WEBGL); + describe('a white sphere with black wireframe lines'); + } + + function draw() { + background(205, 102, 94); + sphere(40); + } + +
+ - |- + +
+ + let detailX; + // slide to see how detailX works + function setup() { + createCanvas(100, 100, WEBGL); + detailX = createSlider(3, 24, 3); + detailX.position(10, height + 5); + detailX.style('width', '80px'); + describe( + 'a white sphere with low detail on the x-axis, including a slider to adjust detailX' + ); + } + + function draw() { + background(205, 105, 94); + rotateY(millis() / 1000); + sphere(40, detailX.value(), 16); + } + +
+ - |- + +
+ + let detailY; + // slide to see how detailY works + function setup() { + createCanvas(100, 100, WEBGL); + detailY = createSlider(3, 16, 3); + detailY.position(10, height + 5); + detailY.style('width', '80px'); + describe( + 'a white sphere with low detail on the y-axis, including a slider to adjust detailY' + ); + } + + function draw() { + background(205, 105, 94); + rotateY(millis() / 1000); + sphere(40, 16, detailY.value()); + } + +
+chainable: true +--- + + +# sphere diff --git a/src/content/reference/en/p5/splice.mdx b/src/content/reference/en/p5/splice.mdx new file mode 100644 index 0000000000..756fc084c8 --- /dev/null +++ b/src/content/reference/en/p5/splice.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: splice +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Inserts a value or an array of values into an existing array. The first + parameter specifies the initial array to be modified, and the second + parameter defines the data to be inserted. The third parameter is an index + value which specifies the array position from which to insert data. + (Remember that array index numbering starts at zero, so the first position + is 0, the second position is 1, and so on.)

+line: 273 +params: + - name: list + description: | +

Array to splice into

+ type: Array + - name: value + description: | +

value to be spliced in

+ type: Any + - name: position + description: | +

in the array from which to insert data

+ type: Integer +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let myArray = [0, 1, 2, 3, 4]; + let insArray = ['A', 'B', 'C']; + print(myArray); // [0, 1, 2, 3, 4] + print(insArray); // ['A','B','C'] + + splice(myArray, insArray, 3); + print(myArray); // [0,1,2,'A','B','C',3,4] + } +
+return: + description: the list + type: Array +chainable: false +--- + + +# splice diff --git a/src/content/reference/en/p5/split.mdx b/src/content/reference/en/p5/split.mdx new file mode 100644 index 0000000000..6b1fc51e6c --- /dev/null +++ b/src/content/reference/en/p5/split.mdx @@ -0,0 +1,65 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: split +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

The split() function maps to String.split(), it + breaks a String into + + pieces using a character or string as the delimiter. The delim parameter + + specifies the character or characters that mark the boundaries between + + each piece. A String[] array is returned that contains each of the pieces.

+ +

The splitTokens() function works in a + similar fashion, except that it + + splits using a range of characters instead of a specific character or + + sequence.

+line: 427 +params: + - name: value + description: | +

the String to be split

+ type: String + - name: delim + description: | +

the String used to separate the data

+ type: String +itemtype: method +class: p5 +example: + - >- + +
+ + + + let names = 'Pat,Xio,Alex'; + + let splitString = split(names, ','); + + text(splitString[0], 5, 30); + + text(splitString[1], 5, 50); + + text(splitString[2], 5, 70); + + describe('“Pat” top left, “Xio” mid left, and “Alex” displayed bottom + left'); + + + +
+return: + description: Array of Strings + type: 'String[]' +chainable: false +--- + + +# split diff --git a/src/content/reference/en/p5/splitTokens.mdx b/src/content/reference/en/p5/splitTokens.mdx new file mode 100644 index 0000000000..042d75f99f --- /dev/null +++ b/src/content/reference/en/p5/splitTokens.mdx @@ -0,0 +1,54 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: splitTokens +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: > +

The splitTokens() function splits a String + at one or many character + + delimiters or "tokens." The delim parameter specifies the character or + + characters to be used as a boundary.

+ +

If no delim characters are specified, any whitespace character is used to + + split. Whitespace characters include tab (\t), line feed (\n), carriage + + return (\r), form feed (\f), and space.

+line: 458 +params: + - name: value + description: | +

the String to be split

+ type: String + - name: delim + description: | +

list of individual Strings that will be used as + separators

+ type: String + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + let myStr = 'Mango, Banana, Lime'; + let myStrArr = splitTokens(myStr, ','); + + print(myStrArr); // prints : ["Mango"," Banana"," Lime"] + } + +
+return: + description: Array of Strings + type: 'String[]' +chainable: false +--- + + +# splitTokens diff --git a/src/content/reference/en/p5/spotLight.mdx b/src/content/reference/en/p5/spotLight.mdx new file mode 100644 index 0000000000..f3dc10dd11 --- /dev/null +++ b/src/content/reference/en/p5/spotLight.mdx @@ -0,0 +1,87 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: spotLight +module: 3D +submodule: Lights +file: src/webgl/light.js +description: > +

Creates a spot light with the given color, position, + + light direction, angle, and concentration.

+ +

Like a pointLight(), a spotLight() + + emits light from a specific point (position). It has a different effect + + when it is positioned farther vs. nearer an object.

+ +

However, unlike a pointLight(), the light is emitted in one + direction + + along a conical shape. The shape of the cone can be controlled using + + the angle and concentration parameters.

+ +

The angle parameter is used to + + determine the radius of the cone. And the concentration + + parameter is used to focus the light towards the center of + + the cone. Both parameters are optional, however if you want + + to specify concentration, you must also specify + angle. + + The minimum concentration value is 1.

+ +

A maximum of 5 spot lights can be active at once.

+ +

Note: lights need to be called (whether directly or indirectly) + + within draw() to remain persistent in a looping program. + + Placing them in setup() will cause them to only have an effect + + the first time through the loop.

+line: 747 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(100, 100, WEBGL); + describe( + 'scene with sphere and spot light. The position of the light is controlled with the mouse position.' + ); + } + function draw() { + background(0); + // move your mouse to change light position + let locX = mouseX - width / 2; + let locY = mouseY - height / 2; + // to set the light position, + // think of the world's coordinate as: + // -width/2,-height/2 ----------- width/2,-height/2 + // | | + // | 0,0 | + // | | + // -width/2,height/2 ----------- width/2,height/2 + ambientLight(50); + spotLight(0, 250, 0, locX, locY, 100, 0, 0, -1, Math.PI / 16); + noStroke(); + sphere(40); + } + +
+alt: |- + scene with sphere and spot light. The position of + the light is controlled with the mouse position. +chainable: true +--- + + +# spotLight diff --git a/src/content/reference/en/p5/sq.mdx b/src/content/reference/en/p5/sq.mdx new file mode 100644 index 0000000000..72fe1e8ffc --- /dev/null +++ b/src/content/reference/en/p5/sq.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sq +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Squares a number, which means multiplying the number by itself. The value + + returned is always a positive number.

+ +

For example, sq(3) evaluates 3 × 3 which is 9. + sq(-3) evaluates + + -3 × -3 which is also 9. Multiplying two negative numbers produces + + a positive number.

+line: 670 +params: + - name: 'n' + description: | +

number to square.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Invert the y-axis. + scale(1, -1); + translate(0, -height); + + let x = frameCount; + let y = 0.01 * sq(x); + point(x, y); + + describe('A series of black dots that get higher quickly from left to right.'); + } + +
+return: + description: squared number. + type: Number +chainable: false +--- + + +# sq diff --git a/src/content/reference/en/p5/sqrt.mdx b/src/content/reference/en/p5/sqrt.mdx new file mode 100644 index 0000000000..a173e46a4e --- /dev/null +++ b/src/content/reference/en/p5/sqrt.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: sqrt +module: Math +submodule: Calculation +file: src/math/calculation.js +description: > +

Calculates the square root of a number. A number's square root can be + + multiplied by itself to produce the original number.

+ +

For example, sqrt(9) returns 3 because 3 × 3 = 9. + sqrt() always + + returns a positive value. sqrt() doesn't work with negative + arguments + + such as sqrt(-9).

+line: 700 +params: + - name: 'n' + description: | +

non-negative number to square root.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + // Invert the y-axis. + scale(1, -1); + translate(0, -height); + + let x = frameCount; + let y = 5 * sqrt(x); + point(x, y); + + describe('A series of black dots that get higher slowly from left to right.'); + } + +
+return: + description: square root of number. + type: Number +chainable: false +--- + + +# sqrt diff --git a/src/content/reference/en/p5/square.mdx b/src/content/reference/en/p5/square.mdx new file mode 100644 index 0000000000..1bc0e081cd --- /dev/null +++ b/src/content/reference/en/p5/square.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: SQUARE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 341 +itemtype: property +class: p5 +chainable: false +--- + + +# SQUARE diff --git a/src/content/reference/en/p5/storeItem.mdx b/src/content/reference/en/p5/storeItem.mdx new file mode 100644 index 0000000000..573657c6dd --- /dev/null +++ b/src/content/reference/en/p5/storeItem.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: storeItem +module: Data +submodule: LocalStorage +file: src/data/local_storage.js +description: | +

Stores a value in local storage under the key name. + Local storage is saved in the browser and persists + between browsing sessions and page reloads. + The key can be the name of the variable but doesn't + have to be. To retrieve stored items + see getItem. + Sensitive data such as passwords or personal information + should not be stored in local storage.

+line: 10 +params: + - name: key + description: '' + type: String + - name: value + description: '' + type: String|Number|Object|Boolean|p5.Color|p5.Vector +itemtype: method +class: p5 +example: + - |2- + +
+ // Type to change the letter in the + // center of the canvas. + // If you reload the page, it will + // still display the last key you entered + let myText; + function setup() { + createCanvas(100, 100); + myText = getItem('myText'); + if (myText === null) { + myText = ''; + } + describe(`When you type the key name is displayed as black text on white background. + If you reload the page, the last letter typed is still displaying.`); + } + function draw() { + textSize(40); + background(255); + text(myText, width / 2, height / 2); + } + function keyPressed() { + myText = key; + storeItem('myText', myText); + } +
+chainable: false +--- + + +# storeItem diff --git a/src/content/reference/en/p5/str.mdx b/src/content/reference/en/p5/str.mdx new file mode 100644 index 0000000000..f3c30ed4eb --- /dev/null +++ b/src/content/reference/en/p5/str.mdx @@ -0,0 +1,37 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: str +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a boolean, string or number to its string representation. + When an array of values is passed in, then an array of strings of the same + length is returned.

+line: 86 +params: + - name: 'n' + description: | +

value to parse

+ type: String|Boolean|Number|Array +itemtype: method +class: p5 +example: + - |- + +
+ print(str('10')); // "10" + print(str(10.31)); // "10.31" + print(str(-10)); // "-10" + print(str(true)); // "true" + print(str(false)); // "false" + print(str([true, '10.3', 9.8])); // [ "true", "10.3", "9.8" ] +
+return: + description: string representation of value + type: String +chainable: false +--- + + +# str diff --git a/src/content/reference/en/p5/string.mdx b/src/content/reference/en/p5/string.mdx new file mode 100644 index 0000000000..c012cc7dd0 --- /dev/null +++ b/src/content/reference/en/p5/string.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: string +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

A string is one of the 7 primitive + data types in Javascript. + + A string is a series of text characters. In Javascript, a string value must + + be surrounded by either single-quotation marks(') or double-quotation + marks(").

+ +

From the + MDN entry: + + A string is a sequence of characters used to represent text.

+line: 309 +itemtype: property +class: p5 +example: + - |- + +
+ + let mood = 'chill'; + console.log(typeof mood); // prints 'string' to the console + +
+alt: This example does not render anything +chainable: false +--- + + +# string diff --git a/src/content/reference/en/p5/stroke.mdx b/src/content/reference/en/p5/stroke.mdx new file mode 100644 index 0000000000..2c01d8de02 --- /dev/null +++ b/src/content/reference/en/p5/stroke.mdx @@ -0,0 +1,15 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: STROKE +module: Constants +submodule: Constants +file: src/core/constants.js +description: '' +line: 660 +itemtype: property +class: p5 +chainable: false +--- + + +# STROKE diff --git a/src/content/reference/en/p5/strokeCap.mdx b/src/content/reference/en/p5/strokeCap.mdx new file mode 100644 index 0000000000..f1c43bbeb3 --- /dev/null +++ b/src/content/reference/en/p5/strokeCap.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: strokeCap +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Sets the style for rendering line endings. These ends are either rounded + + (ROUND), squared (SQUARE), or extended + (PROJECT). The default cap is + + ROUND.

+ +

The argument passed to strokeCap() must be written in ALL CAPS + because + + the constants ROUND, SQUARE, and + PROJECT are defined this way. + + JavaScript is a case-sensitive language.

+line: 209 +params: + - name: cap + description: | +

either ROUND, SQUARE, or PROJECT

+ type: Constant +itemtype: method +class: p5 +example: + - >- + +
+ + + + strokeWeight(12.0); + + strokeCap(ROUND); + + line(20, 30, 80, 30); + + strokeCap(SQUARE); + + line(20, 50, 80, 50); + + strokeCap(PROJECT); + + line(20, 70, 80, 70); + + describe('Three horizontal lines. The top line has rounded ends, the middle + line has squared ends, and the bottom line has longer, squared ends.'); + + + +
+chainable: true +--- + + +# strokeCap diff --git a/src/content/reference/en/p5/strokeJoin.mdx b/src/content/reference/en/p5/strokeJoin.mdx new file mode 100644 index 0000000000..4f2d733f3c --- /dev/null +++ b/src/content/reference/en/p5/strokeJoin.mdx @@ -0,0 +1,120 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: strokeJoin +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Sets the style of the joints which connect line segments. These joints are + + either mitered (MITER), beveled (BEVEL), or rounded + (ROUND). The default + + joint is MITER in 2D mode and ROUND in WebGL + mode.

+ +

The argument passed to strokeJoin() must be written in ALL + CAPS because + + the constants MITER, BEVEL, and ROUND + are defined this way. + + JavaScript is a case-sensitive language.

+line: 247 +params: + - name: join + description: | +

either MITER, BEVEL, or ROUND

+ type: Constant +itemtype: method +class: p5 +example: + - >- + +
+ + + + noFill(); + + strokeWeight(10.0); + + strokeJoin(MITER); + + beginShape(); + + vertex(35, 20); + + vertex(65, 50); + + vertex(35, 80); + + endShape(); + + describe('A right-facing arrowhead shape with a pointed tip in center of + canvas.'); + + + +
+ + +
+ + + + noFill(); + + strokeWeight(10.0); + + strokeJoin(BEVEL); + + beginShape(); + + vertex(35, 20); + + vertex(65, 50); + + vertex(35, 80); + + endShape(); + + describe('A right-facing arrowhead shape with a flat tip in center of + canvas.'); + + + +
+ + +
+ + + + noFill(); + + strokeWeight(10.0); + + strokeJoin(ROUND); + + beginShape(); + + vertex(35, 20); + + vertex(65, 50); + + vertex(35, 80); + + endShape(); + + describe('A right-facing arrowhead shape with a rounded tip in center of + canvas.'); + + + +
+chainable: true +--- + + +# strokeJoin diff --git a/src/content/reference/en/p5/strokeWeight.mdx b/src/content/reference/en/p5/strokeWeight.mdx new file mode 100644 index 0000000000..ea81fd8f0c --- /dev/null +++ b/src/content/reference/en/p5/strokeWeight.mdx @@ -0,0 +1,81 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: strokeWeight +module: Shape +submodule: Attributes +file: src/core/shape/attributes.js +description: > +

Sets the width of the stroke used for lines, points, and the border around + + shapes. All widths are set in units of pixels.

+ +

Note that strokeWeight() is affected by any transformation or + scaling that + + has been applied previously.

+line: 314 +params: + - name: weight + description: | +

the weight of the stroke (in pixels).

+ type: Number +itemtype: method +class: p5 +example: + - >- + +
+ + + + // Default. + + line(20, 20, 80, 20); + + // Thicker. + + strokeWeight(4); + + line(20, 40, 80, 40); + + // Beastly. + + strokeWeight(10); + + line(20, 70, 80, 70); + + describe('Three horizontal black lines. The top line is thin, the middle is + medium, and the bottom is thick.'); + + + +
+ + +
+ + + + // Default. + + line(20, 20, 80, 20); + + // Adding scale transformation. + + scale(5); + + // Coordinates adjusted for scaling. + + line(4, 8, 16, 8); + + describe('Two horizontal black lines. The top line is thin and the bottom is + five times thicker than the top.'); + + + +
+chainable: true +--- + + +# strokeWeight diff --git a/src/content/reference/en/p5/subset.mdx b/src/content/reference/en/p5/subset.mdx new file mode 100644 index 0000000000..7352cc5420 --- /dev/null +++ b/src/content/reference/en/p5/subset.mdx @@ -0,0 +1,52 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: subset +module: Data +submodule: Array Functions +file: src/utilities/array_functions.js +description: | +

Extracts an array of elements from an existing array. The list parameter + defines the array from which the elements will be copied, and the start + and count parameters specify which elements to extract. If no count is + given, elements will be extracted from the start to the end of the array. + When specifying the start, remember that the first array element is 0. + This function does not change the source array.

+line: 308 +params: + - name: list + description: | +

Array to extract from

+ type: Array + - name: start + description: | +

position to begin

+ type: Integer + - name: count + description: | +

number of values to extract

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + let myArray = [1, 2, 3, 4, 5]; + print(myArray); // [1, 2, 3, 4, 5] + + let sub1 = subset(myArray, 0, 3); + let sub2 = subset(myArray, 2, 2); + print(sub1); // [1,2,3] + print(sub2); // [3,4] + } +
+return: + description: Array of extracted elements + type: Array +chainable: false +--- + + +# subset diff --git a/src/content/reference/en/p5/tan.mdx b/src/content/reference/en/p5/tan.mdx new file mode 100644 index 0000000000..8d230d557c --- /dev/null +++ b/src/content/reference/en/p5/tan.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: tan +module: Math +submodule: Trigonometry +file: src/math/trigonometry.js +description: > +

Calculates the tangent of an angle. tan() is useful for many + geometric + + tasks in creative coding. The values returned range from -Infinity + + to Infinity and repeat periodically as the input angle increases. + tan() + + takes into account the current angleMode.

+line: 295 +params: + - name: angle + description: | +

the angle.

+ type: Number +itemtype: method +class: p5 +example: + - |- + +
+ + function draw() { + let x = frameCount; + let y = 5 * tan(x * 0.1) + 50; + point(x, y); + + describe('A series of identical curves drawn with black dots. Each curve starts from the top of the canvas, continues down at a slight angle, flattens out at the middle of the canvas, then continues to the bottom.'); + } + +
+return: + description: tangent of the angle. + type: Number +chainable: false +--- + + +# tan diff --git a/src/content/reference/en/p5/textAlign.mdx b/src/content/reference/en/p5/textAlign.mdx new file mode 100644 index 0000000000..a301bac5ba --- /dev/null +++ b/src/content/reference/en/p5/textAlign.mdx @@ -0,0 +1,122 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textAlign +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: > +

Sets the way text is aligned when text() is + called.

+ +

By default, calling text('hi', 10, 20) places the bottom-left + corner of + + the text's bounding box at (10, 20).

+ +

The first parameter, horizAlign, changes the way + + text() interprets x-coordinates. By default, the + + x-coordinate sets the left edge of the bounding box. textAlign() + accepts + + the following values for horizAlign: LEFT, + CENTER, or RIGHT.

+ +

The second parameter, vertAlign, is optional. It changes the + way + + text() interprets y-coordinates. By default, the + + y-coordinate sets the bottom edge of the bounding box. + textAlign() + + accepts the following values for vertAlign: TOP, + BOTTOM, CENTER, + + or BASELINE.

+line: 11 +itemtype: method +class: p5 +example: + - >- + +
+ + + + strokeWeight(0.5); + + line(50, 0, 50, 100); + + + textSize(16); + + textAlign(RIGHT); + + text('ABCD', 50, 30); + + textAlign(CENTER); + + text('EFGH', 50, 50); + + textAlign(LEFT); + + text('IJKL', 50, 70); + + + describe('The letters ABCD displayed at top-left, EFGH at center, and IJKL + at bottom-right. A vertical line divides the canvas in half.'); + + + +
+ + +
+ + + + strokeWeight(0.5); + + + line(0, 12, width, 12); + + textAlign(CENTER, TOP); + + text('TOP', 50, 12); + + + line(0, 37, width, 37); + + textAlign(CENTER, CENTER); + + text('CENTER', 50, 37); + + + line(0, 62, width, 62); + + textAlign(CENTER, BASELINE); + + text('BASELINE', 50, 62); + + + line(0, 97, width, 97); + + textAlign(CENTER, BOTTOM); + + text('BOTTOM', 50, 97); + + + describe('The words "TOP", "CENTER", "BASELINE", and "BOTTOM" each drawn + relative to a horizontal line. Their positions demonstrate different + vertical alignments.'); + + + +
+chainable: true +--- + + +# textAlign diff --git a/src/content/reference/en/p5/textAscent.mdx b/src/content/reference/en/p5/textAscent.mdx new file mode 100644 index 0000000000..b5e3ae4026 --- /dev/null +++ b/src/content/reference/en/p5/textAscent.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textAscent +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: | +

Returns the ascent of the current font at its current size. The ascent + represents the distance, in pixels, of the tallest character above + the baseline.

+line: 258 +itemtype: method +class: p5 +example: + - |- + +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + textFont(font); + + // Different for each font. + let fontScale = 0.8; + + let baseY = 75; + strokeWeight(0.5); + + // Draw small text. + textSize(24); + text('dp', 0, baseY); + // Draw baseline and ascent. + let a = textAscent() * fontScale; + line(0, baseY, 23, baseY); + line(23, baseY - a, 23, baseY); + + // Draw large text. + textSize(48); + text('dp', 45, baseY); + // Draw baseline and ascent. + a = textAscent() * fontScale; + line(45, baseY, 91, baseY); + line(91, baseY - a, 91, baseY); + + describe('The letters "dp" written twice in different sizes. Each version has a horizontal baseline. A vertical line extends upward from each baseline to the top of the "d".'); + } + +
+return: + description: ascent measured in units of pixels. + type: Number +chainable: false +--- + + +# textAscent diff --git a/src/content/reference/en/p5/textDescent.mdx b/src/content/reference/en/p5/textDescent.mdx new file mode 100644 index 0000000000..b04f9195e2 --- /dev/null +++ b/src/content/reference/en/p5/textDescent.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textDescent +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: | +

Returns the descent of the current font at its current size. The descent + represents the distance, in pixels, of the character with the longest + descender below the baseline.

+line: 310 +itemtype: method +class: p5 +example: + - |- + +
+ + let font; + + function preload() { + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + background(200); + textFont(font); + + // Different for each font. + let fontScale = 0.9; + + let baseY = 75; + strokeWeight(0.5); + + // Draw small text. + textSize(24); + text('dp', 0, baseY); + // Draw baseline and descent. + let d = textDescent() * fontScale; + line(0, baseY, 23, baseY); + line(23, baseY, 23, baseY + d); + + // Draw large text. + textSize(48); + text('dp', 45, baseY); + // Draw baseline and descent. + d = textDescent() * fontScale; + line(45, baseY, 91, baseY); + line(91, baseY, 91, baseY + d); + + describe('The letters "dp" written twice in different sizes. Each version has a horizontal baseline. A vertical line extends downward from each baseline to the bottom of the "p".'); + } + +
+return: + description: descent measured in units of pixels. + type: Number +chainable: false +--- + + +# textDescent diff --git a/src/content/reference/en/p5/textFont.mdx b/src/content/reference/en/p5/textFont.mdx new file mode 100644 index 0000000000..8d1746cbde --- /dev/null +++ b/src/content/reference/en/p5/textFont.mdx @@ -0,0 +1,104 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textFont +module: Typography +submodule: Loading & Displaying +file: src/typography/loading_displaying.js +description: > +

Sets the font used by the text() function.

+ +

The first parameter, font, sets the font. + textFont() recognizes either + + a p5.Font object or a string with the name of a + + system font. For example, 'Courier New'.

+ +

The second parameter, size, is optional. It sets the font size + in pixels. + + This has the same effect as calling textSize().

+ +

Note: WEBGL mode only supports fonts loaded with + + loadFont().

+line: 335 +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + textFont('Courier New'); + textSize(24); + text('hi', 35, 55); + + describe('The text "hi" written in a black, monospace font on a gray background.'); + } + +
+ +
+ + function setup() { + background('black'); + fill('palegreen'); + textFont('Courier New', 10); + text('You turn to the left and see a door. Do you enter?', 5, 5, 90, 90); + text('>', 5, 70); + + describe('A text prompt from a game is written in a green, monospace font on a black background.'); + } + +
+ +
+ + function setup() { + background(200); + textFont('Verdana'); + let currentFont = textFont(); + text(currentFont, 25, 50); + + describe('The text "Verdana" written in a black, sans-serif font on a gray background.'); + } + +
+ +
+ + let fontRegular; + let fontItalic; + let fontBold; + + function preload() { + fontRegular = loadFont('assets/Regular.otf'); + fontItalic = loadFont('assets/Italic.ttf'); + fontBold = loadFont('assets/Bold.ttf'); + } + + function setup() { + background(200); + textFont(fontRegular); + text('I am Normal', 10, 30); + textFont(fontItalic); + text('I am Italic', 10, 50); + textFont(fontBold); + text('I am Bold', 10, 70); + + describe('The statements "I am Normal", "I am Italic", and "I am Bold" written in black on separate lines. The statements have normal, italic, and bold fonts, respectively.'); + } + +
+return: + description: current font or p5 Object. + type: Object +chainable: false +--- + + +# textFont diff --git a/src/content/reference/en/p5/textLeading.mdx b/src/content/reference/en/p5/textLeading.mdx new file mode 100644 index 0000000000..ef157b586d --- /dev/null +++ b/src/content/reference/en/p5/textLeading.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textLeading +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: > +

Sets the spacing between lines of text when + + text() is called. Spacing is measured in pixels.

+ +

Calling textLeading() without an argument returns the current + spacing.

+line: 85 +itemtype: method +class: p5 +example: + - >- + +
+ + + + // "\n" starts a new line of text. + + let lines = 'one\ntwo'; + + + text(lines, 10, 25); + + + textLeading(30); + + text(lines, 70, 25); + + + describe('The words "one" and "two" written on separate lines twice. The + words on the left have less vertical spacing than the words on the right.'); + + + +
+chainable: true +--- + + +# textLeading diff --git a/src/content/reference/en/p5/textOutput.mdx b/src/content/reference/en/p5/textOutput.mdx new file mode 100644 index 0000000000..8377591b69 --- /dev/null +++ b/src/content/reference/en/p5/textOutput.mdx @@ -0,0 +1,158 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textOutput +module: Environment +submodule: Environment +file: src/accessibility/outputs.js +description: > +

Creates a screen reader-accessible description for shapes on the canvas. + + textOutput() adds a general description, list of shapes, and + + table of shapes to the web page.

+ +

The general description includes the canvas size, canvas color, and number + + of shapes. For example, + + Your output is a, 100 by 100 pixels, gray canvas containing the + following 2 shapes:.

+ +

A list of shapes follows the general description. The list describes the + + color, location, and area of each shape. For example, + + a red circle at middle covering 3% of the canvas. Each shape can + be + + selected to get more details.

+ +

textOutput() uses its table of shapes as a list. The table + describes the + + shape, color, location, coordinates and area. For example, + + red circle location = middle area = 3%. This is different from + + gridOutput(), which uses its table as a + grid.

+ +

The display parameter is optional. It determines how the + description is + + displayed. If LABEL is passed, as in + textOutput(LABEL), the description + + will be visible in a div element next to the canvas. Using LABEL + creates + + unhelpful duplicates for screen readers. Only use LABEL during + + development. If FALLBACK is passed, as in + textOutput(FALLBACK), the + + description will only be visible to screen readers. This is the default + + mode.

+ +

Read + + How to label your p5.js code to + + learn more about making sketches accessible.

+line: 10 +params: + - name: display + description: | +

either FALLBACK or LABEL.

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + // Add the text description. + textOutput(); + + // Draw a couple of shapes. + background(200); + fill(255, 0, 0); + circle(20, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle and a blue square on a gray background.'); + } + +
+ +
+ + function setup() { + // Add the text description and + // display it for debugging. + textOutput(LABEL); + + // Draw a couple of shapes. + background(200); + fill(255, 0, 0); + circle(20, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle and a blue square on a gray background.'); + } + +
+ +
+ + function draw() { + // Add the text description. + textOutput(); + + // Draw a moving circle. + background(200); + let x = frameCount * 0.1; + fill(255, 0, 0); + circle(x, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle moves from left to right above a blue square.'); + } + +
+ +
+ + function draw() { + // Add the text description and + // display it for debugging. + textOutput(LABEL); + + // Draw a moving circle. + background(200); + let x = frameCount * 0.1; + fill(255, 0, 0); + circle(x, 20, 20); + fill(0, 0, 255); + square(50, 50, 50); + + // Add a general description of the canvas. + describe('A red circle moves from left to right above a blue square.'); + } + +
+chainable: false +--- + + +# textOutput diff --git a/src/content/reference/en/p5/textSize.mdx b/src/content/reference/en/p5/textSize.mdx new file mode 100644 index 0000000000..af33f6d9ab --- /dev/null +++ b/src/content/reference/en/p5/textSize.mdx @@ -0,0 +1,47 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textSize +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: > +

Sets the font size when + + text() is called. Font size is measured in pixels.

+ +

Calling textSize() without an arugment returns the current + size.

+line: 119 +itemtype: method +class: p5 +example: + - >- + +
+ + + + textSize(12); + + text('Font Size 12', 10, 30); + + textSize(14); + + text('Font Size 14', 10, 60); + + textSize(16); + + text('Font Size 16', 10, 90); + + + describe('The text "Font Size 12" drawn small, "Font Size 14" drawn medium, + and "Font Size 16" drawn large.'); + + + +
+chainable: true +--- + + +# textSize diff --git a/src/content/reference/en/p5/textStyle.mdx b/src/content/reference/en/p5/textStyle.mdx new file mode 100644 index 0000000000..251f60ad7c --- /dev/null +++ b/src/content/reference/en/p5/textStyle.mdx @@ -0,0 +1,61 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textStyle +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: > +

Sets the style for system fonts when + + text() is called. textStyle() accepts the + + following values: NORMAL, ITALIC, BOLD + or BOLDITALIC.

+ +

textStyle() may be overridden by CSS styling. This function + doesn't + + affect fonts loaded with loadFont().

+line: 152 +itemtype: method +class: p5 +example: + - >- + +
+ + + + textSize(12); + + textAlign(CENTER); + + + textStyle(NORMAL); + + text('Normal', 50, 15); + + textStyle(ITALIC); + + text('Italic', 50, 40); + + textStyle(BOLD); + + text('Bold', 50, 65); + + textStyle(BOLDITALIC); + + text('Bold Italic', 50, 90); + + + describe('The words "Normal" displayed normally, "Italic" in italic, "Bold" + in bold, and "Bold Italic" in bold italics.'); + + + +
+chainable: true +--- + + +# textStyle diff --git a/src/content/reference/en/p5/textWidth.mdx b/src/content/reference/en/p5/textWidth.mdx new file mode 100644 index 0000000000..82db1b5f23 --- /dev/null +++ b/src/content/reference/en/p5/textWidth.mdx @@ -0,0 +1,62 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textWidth +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: | +

Returns the maximum width of a string of text drawn when + text() is called.

+line: 192 +params: + - name: str + description: | +

string of text to measure.

+ type: String +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + textSize(28); + strokeWeight(0.5); + let s = 'yoyo'; + let w = textWidth(s); + text(s, 22, 55); + line(22, 55, 22 + w, 55); + + describe('The word "yoyo" underlined.'); + } + +
+ +
+ + function setup() { + background(200); + + textSize(28); + strokeWeight(0.5); + // "\n" starts a new line. + let s = 'yo\nyo'; + let w = textWidth(s); + text(s, 22, 55); + line(22, 55, 22 + w, 55); + + describe('The word "yo" written twice, one copy beneath the other. The words are divided by a horizontal line.'); + } + +
+return: + description: width measured in units of pixels. + type: Number +chainable: false +--- + + +# textWidth diff --git a/src/content/reference/en/p5/textWrap.mdx b/src/content/reference/en/p5/textWrap.mdx new file mode 100644 index 0000000000..d00d0f7498 --- /dev/null +++ b/src/content/reference/en/p5/textWrap.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textWrap +module: Typography +submodule: Attributes +file: src/typography/attributes.js +description: > +

Sets the style for wrapping text when + + text() is called. textWrap() accepts the + + following values:

+ +

WORD starts new lines of text at spaces. If a string of text + doesn't + + have spaces, it may overflow the text box and the canvas. This is the + + default style.

+ +

CHAR starts new lines as needed to stay within the text + box.

+ +

textWrap() only works when the maximum width is set for a text + box. For + + example, calling text('Have a wonderful day', 0, 10, 100) sets + the + + maximum width to 100 pixels.

+ +

Calling textWrap() without an argument returns the current + style.

+line: 369 +params: + - name: style + description: | +

text wrapping style, either WORD or CHAR.

+ type: Constant +itemtype: method +class: p5 +example: + - |- + +
+ + textSize(20); + textWrap(WORD); + text('Have a wonderful day', 0, 10, 100); + +
+ +
+ + textSize(20); + textWrap(CHAR); + text('Have a wonderful day', 0, 10, 100); + +
+ +
+ + textSize(20); + textWrap(CHAR); + text('祝你有美好的一天', 0, 10, 100); + +
+return: + description: style + type: String +chainable: false +--- + + +# textWrap diff --git a/src/content/reference/en/p5/textureMode.mdx b/src/content/reference/en/p5/textureMode.mdx new file mode 100644 index 0000000000..f4d9d5c772 --- /dev/null +++ b/src/content/reference/en/p5/textureMode.mdx @@ -0,0 +1,88 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textureMode +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the coordinate space for texture mapping. The default mode is IMAGE + + which refers to the actual coordinates of the image. + + NORMAL refers to a normalized space of values ranging from 0 to 1.

+ +

With IMAGE, if an image is 100×200 pixels, mapping the image onto the + entire + + size of a quad would require the points (0,0) (100, 0) (100,200) (0,200). + + The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1).

+line: 674 +params: + - name: mode + description: | +

either IMAGE or NORMAL

+ type: Constant +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('quad with a texture, mapped using normalized coordinates'); + } + + function draw() { + texture(img); + textureMode(NORMAL); + beginShape(); + vertex(-50, -50, 0, 0); + vertex(50, -50, 1, 0); + vertex(50, 50, 1, 1); + vertex(-50, 50, 0, 1); + endShape(); + } + +
+ - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + describe('quad with a texture, mapped using image coordinates'); + } + + function draw() { + texture(img); + textureMode(IMAGE); + beginShape(); + vertex(-50, -50, 0, 0); + vertex(50, -50, img.width, 0); + vertex(50, 50, img.width, img.height); + vertex(-50, 50, 0, img.height); + endShape(); + } + +
+alt: 'quad with a texture, mapped using image coordinates' +chainable: false +--- + + +# textureMode diff --git a/src/content/reference/en/p5/textureWrap.mdx b/src/content/reference/en/p5/textureWrap.mdx new file mode 100644 index 0000000000..7b9e33d988 --- /dev/null +++ b/src/content/reference/en/p5/textureWrap.mdx @@ -0,0 +1,91 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: textureWrap +module: 3D +submodule: Material +file: src/webgl/material.js +description: > +

Sets the global texture wrapping mode. This controls how textures behave + + when their uv's go outside of the 0 to 1 range. There are three options: + + CLAMP, REPEAT, and MIRROR.

+ +

CLAMP causes the pixels at the edge of the texture to extend to the bounds. + + REPEAT causes the texture to tile repeatedly until reaching the bounds. + + MIRROR works similarly to REPEAT but it flips the texture with every new + tile.

+ +

REPEAT & MIRROR are only available if the texture + + is a power of two size (128, 256, 512, 1024, etc.).

+ +

This method will affect all textures in your sketch until a subsequent + + textureWrap() call is made.

+ +

If only one argument is provided, it will be applied to both the + + horizontal and vertical axes.

+line: 752 +params: + - name: wrapX + description: | +

either CLAMP, REPEAT, or MIRROR

+ type: Constant + - name: wrapY + description: | +

either CLAMP, REPEAT, or MIRROR

+ type: Constant + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + function preload() { + img = loadImage('assets/rockies128.jpg'); + } + + function setup() { + createCanvas(100, 100, WEBGL); + textureWrap(MIRROR); + describe('an image of the rocky mountains repeated in mirrored tiles'); + } + + function draw() { + background(0); + + let dX = mouseX; + let dY = mouseY; + + let u = lerp(1.0, 2.0, dX); + let v = lerp(1.0, 2.0, dY); + + scale(width / 2); + + texture(img); + + beginShape(TRIANGLES); + vertex(-1, -1, 0, 0, 0); + vertex(1, -1, 0, u, 0); + vertex(1, 1, 0, u, v); + + vertex(1, 1, 0, u, v); + vertex(-1, 1, 0, 0, v); + vertex(-1, -1, 0, 0, 0); + endShape(); + } + +
+alt: an image of the rocky mountains repeated in mirrored tiles +chainable: false +--- + + +# textureWrap diff --git a/src/content/reference/en/p5/tint.mdx b/src/content/reference/en/p5/tint.mdx new file mode 100644 index 0000000000..00e8dad0e2 --- /dev/null +++ b/src/content/reference/en/p5/tint.mdx @@ -0,0 +1,121 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: tint +module: Image +submodule: Loading & Displaying +file: src/image/loading_displaying.js +description: > +

Tints images using a specified color.

+ +

The version of tint() with one parameter interprets it one of + four ways. + + If the parameter is a number, it's interpreted as a grayscale value. If the + + parameter is a string, it's interpreted as a CSS color string. An array of + + [R, G, B, A] values or a p5.Color object + can + + also be used to set the tint color.

+ +

The version of tint() with two parameters uses the first one + as a + + grayscale value and the second as an alpha value. For example, calling + + tint(255, 128) will make an image 50% transparent.

+ +

The version of tint() with three parameters interprets them as + RGB or + + HSB values, depending on the current + + colorMode(). The optional fourth parameter + + sets the alpha value. For example, tint(255, 0, 0, 100) will give + images + + a red tint and make them transparent.

+line: 1098 +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + image(img, 0, 0); + tint('red'); + image(img, 50, 0); + + describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + image(img, 0, 0); + tint(255, 0, 0); + image(img, 50, 0); + + describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + image(img, 0, 0); + tint(255, 0, 0, 100); + image(img, 50, 0); + + describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a transparent red tint.'); + } + +
+ +
+ + let img; + + function preload() { + img = loadImage('assets/laDefense.jpg'); + } + + function setup() { + image(img, 0, 0); + tint(255, 180); + image(img, 50, 0); + + describe('Two images of an umbrella and a ceiling side-by-side. The image on the right is transparent.'); + } + +
+chainable: false +--- + + +# tint diff --git a/src/content/reference/en/p5/torus.mdx b/src/content/reference/en/p5/torus.mdx new file mode 100644 index 0000000000..a088af4e44 --- /dev/null +++ b/src/content/reference/en/p5/torus.mdx @@ -0,0 +1,126 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: torus +module: Shape +submodule: 3D Primitives +file: src/webgl/3d_primitives.js +description: > +

Draw a torus with given radius and tube radius

+ +

DetailX and detailY determine the number of subdivisions in the x-dimension + and + + the y-dimension of a torus. More subdivisions make the torus appear to be + smoother. + + The default and maximum values for detailX and detailY are 24 and 16, + respectively. + + Setting them to relatively small values like 4 and 6 allows you to create new + + shapes other than a torus.

+line: 1006 +params: + - name: radius + description: | +

radius of the whole ring

+ type: Number + optional: true + - name: tubeRadius + description: | +

radius of the tube

+ type: Number + optional: true + - name: detailX + description: | +

number of segments in x-dimension, + the more segments the smoother geometry + default is 24

+ type: Integer + optional: true + - name: detailY + description: | +

number of segments in y-dimension, + the more segments the smoother geometry + default is 16

+ type: Integer + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // draw a spinning torus + // with ring radius 30 and tube radius 15 + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + describe('a rotating white torus'); + } + + function draw() { + background(205, 102, 94); + rotateX(frameCount * 0.01); + rotateY(frameCount * 0.01); + torus(30, 15); + } + +
+ - |- + +
+ + // slide to see how detailX works + let detailX; + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + detailX = createSlider(3, 24, 3); + detailX.position(10, height + 5); + detailX.style('width', '80px'); + describe( + 'a rotating white torus with limited X detail, with a slider that adjusts detailX' + ); + } + + function draw() { + background(205, 102, 94); + rotateY(millis() / 1000); + torus(30, 15, detailX.value(), 12); + } + +
+ - |- + +
+ + // slide to see how detailY works + let detailY; + function setup() { + createCanvas(100, 100, WEBGL); + camera(0, 0, 50*sqrt(3), 0, 0, 0, 0, 1, 0); + perspective(PI/3, 1, 5*sqrt(3), 500*sqrt(3)); + detailY = createSlider(3, 16, 3); + detailY.position(10, height + 5); + detailY.style('width', '80px'); + describe( + 'a rotating white torus with limited Y detail, with a slider that adjusts detailY' + ); + } + + function draw() { + background(205, 102, 94); + rotateY(millis() / 1000); + torus(30, 15, 16, detailY.value()); + } + +
+chainable: true +--- + + +# torus diff --git a/src/content/reference/en/p5/touchEnded.mdx b/src/content/reference/en/p5/touchEnded.mdx new file mode 100644 index 0000000000..42c9f9feca --- /dev/null +++ b/src/content/reference/en/p5/touchEnded.mdx @@ -0,0 +1,79 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchEnded +module: Events +submodule: Touch +file: src/events/touch.js +description: > +

The touchEnded() function is called every + time a touch ends. If no + + touchEnded() function is defined, the mouseReleased() function will be + + called instead if it is defined.

+ + Browsers may have different default behaviors attached to various touch + + events. To prevent any default behavior for this event, add "return false" + + to the end of the method.

+line: 212 +params: + - name: event + description: | +

optional TouchEvent callback argument.

+ type: TouchEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Release touch within the image to + // change the value of the rectangle + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('50-by-50 black rect turns white with touch.'); + } + function touchEnded() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+ +
+ + function touchEnded() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + describe('no image displayed'); + +
+ +
+ + // returns a TouchEvent object + // as a callback argument + function touchEnded(event) { + console.log(event); + } + describe('no image displayed'); + +
+chainable: false +--- + + +# touchEnded diff --git a/src/content/reference/en/p5/touchMoved.mdx b/src/content/reference/en/p5/touchMoved.mdx new file mode 100644 index 0000000000..846658a9b9 --- /dev/null +++ b/src/content/reference/en/p5/touchMoved.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchMoved +module: Events +submodule: Touch +file: src/events/touch.js +description: > +

The touchMoved() function is called every + time a touch move is registered. + + If no touchMoved() function is defined, the mouseDragged() function will + + be called instead if it is defined.

+ + Browsers may have different default behaviors attached to various touch + + events. To prevent any default behavior for this event, add "return false" + + to the end of the method.

+line: 141 +params: + - name: event + description: | +

optional TouchEvent callback argument.

+ type: TouchEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Move your finger across the page + // to change its value + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('50-by-50 black rect turns lighter with touch until white. resets'); + } + function touchMoved() { + value = value + 5; + if (value > 255) { + value = 0; + } + } + +
+ +
+ + function touchMoved() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + describe('no image displayed'); + +
+ +
+ + // returns a TouchEvent object + // as a callback argument + function touchMoved(event) { + console.log(event); + } + describe('no image displayed'); + +
+chainable: false +--- + + +# touchMoved diff --git a/src/content/reference/en/p5/touchStarted.mdx b/src/content/reference/en/p5/touchStarted.mdx new file mode 100644 index 0000000000..b5c4569e20 --- /dev/null +++ b/src/content/reference/en/p5/touchStarted.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touchStarted +module: Events +submodule: Touch +file: src/events/touch.js +description: > +

The touchStarted() function is called once after every time a touch is + + registered. If no touchStarted() function is + defined, the mousePressed() + + function will be called instead if it is defined.

+ + Browsers may have different default behaviors attached to various touch + + events. To prevent any default behavior for this event, add "return false" + + to the end of the method.

+line: 70 +params: + - name: event + description: | +

optional TouchEvent callback argument.

+ type: TouchEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + // Touch within the image to change + // the value of the rectangle + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe('50-by-50 black rect turns white with touch event.'); + } + function touchStarted() { + if (value === 0) { + value = 255; + } else { + value = 0; + } + } + +
+ +
+ + function touchStarted() { + ellipse(mouseX, mouseY, 5, 5); + // prevent default + return false; + } + describe('no image displayed'); + +
+ +
+ + // returns a TouchEvent object + // as a callback argument + function touchStarted(event) { + console.log(event); + } + describe('no image displayed'); + +
+chainable: false +--- + + +# touchStarted diff --git a/src/content/reference/en/p5/touches.mdx b/src/content/reference/en/p5/touches.mdx new file mode 100644 index 0000000000..bae8dde92e --- /dev/null +++ b/src/content/reference/en/p5/touches.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: touches +module: Events +submodule: Touch +file: src/events/touch.js +description: | +

The system variable touches[] contains an array of the positions of all + current touch points, relative to (0, 0) of the canvas, and IDs identifying a + unique touch as it moves. Each element in the array is an object with x, y, + and id properties.

+

The touches[] array is not supported on Safari and IE on touch-based + desktops (laptops).

+line: 10 +itemtype: property +class: p5 +example: + - |- + +
+ + // On a touchscreen device, touch + // the canvas using one or more fingers + // at the same time + function draw() { + clear(); + let display = touches.length + ' touches'; + text(display, 5, 10); + describe(`Number of touches currently registered are displayed + on the canvas`); + } + +
+chainable: false +--- + + +# touches diff --git a/src/content/reference/en/p5/translate.mdx b/src/content/reference/en/p5/translate.mdx new file mode 100644 index 0000000000..0b0ac9c4d4 --- /dev/null +++ b/src/content/reference/en/p5/translate.mdx @@ -0,0 +1,70 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: translate +module: Transform +submodule: Transform +file: src/core/transform.js +description: > +

Specifies an amount to displace objects within the display window. + + The x parameter specifies left/right translation, the y parameter + + specifies up/down translation.

+ +

Transformations are cumulative and apply to everything that happens after + + and subsequent calls to the function accumulates the effect. For example, + + calling translate(50, 0) and then translate(20, 0) is the same as + + translate(70, 0). If translate() is called within + draw(), the + + transformation is reset when the loop begins again. This function can be + + further controlled by using push() and pop().

+line: 529 +itemtype: method +class: p5 +example: + - |- + +
+ + translate(30, 20); + rect(0, 0, 55, 55); + +
+ +
+ + rect(0, 0, 55, 55); // Draw rect at original 0,0 + translate(30, 20); + rect(0, 0, 55, 55); // Draw rect at new 0,0 + translate(14, 14); + rect(0, 0, 55, 55); // Draw rect at new 0,0 + +
+ + +
+ + function draw() { + background(200); + rectMode(CENTER); + translate(width / 2, height / 2); + translate(p5.Vector.fromAngle(millis() / 1000, 40)); + rect(0, 0, 20, 20); + } + +
+alt: |- + white 55×55 rect with black outline at center right. + 3 white 55×55 rects with black outlines at top-l, center-r and bottom-r. + a 20×20 white rect moving in a circle around the canvas +chainable: true +--- + + +# translate diff --git a/src/content/reference/en/p5/triangle.mdx b/src/content/reference/en/p5/triangle.mdx new file mode 100644 index 0000000000..1a601a1df7 --- /dev/null +++ b/src/content/reference/en/p5/triangle.mdx @@ -0,0 +1,58 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: triangle +module: Shape +submodule: 2D Primitives +file: src/core/shape/2d_primitives.js +description: > +

Draws a triangle to the canvas. A triangle is a three-sided polygon. The + + first two parameters specify the triangle's first point (x1,y1). + The middle + + two parameters specify its second point (x2,y2). And the last two + parameters + + specify its third point (x3, y3).

+line: 759 +params: + - name: x1 + description: | +

x-coordinate of the first point.

+ type: Number + - name: y1 + description: | +

y-coordinate of the first point.

+ type: Number + - name: x2 + description: | +

x-coordinate of the second point.

+ type: Number + - name: y2 + description: | +

y-coordinate of the second point.

+ type: Number + - name: x3 + description: | +

x-coordinate of the third point.

+ type: Number + - name: y3 + description: | +

y-coordinate of the third point.

+ type: Number +itemtype: method +class: p5 +example: + - | + +
+ + triangle(30, 75, 58, 20, 86, 75); + describe('A white triangle with a black outline on a gray canvas.'); + +
+chainable: true +--- + + +# triangle diff --git a/src/content/reference/en/p5/trim.mdx b/src/content/reference/en/p5/trim.mdx new file mode 100644 index 0000000000..b2e55c7f3a --- /dev/null +++ b/src/content/reference/en/p5/trim.mdx @@ -0,0 +1,31 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: trim +module: Data +submodule: String Functions +file: src/utilities/string_functions.js +description: | +

Removes whitespace characters from the beginning and end of a String. In + addition to standard whitespace characters such as space, carriage return, + and tab, this function also removes the Unicode "nbsp" character.

+line: 511 +itemtype: method +class: p5 +example: + - |- + +
+ + let string = trim(' No new lines\n '); + text(string + ' here', 2, 50); + describe('“No new lines here” displayed center canvas'); + +
+return: + description: a trimmed String + type: String +chainable: false +--- + + +# trim diff --git a/src/content/reference/en/p5/turnAxis.mdx b/src/content/reference/en/p5/turnAxis.mdx new file mode 100644 index 0000000000..cb57d2ac0b --- /dev/null +++ b/src/content/reference/en/p5/turnAxis.mdx @@ -0,0 +1,51 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: turnAxis +module: Events +submodule: Acceleration +file: src/events/acceleration.js +description: > +

When a device is rotated, the axis that triggers the deviceTurned() + + method is stored in the turnAxis variable. The turnAxis variable is only + defined within + + the scope of deviceTurned().

+line: 378 +itemtype: property +class: p5 +example: + - |- + +
+ + // Run this example on a mobile device + // Rotate the device by 90 degrees in the + // X-axis to change the value. + + let value = 0; + function draw() { + fill(value); + rect(25, 25, 50, 50); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when device turns`); + describe(`50-by-50 black rect in center of canvas. + turns white on mobile when x-axis turns`); + } + function deviceTurned() { + if (turnAxis === 'X') { + if (value === 0) { + value = 255; + } else if (value === 255) { + value = 0; + } + } + } + +
+chainable: false +--- + + +# turnAxis diff --git a/src/content/reference/en/p5/unchar.mdx b/src/content/reference/en/p5/unchar.mdx new file mode 100644 index 0000000000..23e01dabf4 --- /dev/null +++ b/src/content/reference/en/p5/unchar.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: unchar +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a single-character string to its corresponding integer + representation. When an array of single-character string values is passed + in, then an array of integers of the same length is returned.

+line: 214 +itemtype: method +class: p5 +example: + - |- + +
+ print(unchar('A')); // 65 + print(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ] + print(unchar(split('ABC', ''))); // [ 65, 66, 67 ] +
+return: + description: integer representation of value + type: Number +chainable: false +--- + + +# unchar diff --git a/src/content/reference/en/p5/unhex.mdx b/src/content/reference/en/p5/unhex.mdx new file mode 100644 index 0000000000..87ea025c51 --- /dev/null +++ b/src/content/reference/en/p5/unhex.mdx @@ -0,0 +1,29 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: unhex +module: Data +submodule: Conversion +file: src/utilities/conversion.js +description: | +

Converts a string representation of a hexadecimal number to its equivalent + integer value. When an array of strings in hexadecimal notation is passed + in, an array of integers of the same length is returned.

+line: 293 +itemtype: method +class: p5 +example: + - |- + +
+ print(unhex('A')); // 10 + print(unhex('FF')); // 255 + print(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ] +
+return: + description: integer representation of hexadecimal value + type: Number +chainable: false +--- + + +# unhex diff --git a/src/content/reference/en/p5/updatePixels.mdx b/src/content/reference/en/p5/updatePixels.mdx new file mode 100644 index 0000000000..e55d4559a5 --- /dev/null +++ b/src/content/reference/en/p5/updatePixels.mdx @@ -0,0 +1,75 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: updatePixels +module: Image +submodule: Pixels +file: src/image/pixels.js +description: > +

Updates the canvas with the RGBA values in the + + pixels array.

+ +

updatePixels() only needs to be called after changing values + in the + + pixels array. Such changes can be made directly + + after calling loadPixels() or by calling + + set().

+line: 884 +params: + - name: x + description: | +

x-coordinate of the upper-left corner of region + to update.

+ type: Number + optional: true + - name: 'y' + description: | +

y-coordinate of the upper-left corner of region + to update.

+ type: Number + optional: true + - name: w + description: | +

width of region to update.

+ type: Number + optional: true + - name: h + description: | +

height of region to update.

+ type: Number + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + let img; + + function preload() { + img = loadImage('assets/rockies.jpg'); + } + + function setup() { + image(img, 0, 0, width, height); + let d = pixelDensity(); + let halfImage = 4 * (d * width) * (d * height / 2); + loadPixels(); + for (let i = 0; i < halfImage; i += 1) { + pixels[i + halfImage] = pixels[i]; + } + updatePixels(); + + describe('Two identical images of mountain landscapes, one on top of the other.'); + } + +
+chainable: false +--- + + +# updatePixels diff --git a/src/content/reference/en/p5/userStartAudio.mdx b/src/content/reference/en/p5/userStartAudio.mdx new file mode 100644 index 0000000000..27cd9c2eff --- /dev/null +++ b/src/content/reference/en/p5/userStartAudio.mdx @@ -0,0 +1,78 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: userStartAudio +module: p5.sound +submodule: p5.sound +file: lib/addons/p5.sound.js +description: |- +

It is not only a good practice to give users control over starting + audio. This policy is enforced by many web browsers, including iOS and + Google Chrome, which create the Web Audio API's + Audio Context + in a suspended state.

+ +

In these browser-specific policies, sound will not play until a user + interaction event (i.e. mousePressed()) explicitly resumes + the AudioContext, or starts an audio node. This can be accomplished by + calling start() on a p5.Oscillator, + play() on a p5.SoundFile, or simply + userStartAudio().

+ +

userStartAudio() starts the AudioContext on a user + gesture. The default behavior will enable audio on any + mouseUp or touchEnd event. It can also be placed in a specific + interaction function, such as mousePressed() as in the + example below. This method utilizes + StartAudioContext + , a library by Yotam Mann (MIT Licence, 2016).

+line: 198 +params: + - name: elements + description: | +

This argument can be an Element, + Selector String, NodeList, p5.Element, + jQuery Element, or an Array of any of those.

+ type: Element|Array + optional: true + - name: callback + description: | +

Callback to invoke when the AudioContext + has started

+ type: Function + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ function setup() { + // mimics the autoplay policy + getAudioContext().suspend(); + + let mySynth = new p5.MonoSynth(); + + // This won't play until the context has resumed + mySynth.play('A6'); + } + function draw() { + background(220); + textAlign(CENTER, CENTER); + text(getAudioContext().state, width/2, height/2); + } + function mousePressed() { + userStartAudio(); + } +
+return: + description: |- + Returns a Promise that resolves when + the AudioContext state is 'running' + type: Promise +chainable: false +--- + + +# userStartAudio diff --git a/src/content/reference/en/p5/vertex.mdx b/src/content/reference/en/p5/vertex.mdx new file mode 100644 index 0000000000..da1e9af794 --- /dev/null +++ b/src/content/reference/en/p5/vertex.mdx @@ -0,0 +1,146 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: vertex +module: Shape +submodule: Vertex +file: src/core/shape/vertex.js +description: > +

All shapes are constructed by connecting a series of vertices. vertex() + + is used to specify the vertex coordinates for points, lines, triangles, + + quads, and polygons. It is used exclusively within the beginShape() and + + endShape() functions.

+line: 930 +itemtype: method +class: p5 +example: + - |- + +
+ + strokeWeight(3); + beginShape(POINTS); + vertex(30, 20); + vertex(85, 20); + vertex(85, 75); + vertex(30, 75); + endShape(); + +
+ +
+ + createCanvas(100, 100, WEBGL); + background(240, 240, 240); + fill(237, 34, 93); + noStroke(); + beginShape(); + vertex(0, 35); + vertex(35, 0); + vertex(0, -35); + vertex(-35, 0); + endShape(); + +
+ +
+ + createCanvas(100, 100, WEBGL); + background(240, 240, 240); + fill(237, 34, 93); + noStroke(); + beginShape(); + vertex(-10, 10); + vertex(0, 35); + vertex(10, 10); + vertex(35, 0); + vertex(10, -8); + vertex(0, -35); + vertex(-10, -8); + vertex(-35, 0); + endShape(); + +
+ +
+ + strokeWeight(3); + stroke(237, 34, 93); + beginShape(LINES); + vertex(10, 35); + vertex(90, 35); + vertex(10, 65); + vertex(90, 65); + vertex(35, 10); + vertex(35, 90); + vertex(65, 10); + vertex(65, 90); + endShape(); + +
+ +
+ + // Click to change the number of sides. + // In WebGL mode, custom shapes will only + // display hollow fill sections when + // all calls to vertex() use the same z-value. + + let sides = 3; + let angle, px, py; + + function setup() { + createCanvas(100, 100, WEBGL); + setAttributes('antialias', true); + fill(237, 34, 93); + strokeWeight(3); + } + + function draw() { + background(200); + rotateX(frameCount * 0.01); + rotateZ(frameCount * 0.01); + ngon(sides, 0, 0, 80); + } + + function mouseClicked() { + if (sides > 6) { + sides = 3; + } else { + sides++; + } + } + + function ngon(n, x, y, d) { + beginShape(TESS); + for (let i = 0; i < n + 1; i++) { + angle = TWO_PI / n * i; + px = x + sin(angle) * d / 2; + py = y - cos(angle) * d / 2; + vertex(px, py, 0); + } + for (let i = 0; i < n + 1; i++) { + angle = TWO_PI / n * i; + px = x + sin(angle) * d / 4; + py = y - cos(angle) * d / 4; + vertex(px, py, 0); + } + endShape(); + } + +
+alt: |- + 4 black points in a square shape in middle-right of canvas. + 4 points making a diamond shape. + 8 points making a star. + 8 points making 4 lines. + A rotating 3D shape with a hollow section in the middle. +chainable: true +--- + + +# vertex diff --git a/src/content/reference/en/p5/webglVersion.mdx b/src/content/reference/en/p5/webglVersion.mdx new file mode 100644 index 0000000000..c810d936be --- /dev/null +++ b/src/content/reference/en/p5/webglVersion.mdx @@ -0,0 +1,100 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: webglVersion +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

A string variable with the WebGL version in use. Its value equals one of + + the followin string constants:

+ + + +

See setAttributes() for ways to set the + + WebGL version.

+line: 466 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Display the current WebGL version. + text(webglVersion, 42, 54); + + describe('The text "p2d" written in black on a gray background.'); + } + +
+ +
+ + let font; + + function preload() { + // Load a font to use. + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + // Create a canvas using WEBGL mode. + createCanvas(100, 50, WEBGL); + background(200); + + // Display the current WebGL version. + fill(0); + textFont(font); + text(webglVersion, -15, 5); + + describe('The text "webgl2" written in black on a gray background.'); + } + +
+ +
+ + let font; + + function preload() { + // Load a font to use. + font = loadFont('assets/inconsolata.otf'); + } + + function setup() { + // Create a canvas using WEBGL mode. + createCanvas(100, 50, WEBGL); + + // Set WebGL to version 1. + setAttributes({ version: 1 }); + + background(200); + + // Display the current WebGL version. + fill(0); + textFont(font); + text(webglVersion, -14, 5); + + describe('The text "webgl" written in black on a gray background.'); + } + +
+chainable: false +--- + + +# webglVersion diff --git a/src/content/reference/en/p5/while.mdx b/src/content/reference/en/p5/while.mdx new file mode 100644 index 0000000000..57a3a3e021 --- /dev/null +++ b/src/content/reference/en/p5/while.mdx @@ -0,0 +1,66 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: while +module: Foundation +submodule: Foundation +file: src/core/reference.js +description: > +

while creates a loop that is useful for executing + + one section of code multiple times.

+ +

With a 'while loop', the code inside of the loop body (between the curly + + braces) is run repeatedly until the test condition (inside of the parenthesis) + + evaluates to false. The condition is tested before executing the code body + + with while, so if the condition is initially false + + the loop body, or statement, will never execute.

+ +

As with any loop, it is important to ensure that the loop can 'exit', or + that + + the test condition will eventually evaluate to false. This is to keep your + loop + + from trying to run an infinite amount of times, which can crash your + browser.

+ +

From the + MDN entry: + + The while statement creates a loop that executes a specified statement as long + + as the test condition evaluates to true.The condition is evaluated before + + executing the statement.

+line: 448 +itemtype: property +class: p5 +example: + - |- + +
+ + // This example logs the lines below to the console + // 4 + // 3 + // 2 + // 1 + // 0 + let num = 5; + while (num > 0) { + num = num - 1; + console.log(num); + } + +
+alt: This example does not render anything +chainable: false +--- + + +# while diff --git a/src/content/reference/en/p5/width.mdx b/src/content/reference/en/p5/width.mdx new file mode 100644 index 0000000000..0cc619f96c --- /dev/null +++ b/src/content/reference/en/p5/width.mdx @@ -0,0 +1,83 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: width +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

A numeric variable that stores the width of the drawing canvas. Its + + default value is 100.

+ +

Calling createCanvas() or + + resizeCanvas() changes the value of + + width. Calling noCanvas() sets its + value to + + 0.

+line: 750 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + background(200); + + // Display the canvas' width. + text(width, 42, 54); + + describe('The number 100 written in black on a gray square.'); + } + +
+ +
+ + function setup() { + createCanvas(50, 100); + + background(200); + + // Display the canvas' width. + text(width, 21, 54); + + describe('The number 50 written in black on a gray rectangle.'); + } + +
+ +
+ + function setup() { + createCanvas(100, 100); + + background(200); + + // Display the canvas' width. + text(width, 42, 54); + + describe('The number 100 written in black on a gray square. When the mouse is pressed, the square becomes a rectangle and the number becomes 50.'); + } + + // If the mouse is pressed, reisze + // the canvas and display its new + // width. + function mousePressed() { + if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + resizeCanvas(50, 100); + background(200); + text(width, 21, 54); + } + } + +
+chainable: false +--- + + +# width diff --git a/src/content/reference/en/p5/winMouseX.mdx b/src/content/reference/en/p5/winMouseX.mdx new file mode 100644 index 0000000000..f61a4e9cbf --- /dev/null +++ b/src/content/reference/en/p5/winMouseX.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: winMouseX +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable winMouseX always contains the current horizontal + position of the mouse, relative to (0, 0) of the window.

+line: 189 +itemtype: property +class: p5 +example: + - |- + +
+ + let myCanvas; + + function setup() { + //use a variable to store a pointer to the canvas + myCanvas = createCanvas(100, 100); + let body = document.getElementsByTagName('body')[0]; + myCanvas.parent(body); + } + + function draw() { + background(237, 34, 93); + fill(0); + + //move the canvas to the horizontal mouse position + //relative to the window + myCanvas.position(winMouseX + 1, windowHeight / 2); + + //the y of the square is relative to the canvas + rect(20, mouseY, 60, 60); + describe(`60-by-60 black rect y moves with mouse y and fuchsia + canvas moves with mouse x`); + } + +
+chainable: false +--- + + +# winMouseX diff --git a/src/content/reference/en/p5/winMouseY.mdx b/src/content/reference/en/p5/winMouseY.mdx new file mode 100644 index 0000000000..c8f321719b --- /dev/null +++ b/src/content/reference/en/p5/winMouseY.mdx @@ -0,0 +1,46 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: winMouseY +module: Events +submodule: Mouse +file: src/events/mouse.js +description: | +

The system variable winMouseY always contains the current vertical + position of the mouse, relative to (0, 0) of the window.

+line: 226 +itemtype: property +class: p5 +example: + - |- + +
+ + let myCanvas; + + function setup() { + //use a variable to store a pointer to the canvas + myCanvas = createCanvas(100, 100); + let body = document.getElementsByTagName('body')[0]; + myCanvas.parent(body); + } + + function draw() { + background(237, 34, 93); + fill(0); + + //move the canvas to the vertical mouse position + //relative to the window + myCanvas.position(windowWidth / 2, winMouseY + 1); + + //the x of the square is relative to the canvas + rect(mouseX, 20, 60, 60); + describe(`60-by-60 black rect x moves with mouse x and + fuchsia canvas y moves with mouse y`); + } + +
+chainable: false +--- + + +# winMouseY diff --git a/src/content/reference/en/p5/windowHeight.mdx b/src/content/reference/en/p5/windowHeight.mdx new file mode 100644 index 0000000000..23f96cda3a --- /dev/null +++ b/src/content/reference/en/p5/windowHeight.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: windowHeight +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

A numeric variable that stores the height of the browser's + + layout viewport. + + This viewport is the area within the browser that's available for drawing.

+line: 634 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + // Set the canvas' width and height + // using the browser's dimensions. + createCanvas(windowWidth, windowHeight); + + background(200); + + describe('A gray canvas that takes up the entire browser window.'); + } + +
+alt: This example does not render anything. +chainable: false +--- + + +# windowHeight diff --git a/src/content/reference/en/p5/windowResized.mdx b/src/content/reference/en/p5/windowResized.mdx new file mode 100644 index 0000000000..a745f6c77e --- /dev/null +++ b/src/content/reference/en/p5/windowResized.mdx @@ -0,0 +1,55 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: windowResized +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

The code in windowResized() is called once each time the + browser window + + is resized. It's a good place to resize the canvas or make other + + adjustments to accommodate the new window size.

+ +

The event parameter is optional. If added to the function + definition, it + + can be used for debugging or other purposes.

+line: 661 +params: + - name: event + description: | +

optional resize Event.

+ type: UIEvent + optional: true +itemtype: method +class: p5 +example: + - |- + +
+ + function setup() { + createCanvas(windowWidth, windowHeight); + } + + function draw() { + background(200); + + describe('A gray canvas that takes up the entire browser window. It changes size to match the browser window.'); + } + + // Resize the canvas when the + // browser's size changes. + function windowResized() { + resizeCanvas(windowWidth, windowHeight); + } + +
+alt: This example does not render anything. +chainable: false +--- + + +# windowResized diff --git a/src/content/reference/en/p5/windowWidth.mdx b/src/content/reference/en/p5/windowWidth.mdx new file mode 100644 index 0000000000..919591291a --- /dev/null +++ b/src/content/reference/en/p5/windowWidth.mdx @@ -0,0 +1,38 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: windowWidth +module: Environment +submodule: Environment +file: src/core/environment.js +description: > +

A numeric variable that stores the width of the browser's + + layout viewport. + + This viewport is the area within the browser that's available for drawing.

+line: 607 +itemtype: property +class: p5 +example: + - |- + +
+ + function setup() { + // Set the canvas' width and height + // using the browser's dimensions. + createCanvas(windowWidth, windowHeight); + + background(200); + + describe('A gray canvas that takes up the entire browser window.'); + } + +
+alt: This example does not render anything. +chainable: false +--- + + +# windowWidth diff --git a/src/content/reference/en/p5/year.mdx b/src/content/reference/en/p5/year.mdx new file mode 100644 index 0000000000..289defbe14 --- /dev/null +++ b/src/content/reference/en/p5/year.mdx @@ -0,0 +1,32 @@ +--- +layout: '@layouts/reference/SingleReferenceLayout.astro' +title: year +module: IO +submodule: Time & Date +file: src/utilities/time_date.js +description: > +

p5.js communicates with the clock on your computer. The year() function + + returns the current year as an integer (2014, 2015, 2016, etc).

+line: 131 +itemtype: method +class: p5 +example: + - |- + +
+ + let y = year(); + text('Current year: \n' + y, 5, 50); + describe('Current year is displayed'); + +
+return: + description: the current year + type: Integer +chainable: false +--- + + +# year diff --git a/src/scripts/builders/reference.ts b/src/scripts/builders/reference.ts index 622ec00e7e..a942629a8e 100644 --- a/src/scripts/builders/reference.ts +++ b/src/scripts/builders/reference.ts @@ -4,7 +4,7 @@ import { remark } from "remark"; import remarkMDX from "remark-mdx"; import { parseLibrary } from "../parsers/reference"; -const prefix = `./src/pages/en/reference`; +const prefix = `./src/content/reference/en/`; const classMethodPreviews = {}; @@ -31,7 +31,10 @@ export const buildReference = async () => { // Build the reference file differently const indexMdx = getIndexMdx(); - await fs.writeFile(`./src/pages/en/reference/index.mdx`, indexMdx.toString()); + await fs.writeFile( + `./src/content/reference/en/index.mdx`, + indexMdx.toString(), + ); console.log("Done building reference docs!"); };