teratail 374177

https://teratail.com/questions/374177

by cx20

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>

JavaScript

function setup() {
    createCanvas(windowWidth, windowHeight);
    frameRate(60);
}

function draw() {
    background(255);
    shikaku(createVector(width/2 , height/2 ), 40, 300, 300, color(190, 80, 80));
}



//関数shikakuを定義。
//引数(中心位置,四角形の数,幅,高さ,カラー)

function shikaku(rectLocation, numRects, width, height, rectColor) {
    stroke(rectColor);
    noFill();

    for(let i = 0; i < numRects; i++){
        rectMode(CENTER); 

        let currentWidth = map(i, 0, numRects-1, 10, width);
        let currentHeight = map(i, 0, numRects-1, 10, height);

        //通常の同心正方形
        rect(rectLocation.x, rectLocation.y, currentWidth, currentHeight);

        //傾けた同心正方形
        push();
        translate(rectLocation.x, rectLocation.y); //背景の中心で座標を回転
        rotate(PI / 6); 
        rect(0, 0, currentWidth, currentHeight);
        pop();
    }
}