James Katungyi-Project 04

6 petal flower

james-stringart

//James Katungyi
//Section A 0900
//jkatungy@andrew.cmu.edu
//Assignment-Project-04

//variables for first set of lines for 6 different petals
//first point x&y values are the same for all 6 petals
var x1=y1=x11=y11=x21=y21=x31=y31=x41=y41=x51=y51=0;
//second point x values are the same for all 6 petals
var x2=x12=x22=x32=x42=x52=180;
//second point y values are the same for all 6 petals
var y2=y12=y22=y32=y42=y52=54;
//variables for second set of lines
//first point x&y values are the same for all 6 petals
var x3=y3=x13=y13=x23=y23=x33=y33=x43=y43=x53=y53=0;
//second point x values are the same for all 6 petals
var x4=x14=x24=x34=x44=x54=54;
//second point y values are the same for all 6 petals
var y4=y14=y24=y34=y44=y54=180;
//spacing
var spacing=18;

function setup() {
  createCanvas(480, 640);
  background(0);
  strokeWeight(1);
  r = color(255,0,0);
  g = color(0,255,0);
  b = color(0,0,255);
  rg = lerpColor(r,g,0.5);
  gb = lerpColor(g,b,0.5);
  br = lerpColor(b,r,0.5);
  push();
  translate(width/2,height/2);//locate lower tip of petal in canvas center
  //first petal
  rotate(radians(45));
  stroke(r);
  for (i=0;i<8;i++){
    line(x1,y1,x2,y2);//set of lines defines first half of petal
    x1=x1+spacing;
    y2=y2+spacing;
    line(x3,y3,x4,y4);//second set of lines defines second half of petal
    y3=y3+spacing;
    x4=x4+spacing;
    line(0,0,180,180);//middle line
  }
  //second petal
  rotate(radians(60));
  stroke(rg);
  for (i=0;i<8;i++){
    line(x11,y11,x12,y12);//first half of petal
    x11=x11+spacing;
    y12=y12+spacing;
    line(x13,y13,x14,y14);//second half of petal
    y13=y13+spacing;
    x14=x14+spacing;
    line(0,0,180,180);//middle line
  }
  //third petal
  rotate(radians(60));
  stroke(g);
  for (i=0;i<8;i++){
    line(x21,y21,x22,y22);//first half of petal
    x21=x21+spacing;
    y22=y22+spacing;
    line(x23,y23,x24,y24);//second half of petal
    y23=y23+spacing;
    x24=x24+spacing;
    line(0,0,180,180);//middle line
  }
  //fourth petal
  rotate(radians(60));
  stroke(gb);
  for (i=0;i<8;i++){
    line(x31,y31,x32,y32);//first half of petal
    x31=x31+spacing;
    y32=y32+spacing;
    line(x33,y33,x34,y34);//second half of petal
    y33=y33+spacing;
    x34=x34+spacing;
    line(0,0,180,180);//middle line
  }
  //fifth petal
  rotate(radians(60));
  stroke(b);
  for (i=0;i<8;i++){
    line(x41,y41,x42,y42);//first half of petal
    x41=x41+spacing;
    y42=y42+spacing;
    line(x43,y43,x44,y44);//second half of petal
    y43=y43+spacing;
    x44=x44+spacing;
    line(0,0,180,180);//middle line
  }
  //sixth petal
  rotate(radians(60));
  stroke(br);
  for (i=0;i<8;i++){
    line(x51,y51,x52,y52);//first half of petal
    x51=x51+spacing;
    y52=y52+spacing;
    line(x53,y53,x54,y54);//second half of petal
    y53=y53+spacing;
    x54=x54+spacing;
    line(0,0,180,180);//middle line
  }
  pop();
}

A 6 petal flower recreated from online string art patterns.stringartdiy

 

Leave a Reply