float MID = 250; ArrayList lines = new ArrayList(); void setup(){ size(500,500); stroke(255); strokeWeight(2); } void draw(){ background(0,0,128); strokeWeight(2); stroke(255); for(Line n : lines){ n.draw(); } stroke(255,0,0); strokeWeight(1); if(mousePressed){ line(startX,startY,mouseX,mouseY); } if(lines.size() == 0){ for(int i = 0; i < 6;i++){ float a =( PI/2) +( PI / 3 * i); line(MID,MID,MID+cos(a)*10,MID+sin(a)*10); } } } void keyPressed(){ if(key == ' ') { reset(); } } void reset(){ lines = new ArrayList(); } float startX, startY; void mouseDragged(){ //mousePressed(); } void mousePressed(){ startX = mouseX; startY = mouseY; } void mouseReleased(){ float angStart = atan2(startY-MID,startX-MID); float disStart = dist(MID,MID,startX,startY); Point pStart = getPointFromCenter(angStart,disStart); float angEnd = atan2(mouseY-MID,mouseX-MID); float disEnd = dist(MID,MID,mouseX,mouseY); Point pEnd = getPointFromCenter(angEnd,disEnd); for(int i = 0; i < 4; i++){ float angStartRot1 = angStart + (i) * (PI/3); float angEndRot1 = angEnd + (i) * (PI/3); float angStartRot2 = angStart - (i) * (PI/3); float angEndRot2 = angEnd - (i) * (PI/3); Point pStart1 = getPointFromCenter(angStartRot1,disStart); Point pEnd1 = getPointFromCenter(angEndRot1,disEnd); lines.add(new Line(pStart1.x,pStart1.y,pEnd1.x,pEnd1.y)); Point pStart2 = getPointFromCenter(angStartRot2,disStart); Point pEnd2 = getPointFromCenter(angEndRot2,disEnd); lines.add(new Line(pStart2.x,pStart2.y,pEnd2.x,pEnd2.y)); } lines.add(new Line(pStart.x,pStart.y,pEnd.x,pEnd.y)); } class Line{ float x1,y1,x2,y2; Line(float px1,float py1,float px2,float py2){ x1 = px1; y1 = py1; x2 = px2; y2 = py2; } void draw(){ stroke(255); line(x1,y1,x2,y2); float xMid = (x1+x2)/2; float yMid = (y1+y2)/2; float ang = atan2(y1-yMid,x1-xMid); float dis = dist(x1,y1,x2,y2) / 32; ang += PI/2; float xc1 = xMid+(dis*cos(ang)); float yc1 = yMid+(dis*sin(ang)); ang += PI; float xc2 = xMid+(dis*cos(ang)); float yc2 = yMid+(dis*sin(ang)); triangle(x1,y1,x2,y2,xc1,yc1); triangle(x1,y1,x2,y2,xc2,yc2); } } Point getPointFromCenter(float ang, float dis){ return new Point(MID+cos(ang)*dis,MID+sin(ang)*dis); } class Point{ float x, y; Point(float x, float y){ this.x = x; this.y = y; } }