v2n2_gyrating_forms

Benjamin Fox


Based on: Gyrating Forms by James R Warner, 1977

Category: direct


Description:

This sketch is running in the browser.






/* 
Part of the ReCode Project (http://recodeproject.com)
Based on "Gyrating Forms" by James R Warner
Originally published in "Computer Graphics and Art" v2n2, 1977
Copyright (c) 2013 Benjamin Fox - OSI/MIT license (http://recodeproject/license).
*/

/* @pjs pauseOnBlur="true"; */

ArrayList<PVector> points;//container for the points generated elsewhere containing our shape
float sh_w, sh_h;//width and height of our shape
float start_angle;
int generations, deg;


void setup(){
	size(900, 650);
	background(255);

	generations = 50;//how many times we want to draw the shape
	
	deg = 0;
	start_angle = -56;//degrees of rotation we want to start drawing from

	sh_w = 0;
	sh_h = 0;

	//these points were generated by another sketch, tracing clicks on top of the template shape image to create an array of points to draw
	//this could potentially be substituted by an SVG shape or PShape description (any geometery will do)
	points = new ArrayList<PVector>();
	points.add(new PVector(19.0, 3.0));
	points.add(new PVector(67.0, 3.0));
	points.add(new PVector(52.0, 54.0));
	points.add(new PVector(153.0, 137.0));
	points.add(new PVector(234.0, 152.0));
	points.add(new PVector(234.0, 119.0));
	points.add(new PVector(268.0, 85.0));
	points.add(new PVector(299.0, 85.0));
	points.add(new PVector(318.0, 103.0));
	points.add(new PVector(333.0, 151.0));
	points.add(new PVector(366.0, 170.0));
	points.add(new PVector(500.0, 169.0));
	points.add(new PVector(547.0, 202.0));
	points.add(new PVector(515.0, 235.0));
	points.add(new PVector(483.0, 219.0));
	points.add(new PVector(385.0, 238.0));
	points.add(new PVector(401.0, 322.0));
	points.add(new PVector(517.0, 355.0));
	points.add(new PVector(616.0, 471.0));
	points.add(new PVector(582.0, 504.0));
	points.add(new PVector(484.0, 404.0));
	points.add(new PVector(350.0, 389.0));
	points.add(new PVector(269.0, 440.0));
	points.add(new PVector(252.0, 507.0));
	points.add(new PVector(203.0, 507.0));
	points.add(new PVector(219.0, 405.0));
	points.add(new PVector(252.0, 338.0));
	points.add(new PVector(187.0, 221.0));
	points.add(new PVector(135.0, 204.0));
	points.add(new PVector(1.0, 69.0));
	points.add(new PVector(1.0, 37.0));

	for (PVector p : points) {
		if (p.x > sh_w) {
			sh_w = p.x;
		}

		if (p.y > sh_h) {
			sh_h = p.y;
		}
	}

}

void draw(){

	if (deg < generations) {

		stroke(0);
		strokeWeight(1);

		pushMatrix();
		translate(width/2, height/2);//center stage
		rotate(radians(start_angle + deg));//rotate it

		translate(-(sh_w / 2), -(sh_h / 2));//reset where we start to draw our shaoe so it's central

		PVector lp = points.get(0);//initialize last point as the first in the arrayList
		int sz = points.size() - 1;//size of the arrayList

		for (int i = sz; i >= 0; i--) { 
			PVector p = (PVector) points.get(i);
			line(lp.x, lp.y, p.x, p.y);
			lp = p;
		}

		popMatrix();

		deg++;

	}

}