Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Number System and Arithmetic
  • Algebra
  • Set Theory
  • Probability
  • Statistics
  • Geometry
  • Calculus
  • Logarithms
  • Mensuration
  • Matrices
  • Trigonometry
  • Mathematics
Open In App
Next Article:
Introduction to Processing | Java
Next article icon

Creative Programming In Processing | Set 2 (Lorenz Attractor)

Last Updated : 28 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
Creative Programming In Processing | Set 1 (Random Walker)

The Lorenz system is a system of ordinary differential equations first studied by Edward Norton Lorenz, an American mathematician and meteorologist around 1963. It is notable for having chaotic solutions for certain parameter values and initial conditions. It was derived from a simplified model of convection in the Earth’s atmosphere. It also arises naturally in models of lasers and dynamos. The Lorenz attractor is a set of chaotic solutions of the Lorenz system which, when plotted, resemble a butterfly or figure eight. The following image appeared in the Nature Journal on 31 August 2000, pp 949 as part of an article titled The Lorenz Attractor Exists, written by Ian Stewart.


The Lorenz attractor system is most commonly expressed as 3 coupled non-linear differential equations-

  • [Tex]dx / dt = a (y – x)[/Tex]
  • [Tex]dy / dt = x (b – z) – y[/Tex]
  • [Tex]dz / dt = xy – c z[/Tex]


In the above set of equations, ‘a’ is sometimes known as the Prandtl number and ‘b’ the Rayleigh number. One commonly used set of constants is a = 10, b = 28, c = 8 / 3. Another is a = 28, b = 46.92, c = 4.

Sample implementation of the differential equations in Java:

