Contact Form

Name

Email *

Message *

Cari Blog Ini

Processing Sketch Continuing Draw

Processing: Drawing Continuous Lines

Introduction

Processing is a popular programming language and environment specifically designed for visual artists, designers, and artists. It provides a simple and intuitive way to create visual sketches and animations. One of the fundamental functions in Processing is the line() function, which allows you to draw a line between two points on the screen. In this article, we'll take a closer look at the line() function and how it can be used to create continuous lines.

The line() Function

The line() function in Processing takes four parameters:

  • x1: the x-coordinate of the starting point
  • y1: the y-coordinate of the starting point
  • x2: the x-coordinate of the ending point
  • y2: the y-coordinate of the ending point

The line() function draws a straight line from the starting point (x1, y1) to the ending point (x2, y2). The line is drawn with the current stroke color and stroke weight. For example, the following code draws a black line from the point (10, 10) to the point (200, 200):

 stroke(0); // Set the stroke color to black line(10, 10, 200, 200); // Draw a line from (10, 10) to (200, 200) 

Continuous Lines

To draw a continuous line, you can use the line() function inside a draw() function. The draw() function is called repeatedly by Processing, so the code inside the function is executed over and over again. This allows you to create dynamic animations and drawings. For example, the following code draws a continuous line that follows the mouse cursor:

 void draw() {   line(mouseX, mouseY, pmouseX, pmouseY); // Draw a line from the previous mouse position to the current mouse position } 

In this code, the mouseX and mouseY variables store the current position of the mouse cursor, and the pmouseX and pmouseY variables store the previous position of the mouse cursor. The line() function draws a line from the previous mouse position to the current mouse position, creating the effect of a continuous line.

Conclusion

The line() function is a powerful tool that can be used to create a variety of different lines and shapes. By using the line() function inside a draw() function, you can create continuous lines that follow the mouse cursor or other dynamic inputs. This allows you to create interactive and engaging visual experiences with Processing.


Comments