Java Fractal Explorer [7/8]
Key Takeaways
The video demonstrates how to create a Java fractal explorer with depth perception by modifying the makeColor method to return a color based on the number of iterations, utilizing bitwise operations to create a color gradient.
Full Transcript
if we have a look at our fractal Explorer currently we can we can zoom in however the only issue we have is that there's no depth perception we don't know where we are exactly in the fractal or how deep and we're going to change that in the make color method so if you remember we pass in as a parameter the the number of iterations we did on that specific point and then convert that into a color but that color we're returning is being stored as an integer now you might be wondering why a color is an integer to understand this we need to go back to when we first created our fractal image and the type or fractal image we said buffered image DOT type int RGB or integer RGB meaning we're storing values of colors as integers the next question is so how is this done have a simple RGB that color I mean like this each of these components can be stored with values ranging from 0 to 255. as such but we know that an integer is usually stored with 32 bits so that would be like this we can use this to our advantage because we know that with eight bits we can store all the values from 0 to 255. so we actually only need the first three the first three bytes so we can store an integer I mean a color in three bytes so for example this is the value 0 however this would be the value 4 and this would be the value 5. and if they're all ones so like this then we have the value 255. so let's change that back to how it was so now that we understand how colors are being stored as integers we can use that fact to our advantage when creating color given an integer counter there's no right way to do this and I would encourage you to be as creative as possible but my Approach will will be to have a color so to choose a random color that spans all of the writing green and blue Spectrum so maybe a little bit of green a little bit of red a little bit of blue and then have a mask that goes over over top of that that changes those those bit values depending on the magnitude of enter count let me show you how to do that so first we're going to need a color so here's the color I chose it doesn't actually matter which color you choose but I would recommend something that has a bit of red a bit of green and some blue and next we're going to choose a mask something that we're going to to be shifting and oring with our color make sure these values have 0b in front of them meaning we're defining a binary number but these are really just uh random integers so maybe maybe this one would be something like like this or and this one would be a bit smaller because the the biggest one only starts around 10 so uh maybe I don't know something around that range probably a bit bigger um but do remember that these are simply integers the slow type also so the reason I chose the mask to be this value and especially the fact that it has a bunch of zeros at the end is because we're going to be shifting it to the left and we're going to be doing a comparison or rather o-ring o-ring the bits together so that it's going to produce a new color each time depending on the shift of the Mask or in fact the depth so in order to define the the shift magnitude as enter count divided by 13. 13 because that's the number of zeros I think I have I'm not going to count them um but essentially there's going to be 13 different shifts possible so if we say mask shifted by one then that would be this value um but shifted by one so you would add a zero remove a one if we have mask shifted by two then remove a zero but add a zero at the end so every time we're doing a different shift operation we're losing a zero and adding it at the front of the number so what this does is when we actually or this with this this color up here we're going to get a different color for each depth depending on where the shift magnitude is what I mean by o-ring is if we're ordering the numbers say this and that well we look at the two values on top of each other if it contains a one then we put a 1 at the bottom if it can if they're both zero then it's zero so they're both zero all right zero or one is one one or zero plus one one or zero is one so these two all together would give that so we're going to be ordering uh the mask with the color so let's get rid of this and do that so it's going to be the color or with so this single pipe is the binary or and we're going to say mask shifted by where the shift magnitude is and that's it so let's run this and see what colors we get and while as you can see we already have something stunning purple background and and a thick outline for our fractal as we zoom in the colors are changing gorgeous aren't they and as you zoom into the fractal maybe you're going to see some colors get repeated and the reason is occasionally the shift will not have any effect because perhaps a shift of Two and a shift of 7 will result in the the or operation giving uh the same thing so so instead of oring you might try xoring or or ending or some other binary operation you might want but I'm going to stick with the or for now and that's how I plan on viewing the depth in our fractals by changing color but feel free to make any any make color method you choose fit so guys thank you for watching and I'll see you in the next video
Original Description
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
===============================================================================
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from WilliamFiset · WilliamFiset · 19 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
▶
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 Reads
📰
📰
📰
📰
Advanced Stack ApplicationsData Structures and Algorithms Deep‑Dive — Advanced Stack Applications…
Medium · Programming
The Minecraft anvil is a tree-cost optimization problem in disguise
Dev.to · Mark
KMP Algorithm (Knuth-Morris-Pratt): The Smart Way to Perform String Matching in O(N)
Dev.to · Jaspreet singh
Every Backtracking Problem Is the Same Three Lines. I Just Couldn't See the Tree.
Dev.to · Alex Mateo
🎓
Tutor Explanation
DeepCamp AI