Java
int i = 0; double x0, y0, z0, x1, y1, z1; double h = 0.01, a = 10.0, b = 28.0, c = 8.0 / 3.0;  x0 = 0.1; y0 = 0; z0 = 0;  for (i = 0; i < N; i++) {       x1 = x0 + h * a * (y0 - x0);     y1 = y0 + h * (x0 * (b - z0) - y0);     z1 = z0 + h * (x0 * y0 - c * z0);     x0 = x1;     y0 = y1;     z0 = z1;        // Printing the coordinates     if (i > 100)         System.out.println(i + " " + x0 + " " + y0 + " " + z0); } 

We will try to implement the above logic in Processing Java visually. Since we will be plotting the points in 3d, we need use a 3d renderer. We will be using the OPENGL renderer in the following implementation but a P3D renderer can also be used. We also need to use an external Processing library called PeasyCam which helps us to create an interactive camera object for 3d environment workflow. PeasyCam can be downloaded using the Processing IDE from tools ->Add Tool -> Libraries.

We will also be using the following functions to represent the Lorenz Attractor structure-

  • beginShape() – begins recording vertices for a shape.
  • endShape() – stops recording vertices for a shape.
  • vertex() – this function is used to specify the vertex coordinates for points, lines, triangles, quads, and polygons. It is used exclusively within the beginShape() and endShape() functions.


Implementation of Lorenz Attractor in Processing java:-

Java
/* FINAL SKETCH FOR LORENZ ATTRACTOR */  import peasy.*; // Importing peasy package  // Initialization float x = 0.01, y = 0, z = 0; float a = 10, b = 28, c = 8.0 / 3.0;  // ArrayList of PVector objects to store // the position vectors of the points to be plotted. ArrayList<PVector> points = new ArrayList<PVector>(); PeasyCam cam; // Declaring PeasyCam object  void setup() {     // Creating the output window     // and setting up the OPENGL renderer     size(800, 600, OPENGL);      // Initializing the cam object     cam = new PeasyCam(this, 500); }  void draw() {     background(0);      // Implementation of the differential equations     float dt = 0.01;     float dx = (a * (y - x)) * dt;     float dy = (x * (b - z) - y) * dt;     float dz = (x * y - c * z) * dt;     x += dx;     y += dy;     z += dz;      // Adding the position vectors to points ArrayList     points.add(new PVector(x, y, z));     translate(0, 0, -80);     scale(5);     stroke(255);     noFill();      // Beginning plotting of points     beginShape();     for (PVector v : points) {         // Adding random color to the structure in each frame         stroke(random(0, 255), random(0, 255), random(0, 255));         vertex(v.x, v.y, v.z); // plotting the vertices     }     endShape(); // Drawing ends } 

Output:-

Source Materials –

  • The Coding Train Coding Challenges by Daniel Shiffman.
  • The Lorenz Attractor in 3D by Paul Bourke.


Next Article
Introduction to Processing | Java
https://media.geeksforgeeks.org/auth/avatar.png
GeeksforGeeks
Improve
Article Tags :
  • Java
  • Mathematics
  • java-math
  • Maths
Practice Tags :
  • Java

Similar Reads

  • Introduction to Processing | Java
    Processing is an open-source programming language and development environment that is built on top of the Java programming language. It is specifically designed for artists, designers, and other creative professionals who want to create interactive graphics, animations, and other visual applications
    6 min read
  • How to Set Up Processing for Android?
    Introduction:Processing is a free graphical library and Integrated Development Environment (IDE) built for the electronic arts and visual design communities. It is one of the most powerful libraries available today for creating visual algorithmic artworks, both 2D and 3D. It is open-source, based on
    3 min read
  • Fractals: Definition and How to Create Them?
    Fractals represent complex mathematical objects that have been extensively studied as well as depicted by mathematicians, artists, and scientists because of their repetitive features. Referring to the shapes that are different from the simple geometric forms, fractals possess one unique feature that
    6 min read
  • How to Create Gradient Animations Like Instagram using Spark Library in Android?
    In this article, we are going to implement Spark Library. Here we going to show an animation that will change the colors of the activity linearly. This feature can be simply used to show an animation and when a user loads an activity Or can also be used to show animation on the Splash Screen. Let's
    2 min read
  • Applications of Eigenvalues and Eigenvectors
    Eigenvalues and eigenvectors play a crucial role in a wide range of applications across engineering and science. Fields like control theory, vibration analysis, electric circuits, advanced dynamics, and quantum mechanics frequently rely on these concepts. One key application involves transforming ma
    7 min read
  • State Transition Matrix and Diagram
    State Transition Matrices and Diagrams are powerful tools used in the various disciplines including the computer science, engineering and control systems to model the behavior of the systems that transition between the different states. Understanding these concepts is crucial for the students and pr
    9 min read
  • JavaFX | LinearGradient Class
    LinearGradient class is a part of JavaFX. LinearGradient class fills a shape with a linear color gradient pattern. A user may specify more than one LinearGradient pattern and the system will provide interpolation between the colors. Constructors of the class: LinearGradient(double sX, double sY, dou
    4 min read
  • Activation Functions
    To put it in simple terms, an artificial neuron calculates the 'weighted sum' of its inputs and adds a bias, as shown in the figure below by the net input. Mathematically, [Tex]\text{Net Input} =\sum \text{(Weight} \times \text{Input)+Bias}[/Tex] Now the value of net input can be any anything from -
    3 min read
  • Introduction to Chaos Theory
    Chаos theory is а brаոch of mаthemаtics thаt studies complex systems whose behavіor аppeаrs random аոd unpredictable, yet is governed by underlyіոg pаtterոs аոd determіոіstіc equаtіоոs. It explores the dyոаmіcs of lіոeаr systems thаt аre highly seոsіtіve to іոіtіаl cоոdіtіоոs, leаdіոg to dіvergeոt о
    7 min read
  • Real-Life Applications of Fractals
    Applications of Fractals: Fractals are complex geometric shapes that exhibit self-similarity at different scales. They are generated by repeating a simple process iteratively resulting in intricate and fascinating patterns. The Fractals have found numerous applications across various fields due to t
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences