-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
136 lines (107 loc) · 2.54 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const OBJECT_SIZE = 500
const SIDES = 6
var PALETTE = []
function setup() {
createCanvas(window.innerWidth, window.innerHeight, SVG)
colorMode(HSB, 360, 100, 100)
PALETTE = [
color(330, 90, 90), // pink
color(210, 80, 50), // blue
]
angleMode(DEGREES)
noLoop()
}
function draw() {
background(0,.1);
strokeWeight(1)
noFill()
//testLines()
//outlineShape()
//simpleLines()
//circles()
var picker = random(1)
if (picker > .3) {
outlineShape()
}
picker = random(1)
if (picker > .3) {
simpleLines()
}
picker = random(1)
if (picker > .3){
circles()
}
}
function circles () {
var numShapes = SIDES
var angle = 360 / numShapes
var shapeSize = (OBJECT_SIZE / 2) * .93
var sColor = getRandomFromPalette()
var position = (OBJECT_SIZE / 2) - (shapeSize / 2)
stroke(sColor)
strokeWeight(1)
push()
translate(width/2, height/2)
for (var i = 0; i < numShapes; i++){
ellipse(position, 0, shapeSize, shapeSize)
rotate(angle)
}
pop()
}
function simpleLines () {
var stepsOut = 8
var numSteps = randomSelectTwo ? stepsOut : floor(stepsOut * 1.25)
var step = (OBJECT_SIZE / 2) / numSteps
var start = floor(random(0, numSteps))
var stop = floor(random(start, numSteps+1))
console.log(start)
console.log(stop)
var numShapes = randomSelectTwo() ? SIDES : SIDES * 2 // ternary operator
var sColor = getRandomFromPalette()
var sWeight = randomSelectTwo() ? 1 : 3
var angle = 360 / numShapes
push()
translate(width/2, height/2)
stroke(sColor)
strokeWeight(sWeight)
for (var i = 0; i < numShapes; i++){
line(start * step, 0, stop * step, 0)
rotate(angle)
}
pop()
}
function outlineShape () {
var sColor = getRandomFromPalette()
var sWeight = randomSelectTwo() ? 1 : 3
var hexagonTrue = randomSelectTwo()
stroke(sColor)
strokeWeight(sWeight)
push()
translate(width/2, height/2)
if (hexagonTrue) {
hexagon(0, 0, OBJECT_SIZE/2)
} else {
ellipse(0, 0, OBJECT_SIZE, OBJECT_SIZE)
}
pop()
}
function testLines () {
/* if (randomSelectTwo()) {
numShapes = SIDES
} else {
numShapes = SIDES * 2
} */
var numShapes = randomSelectTwo() ? SIDES : SIDES * 2 // ternary operator
var sColor = getRandomFromPalette()
push()
translate(width/2, height/2)
stroke(PALETTE[1])
ellipse(0, 0, OBJECT_SIZE, OBJECT_SIZE)
stroke(sColor)
var angle = 360 / numShapes
for (var i = 0; i < numShapes; i++){
line(0,0, OBJECT_SIZE/2, 0)
rotate(angle)
}
pop()
}