!7 sclass CirclesAndLines { new L circles; new L lines; Circle addCircle(S imageID, double x, double y) { ret addAndReturn(circles, nu(Circle, +x, +y, img := loadImage2(imageID))); } Line addLine(Circle a, Circle b) { ret addAndReturn(lines, nu(Line, +a, +b)); } BufferedImage makeImage(int w, int h) { BufferedImage bg = renderTiledBackground(#1007195, w, h); for (Line l : lines) drawThoughtLine(bg, l.a.img, iround(l.a.x*w), iround(l.a.y*h), l.b.img, iround(l.b.x*w), iround(l.b.y*h), Color.white); for (Circle c : circles) drawThoughtCircle(bg, c.img, iround(c.x*w), iround(c.y*h)); ret bg; } } sclass Circle { BufferedImage img; double x, y; Pt pt(ImageSurface is) { ret new Pt(iround(x*is.getWidth()), iround(y*is.getHeight())); } bool contains(ImageSurface is, Pt p) { ret pointDistance(p, pt(is)) <= thoughtCircleSize(img)/2+1; } } sclass Line { Circle a, b; } p-pretty /* although that's debatable given the detailed person */ { final new CirclesAndLines cal; Circle a = cal.addCircle(#1007291, 1/3.0, 0.5); Circle b = cal.addCircle(#1007292, 2/3.0, 0.5); cal.addLine(a, b); fO makeImg = func(int w, int h) { cal.makeImage(w, h) }; final Canvas canvas = jcanvas(makeImg); disableImageSurfaceSelector(canvas); new CircleDragger(canvas, r { updateCanvas(canvas, makeImg) }, cal.circles); showFrame(canvas); } sclass CircleDragger extends MouseAdapter { ImageSurface is; L circles; O update; int dx, dy; Circle circle; *(ImageSurface *is, O *update, L *circles) { if (containsInstance(is.tools, CircleDragger)) ret; is.tools.add(this); is.addMouseListener(this); is.addMouseMotionListener(this); } public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { Pt p = is.pointFromEvent(e); circle = findCircle(p); if (circle != null) { dx = p.x-iround(circle.x*is.getWidth()); dy = p.y-iround(circle.y*is.getHeight()); } } } public void mouseDragged(MouseEvent e) { if (circle != null) { Pt p = is.pointFromEvent(e); circle.x = (p.x-dx)/(double) is.getWidth(); circle.y = (p.y-dy)/(double) is.getHeight(); callF(update); } } public void mouseReleased(MouseEvent e) { mouseDragged(e); circle = null; } Circle findCircle(Pt p) { new Lowest best; for (Circle c : circles) if (c.contains(is, p)) best.put(c, pointDistance(p, c.pt(is))); ret best.get(); } }