I Do Have a Point – in fact, I have a list of them!

  • 0

I Do Have a Point – in fact, I have a list of them!

Category : Uncategorized

A student found a page on Code Golf – using the least number of characters to do a task in code. It’s a popular sport:

The designs they made interested me. It was really just a bunch of points spaced out around the circumference of a circle, and each point was connected to each other point by a segment. What a great mathematical exercise! It’s simple to space points out around a circle using rotate and translate in Processing:

Unfortunately, when you transform points in Processing, they don’t have absolute coordinates you can use anymore. If you want to keep their coordinates intact, you have to use sines and cosines. Here’s the position of a point r units away from the origin and rotated a certain angle:

You have to convert degrees to radians, or even better, have the computer do it. In Processing it’s as easy as putting the degrees into a function called “radians” and it will convert it for you.

 points = [] #empty points list
 for i in range(12):
     x = 250*cos(radians(360.0*i/12))
     y = 250*sin(radians(360.0*i/12))
     #put point in a list
     points.append([x,y])

In the above code I created a list to put points in, then started a for loop that would space the points evenly around the circle. Now I just had to go over every point and draw a line between it and every other point. That’s done with this nested loop:

for p in points: #from every point
    for other in points: #to every "other" point
        stroke(255,0,0) #red
        line(p[0],p[1],other[0],other[1])

“[0]” means the x-value, and “[1]” means the y-value. Now I can see the outcome with 12 points:

Of course I wanted to make it fancy and interactive, so I connected the number of points to the x-value of the mouse. Now if the user moves their mouse left and right the number of points increases and decreases.

I like the interactivity. You get to choose how crazy it gets.


-Peter Farrell
May 10, 2017


Leave a Reply