ablackbu-section c-Project-11-Composition

press mouse

sketch

var galaxy

function preload() {
    galaxy = loadImage('https://i.imgur.com/W0T1NZk.jpg')
}

function setup() {
    createCanvas(360, 280);
    background(230);
    push()
    scale(.3)
    image(galaxy,0,0)
    pop()
}
    
function draw() {
    fill(255)
    noStroke()
    ellipse(mouseX,mouseY,3,3)

}

function mousePressed(){
    
    var tur1 = makeTurtle(mouseX,mouseY);
    tur1.setColor(color(random(150,255),random(150,255),random(150,255)));
    var w = 3;
    tur1.setWeight(w)
    var side = random(5,20)
    for(var i = 0; i < 100; i++) {
        tur1.penDown();
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.right(60);
        tur1.forward(side);
        tur1.penUp();
        tur1.right(110);
        tur1.forward(side*.8);
        side *= 0.9;
        w *= 0.7
        tur1.setWeight(w);
        tur1. right(50)
    }
}

function turtleLeft(d){this.angle-=d;}function turtleRight(d){this.angle+=d;}
function turtleForward(p){var rad=radians(this.angle);var newx=this.x+cos(rad)*p;
var newy=this.y+sin(rad)*p;this.goto(newx,newy);}function turtleBack(p){
this.forward(-p);}function turtlePenDown(){this.penIsDown=true;}
function turtlePenUp(){this.penIsDown = false;}function turtleGoTo(x,y){
if(this.penIsDown){stroke(this.color);strokeWeight(this.weight);
line(this.x,this.y,x,y);}this.x = x;this.y = y;}function turtleDistTo(x,y){
return sqrt(sq(this.x-x)+sq(this.y-y));}function turtleAngleTo(x,y){
var absAngle=degrees(atan2(y-this.y,x-this.x));
var angle=((absAngle-this.angle)+360)%360.0;return angle;}
function turtleTurnToward(x,y,d){var angle = this.angleTo(x,y);if(angle< 180){
this.angle+=d;}else{this.angle-=d;}}function turtleSetColor(c){this.color=c;}
function turtleSetWeight(w){this.weight=w;}function turtleFace(angle){
this.angle = angle;}function makeTurtle(tx,ty){var turtle={x:tx,y:ty,
angle:0.0,penIsDown:true,color:color(128),weight:1,left:turtleLeft,
right:turtleRight,forward:turtleForward, back:turtleBack,penDown:turtlePenDown,
penUp:turtlePenUp,goto:turtleGoTo, angleto:turtleAngleTo,
turnToward:turtleTurnToward,distanceTo:turtleDistTo, angleTo:turtleAngleTo,
setColor:turtleSetColor, setWeight:turtleSetWeight,face:turtleFace};
return turtle;}

For this project on adapting turtles, I created a galaxy where the user is able to create stars and planets, the planets made are a similar turtle to the spiral one made in lab but these are hexagons that spiral in on each other and get smaller and lighter as they go.

Leave a Reply