-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fully_Connected_Graph.pde
141 lines (123 loc) · 4.34 KB
/
Fully_Connected_Graph.pde
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
130
131
132
133
134
135
136
137
138
139
140
141
/********************** FULLY CONNECTED GRAPH VIEWER **********************/
/*
* Copyright (C) 2021 Sean Barton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*
*
*
* This program draws a simple spherical graph of any given number
* of points where each point used to draw the circle is connected
* to every other point in the circle.
*
* The program begins by drawing a circle using only 10 points,
* however the user can increase or decrease the number of points
* used to draw the circle using the up and down arrows on the
* keyboard. Each time an arrow is pressed, the graph is
* automatically redrawn with the updated number of points.
*
* The program also provides some modularity in the code. In the
* CHANGE section below, the values of each variable can be
* changed to update where and how the graph is drawn. The
* DON'T CHANGE section underneath is also documented to explain how
* the code is working, but none of the code needs to be changed
* to apply any asthetic difference to the graph.
*
* Lastly, if you wish to change the size of the program screen,
* note that you must also change the values for the size()
* function within the setup() function below in the following
* manner:
*
* void setup() {
* size(NEW_X, NEW_Y);
* ...
*
*
*
*
*
* Last Updated: 11/3/21
*/
/********************************* CHANGE! ********************************/
/* VARIABLES DEFINING SIZE AND LOCATION ON THE SCREEN
* ARE MEASURED IN PIXELS.
* VARIABLES DEFINING COLOR ARE EITHER HEXADECIMAL
* COLOR VALUES OR A GRAYSCALE VALUE BETWEEN 0 AND 255.
*/
// Adjusts the size of the game screen
// (Must also change size() to the same values)
final int SIZE_X = 1500;
final int SIZE_Y = 1000;
// Adjusts the BackGround color of the game screen,
// as well as the Line Color and Line Weight of
// the graph. You can use the color selector,
// (Tools -> Color Selector) to easily choose a color.
final int BG = #191A1C;
final int LC = #447E56;
final int LW = 1; // Measured in pixels
// Adjusts the Radius and origin of the graph
final int R = 400;
final int X = 750;
final int Y = 500;
// Adjusts the number of points used to draw the graph
int numPoints = 10;
/**************************************************************************/
/****************************** DON'T CHANGE! *****************************/
boolean update = true;
// Clears the screen and draws a new fully connected
// spherical graph using the number of points defined
// by the global variable numPoints.
void drawShape() {
background(BG);
for(int i = 0; i < numPoints; ++i) {
float x1 = (cos(radians((360F/numPoints) * i)) * R) + X;
float y1 = (sin(radians((360F/numPoints) * i)) * R) + Y;
for(int j = 0; j < numPoints; ++j) {
float x2 = (cos(radians((360F/numPoints) * j)) * R) + X;
float y2 = (sin(radians((360F/numPoints) * j)) * R) + Y;
line(x1, y1, x2, y2);
}
}
update = false;
}
// Initializes the screen with a size, background color,
// and line color/weight
void setup() {
size(1500, 1000);
background(BG);
stroke(LC);
strokeWeight(LW);
}
// Called repeatedly (24 times per second). Draws the scene
void draw() {
if(update) { drawShape(); }
}
// Interrupt for any key being pressed.
void keyPressed() {
// Adds a new point and redraws the graph when up arrow pressed
if(keyCode == UP) {
numPoints++;
update = true;
}
// Removes as point and redraws the graph when down arrow pressed
else if(keyCode == DOWN) {
if(numPoints > 1) {
numPoints--;
update = true;
}
}
}
/**************************************************************************/