Java Fractal Explorer [5/8]

WilliamFiset · Intermediate ·⚡ Algorithms & Data Structures ·11y ago
Git video snapshots: https://github.com/william-fiset/FractalExplorer/commits/master =============================================================================== Developer tools I used in the creation/testing of the content in these videos: 1) Sublime text, my favorite lightweight code editor (https://www.sublimetext.com). NOTE: I'm often asked about the color scheme I use, find it here: https://github.com/williamfiset/dotfiles/tree/master/sublime 2) Kite, a free AI-powered coding assistant that provides smart code completions while typing: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=williamfiset&utm_content=description-only ===============================================================================

What You'll Learn

The video demonstrates how to display a fractal on the screen using Java, introducing variables to track the fractal's position and depth, and creating methods to update the display and transform pixel coordinates into complex plane points.

Full Transcript

in this video we're actually going to display the fractal on the screen but before we can do that we need a few more variables and a few more methods so let's get going so we are going to need some way to track where we are in the fractal and at what depth we are in the fractal so let's create create a default Zoom which is going to be 100% and we're also going to want to have a default top left Exposition and we're going to set that to be3 and we're also going to want a default top left y position along with that we're also going to want zoom factor which is going to be the default zoom and you can almost guess what's coming up next to top left X is going to be default top left X and top left Y is going to be default top left y so now that we have those variables created let's add one more method right here after add canvas let's make a method called update fractal this is probably going to be one of the most important methods um in our program because it's actually going to update the display so public void update fractal so what update fractal is going to do is it's going to go through every single Pixel on our canvas and change its color so to do that it's going to need to Loop through the canvas so let's start looping through all the pixels so while X is less than width x++ for y While y is less than the height y ++ so with X and Y we can get uh a single color on on our canvas but for every pixel we're going to want to transform the current X and Y positions on our canvas to X and Y positions in their complex plane because remember we want to grab that complex Point C and that complex Point C is going to be parameter and argument for compute iterations right here so I'm going to say C of R is going to be equal to get X position for x and C of I is going to be get y position for y um the reason C of R is associated with X is because the real values are on the X AIS and the imaginary values are on the Y AIS so let's make these two methods right now so private double get expose what this is going to do is going to transform the x coordinate into uh a point on our or rather a value on our complex plane so that's going to depend on two things it's going to depend on the resume factor and where top left X currently is I'm just going to give it to you it's Zoom Factor plus top left X and nearly the same thing for the Y just make sure you change all these X's to y's except one small detail if you recall the y axis is flipped so we need to put a negative sign instead of a positive sign and this is going these two methods together are going to to get our C of R and our C ofi and now we want to use those to call compute iterations which is going to return the the number of iterations so uh iteration count compute iterations C of r c ofi and the next thing we need to do is we actually need to create a color based on the number of iterations um so I'm going to create a very rudimentary make color method right now but we'll go more in depth in the next video so let's call this the the pixel color make color it's going to take the number of iterations we did and the last thing we need to do is say fractal image. set RGB at XY so at the pixel we're currently on to be that new pixel color oh and actually I lied one last thing is to call the method canvas. repaint and this should work once we finish implementing the make color method um which I'm going to make right here really quickly so int make color and if you remember this took the number of iterations so iter count and right now we're going to say that if the iteration count is the maximum number of iterations then we want to return black so that's going to be color. black. getet RGB uh otherwise we're just going to make the background blue so blue like this so let me recap what we just did we created a method called update fractal it Loops through all the pixels in in or on our canvas then we we transform those X and Y coordinates into points on our complex plane depending on what our top left X and top left Y and zoom Factor are next we calculate the number of iterations that that complex Point does and then based on the number of iterations that happen we get a different pixel color and then we set the pixel color on our fractal image and once that's all done we repaint on the canvas so let's see if if I have any bugs you never know unclean if we run this we just get a blue canvas so something went wrong I found our error y should be positive so let's go and run this and bingo as you can see we have a very rudiment Mand mandal broth set we can't click in and zoom we can't pan around but it's being displayed Right Here and Now guys thank you for watching and I'll see you in the next video
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from WilliamFiset · WilliamFiset · 17 of 60

