05-3

<<< home | H79.2273 - The World Pixel by Pixel | W02-Pixel x Pixel

Triangles | Download the apps

PXP

Basically starting off the animated circles example, but using triangles, a random position for one vertex, and two animated vertexes shared by all triangles, when the two shared vertexes combine, the triangle becomes a line and therefore create a gradation and shift into white.



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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*      ITP Pixel by Pixel
        circles
        move mouse to interact
        Danny Rozin 2009
*/


#include "testApp.h"

//**** if you are lazy you can put some global variables here, but it is bad practice and will not work for complex data types (put in testApp.h)  ********
const int numOfCircles=1000;                                        // creating a constant integer and giving it a value,
                                                                    // In C when you create an array you have to give it a constant not a variable
int positionsX[numOfCircles], positionsY[numOfCircles];             // two arrays to hold the locations of our circles
float angle = 0;
// ofTriangle(float x1, float y1, float x2, float y2, float x3, float y3)

//************** Everything you want to happen once in the begining, but don't draw anything to the screen here a it will not work ****************
void testApp::setup(){   
    ofBackground(255,255,255);                                          // background color
    ofSetColor(0,0,0,10);                                                   // color of lines and fills
    ofEnableAlphaBlending();  
    ofEnableSmoothing();  
    ofSetLineWidth(2);  
   
    for(int i = 0;i< numOfCircles;i++){                                 // we want our random positions to stay the same, so we put them into our
        positionsX[i]= ofRandom(-ofGetWidth()*2,ofGetWidth()*2) ;                       // global arrays, otherwise, the circles would randomize every frame and it would flicker
        positionsY[i]= ofRandom(-ofGetHeight()*2,ofGetHeight()*2) ;
    }
}



//********************************************* Code in draw() executes every frame,  **********************************************************
void testApp::draw(){  
   
    if (angle <= 360 ) {
    float r = 30.0f;
    float theta = angle;
    float radians = (angle * pi)/180.0;
    float offSetCenterX = r * cos(radians);
    float offSetCenterY = r * sin(radians);
   
   
    // float offSetCenterX = 20 ;
    for(int i=0;i<numOfCircles;i++){   
    float distance = sqrt((positionsX[i]- mouseX)* (positionsX[i]- mouseX)  +   (positionsY[i]- mouseY)* (positionsY[i]- mouseY)) ;
       
        ofFill();                                                           // turn the fill on, we want black circles
        ofSetColor(0,0,0);
        // ofSetColor(255-distance/3,255-distance/3,255-distance/3);        // just for fun, make the circles darker as they grt distant
        //ofCircle(positionsX[i] ,positionsY[i],distance/ 10);         
       
        ofTriangle(positionsX[i], positionsY[i], ofGetWidth()/2-offSetCenterX-r/2, ofGetHeight()/2-offSetCenterX-r/2, mouseX, mouseY);
        //ofTriangle(positionsX[i], positionsY[i], ofGetWidth()/2, ofGetHeight()/2, mouseX, mouseY);

        ofNoFill();                                                         // turn the fill of, we want to draw a white line around each circle
        ofSetColor(255,255,255,255);                                               
        ofTriangle(positionsX[i], positionsY[i], ofGetWidth()/2-offSetCenterX-r/2, ofGetHeight()/2-offSetCenterX-r/2, mouseX, mouseY);
        //ofTriangle(positionsX[i], positionsY[i], ofGetWidth()/2, ofGetHeight()/2, mouseX, mouseY);
        //ofTriangle(positionsX[i], positionsY[i], ofGetWidth()/2, ofGetHeight()/2, mouseX, mouseY);
       
        //ofCircle(positionsX[i] ,positionsY[i],distance/ 10);     
       
        angle += 0.001;
    }} else {angle = 0;}                                                                                                   
                                                                                               
                                                                                                                                                                                                                                                                                                                                                // display the result on the screen
    printf("%f \n", ofGetFrameRate());                                      // put the frame rate into the console
}




//**************** Code in update() execute every frame, but don't draw anything here cause it won't work, in general put most stuff into draw() *************
void testApp::update(){}

//--------------------------------------------------------------
void testApp::keyPressed  (int key){ }


//--------------------------------------------------------------
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(){  }