xxxxxxxxxx
42
/************************************************
Zenek Chapman
Computer Science 30
November 21 2024
The purpose of this code it to create a square rotational fractal
*********************************************************/
var angle = 0 // create variables for width and angle for rotation
var w
var h
function setup() {
createCanvas(400, 400);
w = width - 100
h = height - 100
}
function draw() {
background(0); // create background, and set square up
stroke(255)
noFill();
translate(width/2, height/2) // set the origin to the center of the screen
fractal(w)
noLoop()
}
function fractal(x){
rectMode(CENTER) // change rect mode to center
strokeWeight(2)
angleMode(DEGREES) // change anglemode to degrees
if (w > 30) {
push()
rotate(angle) // rotate the square each time
rect(0,0, w, h) // draw another square
w -= w/25//subtract a 25th of the width from the width and height
h -= h/25
angle -= 0.15 //change the angle of rotation by 0.15 degrees
fractal(w) // re-call the function
pop()}
}