Golan-Schotter

by Golan Levin @ 11:12 pm 11 January 2011

Version for Processing and Processing.JS. Pressing a key pauses the animation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Schotter (1965) by Georg Nees.
// http://www.mediaartnet.org/works/schotter/
// Processing version by Golan Levin
 
// There are versions by other people at
// http://nr37.nl/software/georgnees/index.html
// http://www.openprocessing.org/visuals/?visualID=10429
// But IMHO these are inferior implementations;
// note e.g the misplaced origins for square rotation.
 
//-------------------------------
boolean go = true;
void setup() {
  size(325,565);
}
 
//-------------------------------
void draw() {
  if (go) {
    background (255);
    smooth();
    noFill();
 
    int nRows = 24;
    int nCols = 12;
    float S = 20;
    float marginX = (width  - (nCols*S))/2.0;
    float marginY = (height - (nRows*S))/2.0; 
 
    float maxRotation = (abs(mouseX)/(float)width) * 0.06; //radians
    float maxOffset =  (abs(mouseY)/(float)height) * 0.6;
 
    for (int i=0; i<nRows; i++) {
      for (int j=0; j<nCols; j++) {
        float x = marginX + j*S;
        float y = marginY + i*S;
 
        float rotationAmount = (i+1)*random(0-maxRotation, maxRotation); 
        float offsetX = i*random(0-maxOffset, maxOffset); 
        float offsetY = i*random(0-maxOffset, maxOffset); 
 
        pushMatrix();
        translate(S/2, S/2);
        translate(x+offsetX, y+offsetY);
        rotate(rotationAmount);
        translate(0-S/2, 0-S/2);
        rect(0,0,S,S);
        popMatrix();
      }
    }
  }
}
 
//-------------------------------
void keyPressed() {
  go = !go;
}

Version for OpenFrameworks v.062 (C++). This is based off the EmptyExample provided in the OF download. Note that WP-Syntax uses lang=”cpp” as the shortcode for embedding C++ code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "testApp.h"
 
bool go;
//--------------------------------------------------------------
void testApp::setup(){
	go = true;
}
 
//--------------------------------------------------------------
void testApp::draw(){
 
	ofBackground(255,255,255);
	glEnable(GL_LINE_SMOOTH);
	ofSetColor(0,0,0);
	ofNoFill();
 
	int nRows = 24;
	int nCols = 12;
	float S = 20;
	float marginX = (ofGetWidth()  - (nCols*S))/2.0;
	float marginY = (ofGetHeight() - (nRows*S))/2.0; 
 
	float maxRotation = (abs(mouseX)/(float)ofGetWidth()) * 0.06; //radians
	float maxOffset =  (abs(mouseY)/(float)ofGetHeight()) * 0.6;
 
	for (int i=0; i < nRows; i++) {
		for (int j=0; j < nCols; j++) {
			float x = marginX + j*S;
			float y = marginY + i*S;
 
			float rotationAmount = (i+1)*ofRandom (0-maxRotation, maxRotation); 
			float offsetX = i* ofRandom (0-maxOffset, maxOffset); 
			float offsetY = i* ofRandom (0-maxOffset, maxOffset); 
 
			ofPushMatrix();
			ofTranslate (S/2, S/2, 0);
			ofTranslate (x+offsetX, y+offsetY);
			ofRotateZ   (RAD_TO_DEG * rotationAmount);
			ofTranslate (0-S/2, 0-S/2);
			ofRect(0,0,S,S);
			ofPopMatrix();
		}
	}
}
 
//--------------------------------------------------------------
void testApp::keyPressed(int key){
	go = !go;
	if (!go){
		ofSetFrameRate(1);
	} else {
		ofSetFrameRate(60);
	}
}
 
//--------------------------------------------------------------
void testApp::update(){}
void testApp::keyReleased(int key){}
void testApp::mouseMoved(int x, int y ){}
void testApp::mouseDragged(int x, int y, int button){}
void testApp::mousePressed(int x, int y, int button){}
void testApp::mouseReleased(int x, int y, int button){}
void testApp::windowResized(int w, int h){}

Screencapture of OpenFrameworks version (at https://www.youtube.com/watch?v=bW-aE3OmVzo):

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2023 Interactive Art & Computational Design / Spring 2011 | powered by WordPress with Barecity