1 JES Image Manipulation - 2 - Installation
JES Image Manipulation - 2 - Installation
WilliamFiset
2 JES Image Manipulation - 3 - User Interface
JES Image Manipulation - 3 - User Interface
WilliamFiset
3 JES Image Manipulation - 5 - Negative
JES Image Manipulation - 5 - Negative
WilliamFiset
4 JES Image Manipulation - 6 - Black & White
JES Image Manipulation - 6 - Black & White
WilliamFiset
5 JES Image Manipulation - 4 - Grayscale
JES Image Manipulation - 4 - Grayscale
WilliamFiset
6 JES Image Manipulation - 8 - Blur
JES Image Manipulation - 8 - Blur
WilliamFiset
7 JES Image Manipulation - 7 - Edge Detection
JES Image Manipulation - 7 - Edge Detection
WilliamFiset
8 JES Image Manipulation - 9 - Blend
JES Image Manipulation - 9 - Blend
WilliamFiset
9 JES Image Manipulation - 10 - Matte
JES Image Manipulation - 10 - Matte
WilliamFiset
10 JES Image Manipulation - 13 - Rotate90
JES Image Manipulation - 13 - Rotate90
WilliamFiset
11 JES Image Manipulation - 12 - Mirroring Picture
JES Image Manipulation - 12 - Mirroring Picture
WilliamFiset
12 JES Image Manipulation - 11  - Crop Image
JES Image Manipulation - 11 - Crop Image
WilliamFiset
13 JES Image Manipulation - 14 - Stretch picture
JES Image Manipulation - 14 - Stretch picture
WilliamFiset
14 Java Fractal Explorer [6/8]
Java Fractal Explorer [6/8]
WilliamFiset
15 Java Fractal Explorer [4/8]
Java Fractal Explorer [4/8]
WilliamFiset
16 Java Fractal Explorer [8/8]
Java Fractal Explorer [8/8]
WilliamFiset
Java Fractal Explorer [5/8]
Java Fractal Explorer [5/8]
WilliamFiset
18 Java Fractal Explorer [2/8]
Java Fractal Explorer [2/8]
WilliamFiset
19 Java Fractal Explorer [7/8]
Java Fractal Explorer [7/8]
WilliamFiset
20 Java Fractal Explorer [1/8]
Java Fractal Explorer [1/8]
WilliamFiset
21 Java Fractal Explorer [3/8]
Java Fractal Explorer [3/8]
WilliamFiset
22 Introduction [Programming Competition Problems]
Introduction [Programming Competition Problems]
WilliamFiset
23 String Manipulation 1 [Programming Competition Problems]
String Manipulation 1 [Programming Competition Problems]
WilliamFiset
24 String Manipulation 2 [Programming Competition Problems]
String Manipulation 2 [Programming Competition Problems]
WilliamFiset
25 Graph Theory 1 [Programming Competition Problems]
Graph Theory 1 [Programming Competition Problems]
WilliamFiset
26 Logic 1 [Programming Competition Problems]
Logic 1 [Programming Competition Problems]
WilliamFiset
27 Grid Problems 1 [Programming Competition Problems]
Grid Problems 1 [Programming Competition Problems]
WilliamFiset
28 Dynamic Programming 1 [Programming Competition Problems]
Dynamic Programming 1 [Programming Competition Problems]
WilliamFiset
29 Introduction to Big-O
Introduction to Big-O
WilliamFiset
30 Dynamic and Static Arrays
Dynamic and Static Arrays
WilliamFiset
31 Dynamic Array Code
Dynamic Array Code
WilliamFiset
32 Linked Lists Introduction
Linked Lists Introduction
WilliamFiset
33 Doubly Linked List Code
Doubly Linked List Code
WilliamFiset
34 Stack Introduction
Stack Introduction
WilliamFiset
35 Stack Implementation
Stack Implementation
WilliamFiset
36 Stack Code
Stack Code
WilliamFiset
37 Queue Introduction
Queue Introduction
WilliamFiset
38 Queue Implementation
Queue Implementation
WilliamFiset
39 Queue Code
Queue Code
WilliamFiset
40 Priority Queue Introduction
Priority Queue Introduction
WilliamFiset
41 Priority Queue Min Heaps and Max Heaps
Priority Queue Min Heaps and Max Heaps
WilliamFiset
42 Priority Queue Inserting Elements
Priority Queue Inserting Elements
WilliamFiset
43 Priority Queue Removing Elements
Priority Queue Removing Elements
WilliamFiset
44 Priority Queue Code
Priority Queue Code
WilliamFiset
45 Union Find Introduction
Union Find Introduction
WilliamFiset
46 Union Find Kruskal's Algorithm
Union Find Kruskal's Algorithm
WilliamFiset
47 Union Find - Union and Find Operations
Union Find - Union and Find Operations
WilliamFiset
48 Union Find Path Compression
Union Find Path Compression
WilliamFiset
49 Union Find Code
Union Find Code
WilliamFiset
50 Binary Search Tree Introduction
Binary Search Tree Introduction
WilliamFiset
51 Binary Search Tree Insertion
Binary Search Tree Insertion
WilliamFiset
52 Binary Search Tree Removal
Binary Search Tree Removal
WilliamFiset
53 Binary Search Tree Traversals
Binary Search Tree Traversals
WilliamFiset
54 Binary Search Tree Code
Binary Search Tree Code
WilliamFiset
55 Fenwick Tree range queries
Fenwick Tree range queries
WilliamFiset
56 Fenwick Tree point updates
Fenwick Tree point updates
WilliamFiset
57 Fenwick Tree construction
Fenwick Tree construction
WilliamFiset
58 Fenwick tree source code
Fenwick tree source code
WilliamFiset
59 Hash table hash function
Hash table hash function
WilliamFiset
60 Hash table separate chaining
Hash table separate chaining
WilliamFiset

This video teaches how to display a fractal on the screen using Java, covering the introduction of variables to track the fractal's position and depth, and the creation of methods to update the display and transform pixel coordinates into complex plane points.

Key Takeaways
  1. Create variables to track the fractal's position and depth
  2. Create a method to update the display
  3. Transform pixel coordinates into complex plane points
  4. Calculate the number of iterations for each complex point
  5. Create a color based on the number of iterations
  6. Set the pixel color on the fractal image
  7. Repaint the canvas
💡 The update fractal method is crucial in displaying the fractal on the screen, as it loops through all the pixels on the canvas, transforms the coordinates into complex plane points, and calculates the number of iterations to determine the pixel color.

Related AI Lessons

Bloom Filters, Explained Properly
Learn how Bloom filters work and their benefits, including tiny memory and blazing speed, in exchange for potential false positives.
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Learn how prefix sums enable instant range queries in arrays, boosting performance in various applications
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
A simple math question can destroy a developer's interview, highlighting the importance of being prepared for unexpected questions
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Learn to remove duplicates from a sorted array using the two pointers technique, improving from brute force to optimized solutions
Medium · Python
Up next
Stump Grinder Carbide Wheel Grinds Hardwood To Chips
Innoforge Studio
Watch →