Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pynoise code bug #489

Merged
merged 8 commits into from
May 11, 2023
Merged

fix pynoise code bug #489

merged 8 commits into from
May 11, 2023

Conversation

sdbds
Copy link
Contributor

@sdbds sdbds commented May 9, 2023

I discussed pynoise with my friend, and he pointed out a coding bug in it. After the loop starts, w and h will be overwritten, requiring renaming new variable. Upon his testing, this issue indeed exists.

Before↓
image

After↓
image

I consulted with the author, and he agreed that the revised version better reflects the effects mentioned in the article, even though the original version also had good results. He has updated the article and added new notes, so I am submitting this new code to better align with the intended effect.

we can keep old code in a variant,too.

@sdbds
Copy link
Contributor Author

sdbds commented May 9, 2023

The loop will break once when w or h becomes 1. Here is how I got that answer:

The initial values of w and h are 512.
The loop will iterate 6 times, with i ranging from 0 to 5.
In each iteration, r is a random number between 2 and 4.
w and h are divided by r^i and rounded down to the nearest integer.
If w or h becomes 1, the loop will break.
Let’s assume the worst case scenario, where r is always 4. Then we can calculate the values of w and h in each iteration as follows:

i = 0: w = 512 / 4^0 = 512, h = 512 / 4^0 = 512
i = 1: w = 512 / 4^1 = 128, h = 512 / 4^1 = 128
i = 2: w = 128 / 4^2 = 8, h = 128 / 4^2 = 8
i = 3: w = 8 / 4^3 = 1, h = 32 / 4^3 = 1

As you can see, when i is 3, both w and h become zero, which is less than one. So the loop will break at this point. Therefore, the loop will break once in the worst case scenario.

@kohya-ss
Copy link
Owner

Thank you for this! I think this update makes sense, and will merge as soon as possible.

@kohya-ss kohya-ss changed the base branch from main to dev May 11, 2023 12:48
@kohya-ss kohya-ss merged commit 8d562ec into kohya-ss:dev May 11, 2023
@sdbds sdbds deleted the fix_mutil_noise2 branch May 15, 2023 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants