Java Fractal Explorer [5/8]
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
▶
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
JES Image Manipulation - 2 - Installation
WilliamFiset
JES Image Manipulation - 3 - User Interface
WilliamFiset
JES Image Manipulation - 5 - Negative
WilliamFiset
JES Image Manipulation - 6 - Black & White
WilliamFiset
JES Image Manipulation - 4 - Grayscale
WilliamFiset
JES Image Manipulation - 8 - Blur
WilliamFiset
JES Image Manipulation - 7 - Edge Detection
WilliamFiset
JES Image Manipulation - 9 - Blend
WilliamFiset
JES Image Manipulation - 10 - Matte
WilliamFiset
JES Image Manipulation - 13 - Rotate90
WilliamFiset
JES Image Manipulation - 12 - Mirroring Picture
WilliamFiset
JES Image Manipulation - 11 - Crop Image
WilliamFiset
JES Image Manipulation - 14 - Stretch picture
WilliamFiset
Java Fractal Explorer [6/8]
WilliamFiset
Java Fractal Explorer [4/8]
WilliamFiset
Java Fractal Explorer [8/8]
WilliamFiset
Java Fractal Explorer [5/8]
WilliamFiset
Java Fractal Explorer [2/8]
WilliamFiset
Java Fractal Explorer [7/8]
WilliamFiset
Java Fractal Explorer [1/8]
WilliamFiset
Java Fractal Explorer [3/8]
WilliamFiset
Introduction [Programming Competition Problems]
WilliamFiset
String Manipulation 1 [Programming Competition Problems]
WilliamFiset
String Manipulation 2 [Programming Competition Problems]
WilliamFiset
Graph Theory 1 [Programming Competition Problems]
WilliamFiset
Logic 1 [Programming Competition Problems]
WilliamFiset
Grid Problems 1 [Programming Competition Problems]
WilliamFiset
Dynamic Programming 1 [Programming Competition Problems]
WilliamFiset
Introduction to Big-O
WilliamFiset
Dynamic and Static Arrays
WilliamFiset
Dynamic Array Code
WilliamFiset
Linked Lists Introduction
WilliamFiset
Doubly Linked List Code
WilliamFiset
Stack Introduction
WilliamFiset
Stack Implementation
WilliamFiset
Stack Code
WilliamFiset
Queue Introduction
WilliamFiset
Queue Implementation
WilliamFiset
Queue Code
WilliamFiset
Priority Queue Introduction
WilliamFiset
Priority Queue Min Heaps and Max Heaps
WilliamFiset
Priority Queue Inserting Elements
WilliamFiset
Priority Queue Removing Elements
WilliamFiset
Priority Queue Code
WilliamFiset
Union Find Introduction
WilliamFiset
Union Find Kruskal's Algorithm
WilliamFiset
Union Find - Union and Find Operations
WilliamFiset
Union Find Path Compression
WilliamFiset
Union Find Code
WilliamFiset
Binary Search Tree Introduction
WilliamFiset
Binary Search Tree Insertion
WilliamFiset
Binary Search Tree Removal
WilliamFiset
Binary Search Tree Traversals
WilliamFiset
Binary Search Tree Code
WilliamFiset
Fenwick Tree range queries
WilliamFiset
Fenwick Tree point updates
WilliamFiset
Fenwick Tree construction
WilliamFiset
Fenwick tree source code
WilliamFiset
Hash table hash function
WilliamFiset
Hash table separate chaining
WilliamFiset
Related AI Lessons
⚡
⚡
⚡
⚡
Bloom Filters, Explained Properly
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Medium · Python
🎓
Tutor Explanation
DeepCamp AI