mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
added coherence support. shape of dots changed to circles.
This commit is contained in:
parent
ce639a11f0
commit
3ebd48eb70
@ -6,7 +6,7 @@
|
||||
// import { core, data, sound, util, visual } from "../out/psychojs-2024.1.0.js";
|
||||
import { core, data, sound, util, visual } from "./index.js";
|
||||
|
||||
// import {StimInspector} from 'https://run.pavlovia.org/lgtst/stiminspector/StimInspector.js';
|
||||
import {StimInspector} from 'https://run.pavlovia.org/lgtst/stiminspector/StimInspector.js';
|
||||
// import {StimInspector} from '../stiminspector/StimInspector.js';
|
||||
// import {PsyexpReader} from '../psyexpreader/PsyexpReader.js';
|
||||
const { PsychoJS } = core;
|
||||
@ -38,7 +38,7 @@ psychoJS.openWindow({
|
||||
waitBlanking: true
|
||||
});
|
||||
|
||||
// new StimInspector(psychoJS.window, { core, data, sound, util, visual });
|
||||
new StimInspector(psychoJS.window, { core, data, sound, util, visual });
|
||||
|
||||
// schedule the experiment:
|
||||
// psychoJS.schedule(psychoJS.gui.DlgFromDict({
|
||||
@ -136,11 +136,11 @@ async function experimentInit() {
|
||||
// tex: 'sin',
|
||||
// mask: undefined,
|
||||
// ori: 0,
|
||||
// size: [256, 512],
|
||||
// size: [512, 512],
|
||||
// pos: [0, 0],
|
||||
// units: "pix",
|
||||
// depth: 0
|
||||
// })
|
||||
// }),
|
||||
new visual.DotStim({
|
||||
win : psychoJS.window,
|
||||
name: 'dots',
|
||||
@ -150,6 +150,7 @@ async function experimentInit() {
|
||||
pos: [0, 0],
|
||||
units: "pix",
|
||||
depth: 0,
|
||||
dotSize: 10,
|
||||
dotLife: 0,
|
||||
speed: 0.5,
|
||||
fieldShape: "circle"
|
||||
|
@ -129,6 +129,7 @@ export class DotStim extends VisualStim
|
||||
|
||||
this._size_px = util.to_px(this.size, this.units, this.win);
|
||||
this._dotsLife = new Float32Array(nDots);
|
||||
this._dotsDir = new Float32Array(nDots);
|
||||
|
||||
// TODO: DEBUG.
|
||||
// const s = new PIXI.Sprite(PIXI.Texture.WHITE);
|
||||
@ -176,17 +177,25 @@ export class DotStim extends VisualStim
|
||||
let i;
|
||||
let dot;
|
||||
let dotConfig;
|
||||
const coherentDots = Math.round(this._coherence * this._nDots);
|
||||
|
||||
for (i = 0; i < this._nDots; i ++)
|
||||
{
|
||||
dot = new PIXI.Sprite(PIXI.Texture.WHITE);
|
||||
// TODO: ensure this is an optimal way to do this.
|
||||
dot = new PIXI.Graphics();
|
||||
dot.beginFill(0xffffff);
|
||||
dot.arc(0, 0, this._dotSize * 0.5, 0, Math.PI * 2);
|
||||
dot.endFill();
|
||||
dotConfig = this._configureDot();
|
||||
dot.x = dotConfig.position.x;
|
||||
dot.y = dotConfig.position.y;
|
||||
dot.width = this._dotSize;
|
||||
dot.height = this._dotSize;
|
||||
this._pixi.addChild(dot);
|
||||
this._dotsLife[ i ] = dotConfig.lifetime;
|
||||
this._dotsDir[ i ] = this._dir;
|
||||
if (i > coherentDots)
|
||||
{
|
||||
this._dotsDir[ i ] = Math.random() * 360;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,8 +221,8 @@ export class DotStim extends VisualStim
|
||||
// Move dots.
|
||||
if (this._noiseDots === "direction")
|
||||
{
|
||||
const x = Math.cos(this._dir * Math.PI / 180);
|
||||
const y = Math.sin(this._dir * Math.PI / 180);
|
||||
const x = Math.cos(this._dotsDir[ i ] * Math.PI / 180);
|
||||
const y = Math.sin(this._dotsDir[ i ] * Math.PI / 180);
|
||||
|
||||
// TODO: ensure this is adequate conversion of speed.
|
||||
const speed_px = util.to_px([ this._speed, this._speed ], this.units, this.win)[ 0 ];
|
||||
@ -450,6 +459,12 @@ export class DotStim extends VisualStim
|
||||
}
|
||||
}
|
||||
|
||||
setCoherence(c = 1, log = false)
|
||||
{
|
||||
const coherence = Math.max(0, Math.min(1, c));
|
||||
this._setAttribute("coherence", coherence, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the stimulus, if necessary.
|
||||
*
|
||||
@ -460,12 +475,17 @@ export class DotStim extends VisualStim
|
||||
// Always update dots.
|
||||
this._updateDots();
|
||||
|
||||
if (!this._needPixiUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// if (!this._needUpdate)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
this._needPixiUpdate = false;
|
||||
// this._needUpdate = false;
|
||||
|
||||
// if (this._needPixiUpdate)
|
||||
// {
|
||||
// this._needPixiUpdate = false;
|
||||
// }
|
||||
|
||||
this._pixi.zIndex = -this._depth;
|
||||
this.opacity = this._opacity;
|
||||
|
Loading…
Reference in New Issue
Block a user