1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 10:40:54 +00:00
psychojs/docs/visual_Polygon.js.html
2021-02-20 13:02:55 +01:00

197 lines
7.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: visual/Polygon.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: visual/Polygon.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Polygonal Stimulus.
*
* @author Alain Pitiot
* @version 2021.1.0
* @copyright (c) 2017-2020 Ilixa Ltd. (http://ilixa.com) (c) 2020 Open Science Tools Ltd. (https://opensciencetools.org)
* @license Distributed under the terms of the MIT License
*/
import {ShapeStim} from './ShapeStim';
import {Color} from '../util/Color';
/**
* &lt;p>Polygonal visual stimulus.&lt;/p>
*
* @name module:visual.Polygon
* @class
* @extends ShapeStim
* @param {Object} options
* @param {String} options.name - the name used when logging messages from this stimulus
* @param {Window} options.win - the associated Window
* @param {number} [options.lineWidth= 1.5] - the line width
* @param {Color} [options.lineColor= Color('white')] the line color
* @param {Color} options.fillColor - the fill color
* @param {number} [options.opacity= 1.0] - the opacity
* @param {number} [options.edges= 3] - the number of edges of the polygon
* @param {number} [options.radius= 0.5] - the radius of the polygon
* @param {Array.&lt;number>} [options.pos= [0, 0]] - the position
* @param {number} [options.size= 1.0] - the size
* @param {number} [options.ori= 0.0] - the orientation (in degrees)
* @param {string} options.units - the units of the stimulus vertices, size and position
* @param {number} [options.contrast= 1.0] - the contrast
* @param {number} [options.depth= 0] - the depth
* @param {boolean} [options.interpolate= true] - whether or not the shape is interpolated
* @param {boolean} [options.autoDraw= false] - whether or not the stimulus should be automatically drawn on every frame flip
* @param {boolean} [options.autoLog= false] - whether or not to log
*/
export class Polygon extends ShapeStim
{
constructor({name, win, lineWidth, lineColor, fillColor, opacity, edges, radius, pos, size, ori, units, contrast, depth, interpolate, autoDraw, autoLog} = {})
{
super({
name,
win,
lineWidth,
lineColor,
fillColor,
opacity,
pos,
ori,
size,
units,
contrast,
depth,
interpolate,
autoDraw,
autoLog
});
this._psychoJS.logger.debug('create a new Polygon with name: ', name);
this._addAttribute(
'edges',
edges,
3
);
this._addAttribute(
'radius',
radius,
0.5
);
this._updateVertices();
if (this._autoLog)
{
this._psychoJS.experimentLogger.exp(`Created ${this.name} = ${this.toString()}`);
}
}
/**
* Setter for the radius attribute.
*
* @name module:visual.Polygon#setRadius
* @public
* @param {number} radius - the polygon radius
* @param {boolean} [log= false] - whether of not to log
*/
setRadius(radius, log = false)
{
const hasChanged = this._setAttribute('radius', radius, log);
if (hasChanged)
{
this._updateVertices();
}
}
/**
* Setter for the edges attribute.
*
* @name module:visual.Polygon#setEdges
* @public
* @param {number} edges - the number of edges
* @param {boolean} [log= false] - whether of not to log
*/
setEdges(edges, log = false)
{
const hasChanged = this._setAttribute('edges', Math.round(edges), log);
if (hasChanged)
{
this._updateVertices();
}
}
/**
* Update the vertices.
*
* @name module:visual.Polygon#_updateVertices
* @private
*/
_updateVertices()
{
this._psychoJS.logger.debug('update the vertices of Polygon: ', this.name);
const angle = 2.0 * Math.PI / this._edges;
const vertices = [];
for (let v = 0; v &lt; this._edges; ++v)
{
vertices.push([Math.sin(v * angle) * this._radius, Math.cos(v * angle) * this._radius]);
}
this.setVertices(vertices);
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.Keyboard.html">Keyboard</a></li><li><a href="module-core.KeyPress.html">KeyPress</a></li><li><a href="module-core.Logger.html">Logger</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.Form.html">Form</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Polygon.html">Polygon</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextBox.html">TextBox</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li><li><a href="TextInput.html">TextInput</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Sat Feb 20 2021 13:00:58 GMT+0100 (Central European Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>