-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofApp.cpp
129 lines (100 loc) · 3.81 KB
/
ofApp.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetBackgroundColor(255);
ofSetBackgroundAuto(false);
ofNoFill();
ofSetCircleResolution(60);
// initialize global variables
totalRays = 20;
stepSize = 50;
radius = 100;
angleStep = 360.0/totalRays;
sunLocX = ofGetWidth()/2;
sunLocY = ofGetHeight()/2;
for(int i = 0; i < totalRays; i++)
{
noiseSeeds.push_back(ofRandom(0,10000));
}
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
// center all elements
if(mouseX != 0 || mouseY != 0)
{
// follow mouse at slow rate
sunLocX += (mouseX - sunLocX)*0.01;
sunLocY += (mouseY - sunLocY)*0.01;
}
ofTranslate(sunLocX,sunLocY);
ofSetColor(0,30);
// draw sun rays
ofBeginShape();
ofPoint initPointLocation;
float initNoisedRadius = (ofNoise(noiseSeeds[totalRays-1])* stepSize) + radius;
// equally space rays around the center
initPointLocation.x = cos(ofDegToRad(-angleStep)) * initNoisedRadius;
initPointLocation.y = sin(ofDegToRad(-angleStep)) * initNoisedRadius;
ofCurveVertex(initPointLocation);
for (int i=0; i<totalRays; i++)
{
ofPoint pointLocation;
// map mouse position on screen to 0-1 float
// sets 'noised' distance from default sun body radius
float noisedRadius = (ofNoise(noiseSeeds[i])* stepSize) + radius;
// equally space rays around the center
pointLocation.x = cos(ofDegToRad(angleStep*i)) * noisedRadius;
pointLocation.y = sin(ofDegToRad(angleStep*i)) * noisedRadius;
ofCurveVertex(pointLocation);
noiseSeeds[i] += 0.01;
}
ofPoint endPointLocation;
float endNoisedRadius = (ofNoise(noiseSeeds[0])* stepSize) + radius;
// equally space rays around the center
endPointLocation.x = cos(ofDegToRad(angleStep)* 0) * endNoisedRadius;
endPointLocation.y = sin(ofDegToRad(angleStep) * 0) * endNoisedRadius;
ofCurveVertex(endPointLocation);
ofPoint controlPointLocation;
float controlNoisedRadius = (ofNoise(noiseSeeds[1])* stepSize) + radius;
// equally space rays around the center
controlPointLocation.x = cos(ofDegToRad(angleStep)) * controlNoisedRadius;
controlPointLocation.y = sin(ofDegToRad(angleStep)) * controlNoisedRadius;
ofCurveVertex(controlPointLocation);
ofEndShape();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}