There is a drawn graph, it marks the boundaries of a certain area: Schedule
I thought that it was possible to make lines parallel to the y axis with a small step, and somehow rotate them by selecting an arbitrary area by points, but even then the whole area will turn and you will not understand what.
What better way to do this? Looking exactly sloping lines.
In the paint it would look like this:
enter image description here
(color / style is not important, then I'll change it). Thank you in advance.

    1 answer 1

    You can create a java.awt.geom.Area object containing the desired area, and then paint it using the striped java.awt.Paint implementation. You can also limit this area to the drawing area and shade it manually.

     import java.awt.*; import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.geom.*; import java.util.function.DoubleUnaryOperator; import javax.swing.*; public class DiagonalPaint { static void initUi() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); DoubleUnaryOperator function = x -> -0.5 * (x-3)*(x-3) + 2; frame.add( new JPanel() { static final double SCALE = 40; static final double STEP = 0.01; static final double LEFT = 0; static final double RIGHT = 10; @Override public void paintComponent( Graphics g ) { Graphics2D g2d = (Graphics2D)g.create(); g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); g2d.setColor( Color.WHITE ); g2d.fillRect( 0, 0, getWidth(), getHeight() ); // Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΠΏΠ΅Ρ€Π΅ΡΡ‡ΠΈΡ‚Ρ‹Π²Π°Ρ‚ΡŒ всС ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ Ρ€Π°Π·, я ΡΠΌΠ΅Ρ‰Π°ΡŽ ΠΈ ΠΏΠ΅Ρ€Π΅Π²ΠΎΡ€Π°Ρ‡ΠΈΠ²Π°ΡŽ // вСсь экран (надписи Ρ‚ΠΎΠΆΠ΅ пСрСвСрнутся) AffineTransform transform = AffineTransform.getTranslateInstance( getWidth() / 2, getHeight() / 2 ); transform.concatenate( AffineTransform.getScaleInstance( 1, -1 ) ); g2d.setTransform( transform ); // оси g2d.setColor( Color.BLACK ); g2d.drawLine( -1000, 0, 1000, 0 ); for ( int i = -10; i < 10; i += 1 ) { g2d.drawLine( (int)(i * SCALE), -5, (int)(i * SCALE), 5 ); } g2d.drawLine( 0, -1000, 0, 1000 ); for ( int i = -10; i < 10; i += 1 ) { g2d.drawLine( -5, (int)(i * SCALE), 5, (int)(i * SCALE) ); } // создаСтся Area с Π·Π°ΠΊΡ€Π°ΡˆΠΈΠ²Π°Π΅ΠΌΠΎΠΉ ΠΎΠ±Π»Π°ΡΡ‚ΡŒΡŽ Area area = createGraphArea( function, 1.5, 3 ); area.transform( AffineTransform.getScaleInstance( SCALE, SCALE ) ); // ΠΌΠ°ΡΡˆΡ‚Π°Π±ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ // Π»ΠΈΠ½Π΅ΠΉΠ½Ρ‹ΠΉ Π³Ρ€Π°Π΄ΠΈΠ΅Π½Ρ‚ Π² качСствС Π·Π°Π»ΠΈΠ²ΠΊΠΈ g2d.setPaint( new LinearGradientPaint( 0, 0, // ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ Π½Π°Ρ‡Π°Π»Π° ΠΈ ΠΊΠΎΠ½Ρ†Π° Π»ΠΈΠ½ΠΈΠΈ 5, 5, // ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΡΡŽΡ‚ Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΡˆΠΈΡ€ΠΈΠ½Ρƒ шага Π³Ρ€Π°Π΄ΠΈΠ΅Π½Ρ‚Π° new float[] {0.4999f, 0.5000f, 0.5001f, 1f}, // Ρ‚ΠΎΡ‡ΠΊΠΈ для Ρ†Π²Π΅Ρ‚ΠΎΠ² // ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ ΠΌΠ΅ΠΆΠ΄Ρƒ ΠΎΡ€Π°Π½ΠΆΠ΅Π²Ρ‹ΠΌ ΠΈ Π±Π΅Π»Ρ‹ΠΌ ΠΎΡ‡Π΅Π½ΡŒ ΠΌΠ°Π», поэтому Π±ΡƒΠ΄Π΅Ρ‚ ΠΊΠ°Π·Π°Ρ‚ΡŒΡΡ Ρ€Π΅Π·ΠΊΠΈΠΌ new Color[] {Color.ORANGE, Color.ORANGE, Color.WHITE, Color.WHITE}, CycleMethod.REFLECT ) ); g2d.fill( area ); // ΠΠ»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ - ΡƒΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ ΠΎΠ±Ρ€Π΅Π·ΠΊΡƒ ΠΏΠΎ Ρ„ΠΎΡ€ΠΌΠ΅ области // ΠΈ Π·Π°Ρ€ΠΈΡΠΎΠ²Π°Ρ‚ΡŒ линиями Π²Ρ€ΡƒΡ‡Π½ΡƒΡŽ /* Shape oldClip = g2d.getClip(); g2d.setClip( area ); Rectangle bounds = area.getBounds(); g2d.setPaint( Color.ORANGE ); for ( int y = bounds.y - bounds.width; y < bounds.y + bounds.height; y += 10) { g2d.drawLine( bounds.x, y, bounds.x + bounds.width, y + bounds.width ); } g2d.setClip( oldClip ); /**/ // ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΎΠ±Ρ€ΠΈΡΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ±Π»Π°ΡΡ‚ΡŒ ΠΏΡƒΠ½ΠΊΡ‚ΠΈΡ€ΠΎΠΌ /* g2d.setPaint( Color.ORANGE ); g2d.setStroke( new BasicStroke( 1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] { 10f }, 0f ) ); g2d.draw( area ); /**/ // отрисовка самого Π³Ρ€Π°Ρ„ΠΈΠΊΠ° Path2D line = createGraphPath( function, LEFT, RIGHT ); line.transform( AffineTransform.getScaleInstance( SCALE, SCALE ) ); g2d.setPaint( Color.BLACK ); g2d.setStroke( new BasicStroke( 2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL ) ); g2d.draw( line ); g2d.dispose(); } private Path2D.Double createGraphPath( DoubleUnaryOperator function, double left, double right ) { Path2D.Double line = new Path2D.Double(); line.moveTo( left, function.applyAsDouble( left ) ); for ( double x = left + STEP; x < right; x += STEP ) { line.lineTo( x, function.applyAsDouble( x ) ); } line.lineTo( right, function.applyAsDouble( right ) ); return line; } // созданиС области ΠΏΠΎΠ΄ Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠΌ private Area createGraphArea( DoubleUnaryOperator function, double left, double right ) { Path2D.Double path = createGraphPath( function, left, right ); Rectangle2D bounds = path.getBounds2D(); path.lineTo( bounds.getMaxX(), 0 ); path.lineTo( bounds.getMinX(), 0 ); path.closePath(); return new Area( path ); } }); frame.setSize( 800, 600 ); frame.setVisible( true ); } public static void main(String[] args) { SwingUtilities.invokeLater( DiagonalPaint::initUi ); } } 

    result

    Instead of LinearGradientPaint you can use TexturePaint .