-
Notifications
You must be signed in to change notification settings - Fork 91
/
sketch.js
113 lines (79 loc) · 2.55 KB
/
sketch.js
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
////////////////////////////////////////////////////////////////////////////////
// //
// P5.GUI : Slider-Range Example 1 //
// //
////////////////////////////////////////////////////////////////////////////////
// This example shows how to use magic variables to control the slider range
// and step for individual variables.
// Just append 'min', 'max' or 'step' to your variable names...
// seed color and alpha
var seedColor = '#ff00dd';
var bgColor = [0, 0, 0];
// inital number of seeds
var seeds = 500;
// angle (phi)
var angle = 360 * (Math.sqrt(5) - 1) / 2;
// radius of the seed
var radius = 3;
// scale
var zoom = 15;
// seed opacity
var opacity = 150;
////////////////////////////////////////////////////////////////////////////////
// This is where the magic happens ...
// set slider range with magic variables
var seedsMin = 1;
var seedsMax = 2000;
// set angle range and step with magic variables
var angleMax = 360;
var angleStep = 0.1;
// set radius range and step with magic variables
var radiusMin = 0.5;
var radiusMax = 5;
var radiusStep = 0.1;
// set step range with magic variables
var zoomMax = 50;
var zoomStep = 0.1;
// set opacity range with magic variables
var opacityMax = 255;
////////////////////////////////////////////////////////////////////////////////
// the gui object
var gui;
function setup() {
// all angles in degrees (0 .. 360)
angleMode(DEGREES);
// create a canvas that fills the window
createCanvas(windowWidth, windowHeight);
// create the GUI
gui = createGui('slider-range-1');
gui.addGlobals('seeds', 'angle', 'zoom', 'radius', 'seedColor', 'opacity', 'bgColor');
// only call draw when then gui is changed
noLoop();
}
function draw() {
// hello darkness my old friend
background(bgColor);
// let the seeds be filleth
var c = color(seedColor);
fill(red(c), green(c), blue(c), opacity);
stroke(0, opacity);
// absolute radius
var r = radius * zoom;
push();
// go to the center of the sunflower
translate(width/2, height/2);
// rotate around the center while going outwards
for(var i = 0; i < seeds; i++) {
push();
rotate(i * angle);
// distance to the center of the sunflower
var d = sqrt(i + 0.5) * zoom;
ellipse(d, 0, r, r);
pop();
}
pop();
}
// dynamically adjust the canvas to the window
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}