Skip to content

Dynamically create row of geometrical shapes for each trial #3208

Answered by Shaobin-Jiang
lpavan98 asked this question in Q&A
Discussion options

You must be logged in to vote

This is not going to be an easy one. We are going to have to break it up part from part.


We start from defining some constants here, namely the size, color, and shape.

const SIZE = [30, 60, 90]; // use radius to represent size
const COLOR = ['red', 'green', 'blue'];
const SHAPE = [
    // triangle
    (context, center_x, center_y, radius, color) => {
        context.save();
        context.fillStyle = color;

        context.moveTo(center_x, center_y - radius);
        context.beginPath();
        context.lineTo(center_x + radius / 2 * Math.sqrt(3), center_y + radius / 2);
        context.lineTo(center_x - radius / 2 * Math.sqrt(3), center_y + radius / 2);
        context.lineTo(center_x, 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lpavan98
Comment options

@Shaobin-Jiang
Comment options

@lpavan98
Comment options

Answer selected by lpavan98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants