Search

ICM Week 5 - Functions



This week's code is a bit of a mess. Learning how to use functions has helped organize myself immensely. But I also got myself in trouble and near the end I had to abandon the effort to keep my code nice and compact by throwing away some of the more complex functions that I couldn't get to work.


This week I wanted try out an idea I had last week and play around with making a Ye Olde signal test pattern, which were used for television broadcasts back in the 40s (they stopped being used shortly before I was born). I thought this images would be great practice implementing loops and functions in my code due to all the repeating and patterned shapes.


I was right!


I quickly found out however, that there are SO MANY elements in a test pattern I ran out of time to draw them all - hence the messy code you'll see here. I also wanted to add some interactive elements and more animations, but my eyes were bigger than my stomach this week.


What Worked:

I'm pretty proud of the rotating circles I made, which actually materialized how I wanted it to in my head. The surprise came when I started putting variables inside the rotate() function that were defined in a for() loop. The results made this really cool spiral effect.



Here's the code for that:


let angle = 0
function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(0);
  angleMode(DEGREES)
  
  
  for(let i = 0; i<=600; i+= 10){
   
  push()
  translate(width/2,height/2)
  noFill()
  rotate(angle+i)
  stroke(i-60);
  strokeWeight(5);
  arc(0,0,i,i,0,30)
  arc(0,0,i,i,60,90)
  arc(0,0,i,i,120,150)
  arc(0,0,i,i,180,210)
  arc(0,0,i,i,240,270)
  arc(0,0,i,i,240,270)
  arc(0,0,i,i,300,330)
  pop();
    angle += .0025
  }
  
}

What Didn't Work:

I'm having trouble manipulating the speed of the rotation when I'm calling the same function. It seems that each time I call the function "rotatingcircle" in my sketch, the speed variable I established as a parameter overrides the speed of the others. So right now all of the circles spin at the same rate, which originally I wanted the function arguments to determine the speed of each circle.


What I learned

I'm still trying to figure out how for() loops work. It takes a long time and a lot of tinkering to get the results I want and I often end up stumbling on results that are cooler than my intentions, which is as frustrating as it is hilarious. It's frustrating mainly because I feel like I'm impeded by my simplistic understanding of some of these functions.


It's hard for me to craft more complex code because I still find myself confused by how it all works. I know it'll get easier as I go along but I'm currently at the stage where my understanding of what is possible is still quite narrow. This makes it hard to even begin to understand how to make really cool, unique, and interactive drawings.


12:15 am - Just keep typing, just keep typing...






© 2020 by Dhemerae Ford