psychopy.org | Reference | Downloads | Github

TypeError: visual.Circle is not a constructor

URL of experiment: https://pavlovia.org/Wake/ebbinghaus-darts

Description of the problem: I’m trying to create circles on the fly.

Python code

pic = []

for Idx in range(nflankers):
pic.append(visual.Circle(
win=win,
fillColor=flankercolour,
lineColor=“black”,
pos = [scalecos(Idx2pi/nflankers)(dtarget+offset+dflanker/2),voffset+scalesin(Idx2pi/nflankers)(dtarget+offset+dflanker/2)],
size=scale*dflanker
))

PsychoJs:

pic = [];
for (var Idx = 0, _pj_a = nflankers; (Idx < _pj_a); Idx += 1) {
pic.append(new visual.Circle({“win”: win, “fillColor”: flankercolour, “lineColor”: “black”, “pos”: [((scale * cos((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))), (voffset + ((scale * sin((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))))], “size”: (scale * dflanker)}));
}

Error: TypeError: visual.Circle is not a constructor

I switched to visual.Circle from ShapeStim because I was getting an error when running locally, despite using working code pasted from another experiment. I’ll try again if that’s easier.

I’ve already set pi=Math.pi in the startup code.

Best wishes,

Wakefield

Two suggestions. First:

"win": psychoJS.window

Second: “append” is not the same in JS vs. Python. The JS function you want is “push”. Also, I think it might work better if you create each object and then add it rather than try to create the object within the function, though I wouldn’t swear to that mattering in this case.

tempCirc = new visual.Circle({"win": psychoJS.window, 
                "fillColor": flankercolour, 
                "lineColor": "black", 
                "pos": [((scale * cos((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))), (voffset + ((scale * sin((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))))], 
                "size": (scale * dflanker)}));
pic.push(tempCirc);
1 Like

Thanks for the suggestions but I think it must be something else.

While I had missed the .append, I’d already set pi=Math.pi and win = psychoJS.window in what is likely to become a standard startup JS code (along with a shuffle function).

Trying your suggestions I now have:

pic = [];
for (var Idx = 0, _pj_a = nflankers; (Idx < _pj_a); Idx += 1) {
temppic = new visual.Circle({“win”: psychoJS.window, “fillColor”: flankercolour, “lineColor”: “black”, “pos”: [((scale * Math.cos((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))), (voffset + ((scale * Math.sin((((Idx * 2) * pi) / nflankers))) * ((dtarget + offset) + (dflanker / 2))))], “size”: (scale * dflanker)});
pic.push(temppic);
}

and it gives the same error.

I couldn’t paste your code directly because it wouldn’t initialise – presumably do to not liking the formatting.

Best wishes,

Wakefield

What do you mean wouldn’t initialize? As in, gets stuck on “initializing” when you try to run it?

Yes, that’s what I meant.

I’ve now got three routines trying to do the same thing – visual.Polygon, visual.Shapestim and visual.Circle. However, I’m finding it difficult to test because the version I’m running (either piloting on Pavlovia or locally through the runner) isn’t the latest iteration. I’m still getting visual.Circle is not a constructor, which I suspect means it doesn’t exist in PsychoJS so I’m waiting to find out whether Polygon works, or whether I’ll have to specify 36 points on a circle for Shapestim,

Best wishes,

Wakefield

Try opening your javascript console (view -> developer -> Javascript console) in chrome and see if it’s showing any error messages when you run your experiment. That’s usually what happens when it gets stuck on “initializing”, and it’s usually the result of some subtle syntax issue.