-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspaghetticode.js
More file actions
135 lines (118 loc) · 3.07 KB
/
spaghetticode.js
File metadata and controls
135 lines (118 loc) · 3.07 KB
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
//Spaghetti
var v = [], w = [], buf, canvas, ctx;
function setup(){
createCanvas(window.innerWidth,window.innerHeight);
pg = createGraphics(window.innerWidth,window.innerHeight);
pg.noStroke();
pg.rect(0, 0, window.innerWidth,window.innerHeight)
//TOP
for (var n = 0; n < 15; n++) {
var prtr = window.innerWidth*n/16;
v.push(new Vine(prtr+window.innerWidth/16, 0, Math.PI/2));
}
//BOTTOM
for (var n = 0; n < 15; n++) {
var prtr = window.innerWidth*n/16;
v.push(new Vine(prtr+window.innerWidth/11, window.innerHeight, -Math.PI/2));
}
//LEFT
for (var m = 0; m < 10; m++) {
var prtr = window.innerHeight*m/11;
v.push(new Vine(0, prtr+window.innerHeight/11, 0));
}
//RIGHT
for (var m = 0; m < 10; m++) {
var prtr = window.innerHeight*m/11;
v.push(new Vine(window.innerWidth, prtr+window.innerHeight/11, Math.PI));
}
//SAUCE
for (var l = 0; l < 25; l++) {
w.push(new Drop());
}
}
function draw(){
for (var n = 0; n < v.length; n++) {
v[n].move();
v[n].draw();
}
for (var m = 0; m < w.length; m++) {
w[m].move();
w[m].draw();
}
}
function Vine(x, y, initAng){
this.x = x;
this.y = y;
this.rad = 5;
this.ang = initAng;
var count = 0, swap = 0.1, inc = 10, prevx, prevy;
this.move = function(){ //INCREMENTING COORDINATES
if(count++>100)
return;
prevx=this.x;
prevy=this.y;
this.x+=inc*cos(this.ang);
this.y+=inc*sin(this.ang);
this.ang+=swap;
if(this.ang > Math.PI*2){
this.ang%=Math.PI/2;
}
//CHANGE DIRECTION
if (chances(10)) {
swap = -swap;
}
}
this.draw = function(){
if(count>100)
return;
var pangle = this.ang + Math.PI/2;
noStroke();
fill(255, 217, 102);
ellipse(this.x, this.y, this.rad*2, this.rad*2);
quad(prevx+this.rad*cos(pangle), prevy+this.rad*sin(pangle),
prevx-this.rad*cos(pangle), prevy-this.rad*sin(pangle),
this.x-this.rad*cos(pangle), this.y-this.rad*sin(pangle),
this.x+this.rad*cos(pangle), this.y+this.rad*sin(pangle));
pg.fill(255, 217, 102);
pg.ellipse(this.x, this.y, this.rad*2, this.rad*2);
pg.quad(prevx+this.rad*cos(pangle), prevy+this.rad*sin(pangle),
prevx-this.rad*cos(pangle), prevy-this.rad*sin(pangle),
this.x-this.rad*cos(pangle), this.y-this.rad*sin(pangle),
this.x+this.rad*cos(pangle), this.y+this.rad*sin(pangle));
}
function chances(ez){
var n = Math.floor(Math.random()*ez+1);
if(n==1)
return true;
return false;
}
};
function Drop(){
this.x = rnjesus(window.innerWidth*0.75, window.innerWidth*0.05);
this.y = -200;
this.vel = rnjesus(13, 3);
var count2 = 0;
this.move = function(){
if(count2++<100||count2>150)
return;
this.y+=this.vel;
}
this.draw = function(){
if(count2<100||count2>150)
return;
fill(255, 0, 0);
ellipse(this.x+150, this.y+150, 100, 100);
if(count2==150){
image(pg, 0, 0);
var x = new Image();
x.setAttribute("src", "sauce.png");
document.getElementById('imgs').appendChild(x);
x.style.top = this.y + "px";
x.style.left = this.x + "px";
}
}
function rnjesus(boundup, bounddown){
var n = Math.floor(Math.random()*(boundup-bounddown)+bounddown);
return n;
}
};