d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Doing Intro To Programming At Uni > Using Processing/ Basic Form Of Java
Add Reply New Topic New Poll
Member
Posts: 9,710
Joined: May 11 2008
Gold: 550.69
Mar 11 2013 05:23pm
using a simplified version of java to write a code to make black balls turn red and connected by a line, which is all reset by keypress

float x = 150;
float y = 200;
int red = 0;

void setup() {
size(300, 400);
background(80, 255, 80);
fill(255, 0, 0);
ellipse(150, 200, 50, 50);
}

void mousePressed() {
noLoop();
x = ((x + mouseX) /2);
y = ((y + mouseY) /2);
loop();
}
void draw() {

if (mousePressed == true) {
red = 0;
}
red = red + 10;
fill(red, 0, 0);
ellipse(x, y, 50, 50);
}

please someone help. lol. i get the feeling i have made it needlessly complicated but i dont know how to simplify it, also working on the connecting lines and reset now but my format makes it hard to include the information.
Member
Posts: 9,710
Joined: May 11 2008
Gold: 550.69
Mar 11 2013 06:50pm
made some progress, should be easier to read now

final int DIA = 50;
float circleX = 150;
float circleY = 200;
float lineX, lineY;
int RED = 0;

void setup() {
size(300, 400);
background(80, 255, 80);
fill(255, 0, 0);
ellipse(150, 200, DIA, DIA); // DIA is constant
strokeWeight(1);
}

void draw() {
if (mousePressed == true) // pressing mouse resets colour to black
RED = 0;
RED = RED + 10;
strokeWeight(2);
line(circleX, circleY, lineX, lineY);
strokeWeight(1);
fill(RED, 0, 0); // (0, 0, 0) approaches (255, 0, 0)
ellipse(circleX, circleY, DIA, DIA);
}

void mousePressed() {
circleX = (circleX + mouseX) /2; // midpoint of circleX and mouseX
circleY = (circleY + mouseY) /2; // midpoint of circleY and mouseY
}

i need to draw a line from circleX/Y to the previous circleX/Y

but i have no idea what i need to do in order to find the coordinates of the previous circle

i need to draw the line before the circle so the final circle appear on top of the line
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 11 2013 07:40pm
if you know there are exactly two circles, just add more variables. eg circle2x and circle2y

if there are more than two, create an array. every time you draw a circle, queue up your points
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll