Java Fractal Explorer [7/8]

WilliamFiset · Intermediate ·⚡ Algorithms & Data Structures ·11y ago

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 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
17 Java Fractal Explorer [5/8]
Java Fractal Explorer [5/8]
WilliamFiset
18 Java Fractal Explorer [2/8]
Java Fractal Explorer [2/8]
WilliamFiset
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 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. The viewer will learn how to use bitwise operations to create a color gradient and how to modify the makeColor method to return a color based on the number of iterations.

Key Takeaways
  1. Understand how colors are stored as integers in Java
  2. Choose a color and a mask to use in the makeColor method
  3. Modify the makeColor method to return a color based on the number of iterations using bitwise operations
  4. Test the modified makeColor method to see the color gradient in action
💡 Using bitwise operations to create a color gradient based on the number of iterations can add depth perception to a fractal explorer

Related Reads

📰
Advanced Stack ApplicationsData Structures and Algorithms Deep‑Dive — Advanced Stack Applications…
Learn advanced stack applications in data structures and algorithms to improve coding skills
Medium · Programming
📰
The Minecraft anvil is a tree-cost optimization problem in disguise
Optimize tree costs in Minecraft using graph theory and algorithms, just like the anvil repair system
Dev.to · Mark
📰
KMP Algorithm (Knuth-Morris-Pratt): The Smart Way to Perform String Matching in O(N)
Learn the KMP algorithm for efficient string matching in O(N) time complexity and improve your coding skills
Dev.to · Jaspreet singh
📰
Every Backtracking Problem Is the Same Three Lines. I Just Couldn't See the Tree.
Master backtracking problems with a simple three-line approach to improve problem-solving skills in coding interviews and challenges
Dev.to · Alex Mateo
Up next
Stump Grinder Carbide Wheel Grinds Hardwood To Chips
Innoforge Studio
Watch →