i hate arrays. attention to mister blindfishy
in
Programming Questions
•
2 years ago
hey blindfish i noticed how you have been helping a lot of beginners with their work. i would post a forum but i need help fast bc i have so much stuff to do to this code. This a assignment where i am going to use x[] and y [] to integrate it into minim to create sound. with my code every time i press the different stroke weight to change it in draw. the icon is affected by the strokes so im trying to make a array with strokes [] but it isnt working:
int points = 5000;
int [] x;
int [] y;
int [] drawnC;
int [] strokes;
int index = 0;
color drawing = color (0,0,0);
color[] c = new color [10];
void setup() {
size(600, 600);
x = new int[points];
y = new int[points];
drawnC = new int[points];
strokes = new int[points];
c [0] = color (0, 0, 0);
c [1] = color (255, 0, 0);
c [2] = color (255, 125, 0);
c [3] = color (255, 255, 0);
c [4] = color (0, 255, 0);
c [5] = color (0, 0, 255);
c [6] = color (142, 47, 180);
c [7] = color (255, 0, 222);
c [8] = color (125, 125, 125);
c [9] = color (255, 255, 255);
}
void draw() {
background(255);
makeToolbox();
makeLines();
}
void makeToolbox() {
// for color icons
int i = 0;
int s = 20;
stroke (0);
for (int y = 0; y < 405 ; y += 30) {
if (i <= 9) {
// draw boxes
fill (c[i]);
i = i + 1;
rect (0, y, 30, 30);
}
else {
// draw stroke size circle
fill(255);
rect (0, y, 30, 30);
fill (drawing);
ellipse (15, y + 15, s, s);
s = s - 5;
}
}
}
void makeLines() {
strokeWeight(1);
stroke(drawing);
if ( mousePressed == true ) {
if ( mouseX > 30 || mouseY > 435) {
x[index] = mouseX;
y[index] = mouseY;
drawnC[index] = drawing;
strokes[index] = drawing;
index = index + 1;
if ( index >= points ) {
index = 0;
}
}
}
for (int i = 1; i < index; i = i + 1 ) {
stroke(drawnC[i]);
stroke(drawnC[i]);
line(x[i-1], y[i-1], x[i], y[i]);
}
}
void mouseClicked() {
println(mouseX + " " + mouseY);
if(mouseX < 30 && mouseY < 285) {
int colorIndex = int( mouseY/30 );
drawing = c[colorIndex];
}
if(mouseX > 5 && mouseX < 25 && mouseY > 300 && mouseY < 330 ) {
strokeWeight (20);
}
if(mouseX > 5 && mouseX < 25 && mouseY > 330 && mouseY < 360 ) {
strokeWeight (14);
}
if(mouseX > 5 && mouseX < 25 && mouseY > 360 && mouseY < 390 ) {
strokeWeight (7);
}
if(mouseX > 5 && mouseX < 25 && mouseY > 390 && mouseY < 420 ) {
strokeWeight (1);
}
}
1
