-
Notifications
You must be signed in to change notification settings - Fork 5
/
Draw.js
125 lines (107 loc) · 2.56 KB
/
Draw.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
function Draw(){
this.Dstyle = function(){
if(obj.fillShape){
gr.fill(obj.color);
gr.noStroke();
fill(obj.color);
noStroke();
}
else{
gr.noFill();
gr.stroke(obj.color);
gr.strokeWeight(obj.sizePaint);
noFill();
stroke(obj.color);
strokeWeight(obj.sizePaint);
}
}
this.Dfree = function(){
gr.strokeWeight(obj.sizePaint);
gr.stroke(obj.color);
gr.line(pmouseX, pmouseY, mouseX, mouseY);
}
this.Dpoint = function(x, y){
gr.strokeWeight(obj.sizePaint);
gr.stroke(obj.color);
gr.point(x, y);
}
this.DlineF = function(){
gr.strokeWeight(obj.sizePaint);
gr.stroke(obj.color);
gr.line(pPosmouseX, pPosmouseY, mouseX, mouseY);
}
this.Dline = function(x1, y1, x2, y2, drawToimage){
gr.strokeWeight(obj.sizePaint);
gr.stroke(obj.color);
stroke(obj.color);
strokeWeight(obj.sizePaint);
if(drawToimage){
gr.line(x1, y1, x2, y2);
}else{
line(x1, y1, x2, y2);
}
}
this.Dcircle = function(x1, y1, x2, y2, drawToimage){
this.center = createVector((x2 + x1)*0.5, (y1 + y2)*0.5);
this.r1 = abs(x1 - x2);
this.r2 = abs(y1 - y2);
this.Dstyle();
if(drawToimage){
gr.ellipse(this.center.x, this.center.y, this.r1, this.r2);
}
else {
ellipse(this.center.x, this.center.y, this.r1, this.r2);
}
}
this.Drect = function(x1, y1, x2, y2, drawToimage){
this.x1 = (x1 < x2) ? x1:x2;
this.y1 = (y1 < y2) ? y1:y2;
this.x2 = (x1 > x2) ? x1:x2;
this.y2 = (y1 > y2) ? y1:y2;
this.Dstyle();
if(drawToimage){
gr.rect(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1);
}
else{
rect(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1);
}
}
this.Drand = function(type, num){
for(var i = 0; i < num; i++){
obj.color = [random(255), random(255), random(255)];
switch(type){
case 'circle':
var x1 = random(w);
var y1 = random(h);
var rand = random(200);
var x2 = x1 + obj.sizePaint * 2;
var y2 = y1 + obj.sizePaint * 2;
this.Dcircle(x1, y1, x2, y2, true);
break;
case 'line':
var x1 = random(w);
var y1 = random(h);
var x2 = random(w);
var y2 = random(h);
this.Dline(x1, y1, x2, y2, true);
break;
case 'rect':
var x1 = random(w*0.5);
var y1 = random(h*0.5);
var x2 = x1 + random(w*0.5);
var y2 = y1 + random(h*0.5);
this.Drect(x1, y1, x2, y2, true);
break;
case 'point':
this.Dpoint(random(w), random(h));
break;
case 'all':
this.Drand('circle', 1);
this.Drand('point', 1);
this.Drand('line', 1);
this.Drand('rect', 1);
break;
}
}
}
}