6

Algorithm You can simplify the code and make it run faster if you construct the next-level carpet by continuing to work on the previous image (punching more holes in it), rather than starting with a blank slate every time. The code can look prettier and more Pythonic too, since the technique lets you get rid of the recursion. Coding practices It's a good ...


4

The two things that currently bother me most about this code are Naming and Abstraction. Don't get me wrong, this is something pretty cool and it's really well-crafted for the most part. But I'm still waiting for this to go the last mile: There is 12 local variables or functions in your main. I reckon you can easily reduce that to half as many by adding ...


4

I only have a few small suggestions: I like to have "tweaks" that I may want to change later at the top of my file. This makes it easier to quickly alter them when playing around without needing to dig through the code. I'd move levels and standard_frame_time_in_ms to the top so they're a little more accessible. I might also change levels to n_levels or ...


4

I'll start off with some possible improvements in the logic. Firstly, in Maze::generate, the initialisation of candidates_list could be simplified from candidates_list = [] candidates_list.append((0, 0)) to candidates_list = [(0, 0)] Secondly, right on the next line, the condition could be simplified from while len(candidates_list) > 0: to while ...


3

I am not sure how I would inherit a static method As I'm sure you've figured out, you can't. I also don't think this would make any sense in your case, since the APIs is not the same. If you are just wanting to reduce the amount of code that these Add methods have in common, then hopefully some of my suggestions below will help. tm Redundancy Why do you ...


3

I don't see anything major. Just some nitpicks: offsets_to_surrounding_tiles could be written using a list comprehension/generator expression so the offsets don't need to be hard-coded: def offsets_to_surrounding_tiles2(): return [(x, y) for y in range(-1, 2) for x in range(-1, 2) if (x, y) != (0, 0)] # So we don't ...


3

Optimization You can achieve a significant perfomance improvement by using a so-called 'dirty rectangles' approach. Instead of calculating the color-distance of every single pixel every single time, you only need to recalculate the distance of pixels that have been modified. Every step, you're eliminating two genomes, so they will have to be fully ...


2

I have two small sugestions... Without using different math in ColorDistance which is the bottleneck (according to ReShaprer profiler (dotTrace)) as a quick speed improvement you can paralleize ScoreGenoms by using Parallel.For replacing the original for Parallel.For(0, numberOfGenomes, i => { ... }) Evolve on the other hand could use Application....


2

Naming public static void drawRectangle(Graphics g, int xCenter, int yCenter, int levelsNeeded){ I would call this drawRectangles, as it draws four rectangles on each iteration of the loop. Also, that leaves room for a drawRectangle method. Typos //all squres are based off an 8 pixel system. I use this to shift things around ALOT. This has ...


2

Putting this statement before S := S / 255, makes the record consistent for handling HSV: H := H/360.0; //for making the 0..360 degrees map to 0..1 as required in the assert Additionally, these setter,getter can help working with degree values of Hue which is standard for web colors: procedure TColorRec.SetHueDegrees(const Value: Double); var H, S, V: ...


2

Docstrings: You should include a docstring at the beginning of every method, class, and module you write. This will help any documentation identify what your code is supposed to do. Unnecessary Methods: You have a method, intro, specifically for printing the introduction to your program. It's only two print statements. It's unnecessary in my opinion to have ...


2

When drawing graphics I admit that it in general can be difficult to split the code into meaningful sub methods because often many variables are used across different sections of the process. A way to do it could be to make a non static class, that holds the entire data set, constant key measurements and other resources as member fields/properties and then ...


2

The code in this answer is not tested and is only there as a guide "A badly constructed object is not better than using globals." – me def circle_radius_from_circumference(circ): return circ / math.tau def circle_circumference_from_radius(radius): return radius * math.tau How to make an object out of that ? class Circle: @staticmethod ...


2

typedef is your friend You're using C99, so typedef struct { ... } rectangle; instead of the older style. Additional structs If you want to tighten up some of your code, one potential way is to make a coordinate struct. This would halve the number of members of rectangle, for instance. Such nesting would not have a performance impact. It would also be ...


2

Gravitational Constant In your description you mention the gravitational constant is 0.5 for performance reasons, in the code it is actually 0.1. This Pointer There are times when the this pointer is necessary, but it is not necessary in the code under review (EntryPoint.cs, Body.cs and BodySystem.cs). Variable Names To some extent this is personal ...


1

Welcome to CodeReview! I'm not familiar enough with your stack to suggest performance improvements, but one other thing I will suggest: use a fixed-width format for your table, like this: Coords = np.array([ [ 0.00, 0.00, 0.00, 0.00, 'N', 0, 0], [ 0.00, 1.00, 0.00, 'BRANCH', 'N', 0, 0], [ 0.00, 0.00, 0.00, 'BRANCH', 0....


1

Kudos on using modern OpenGL for this! We see a lot of OpenGL code around here relying on deprecated functionality, so this is a breath of fresh air. Naming I think your naming needs some work. The name convert_pixels_to_render_coordinates is highly confusing. When I think of pixels, I generally think of an array of RGB(A) values (or possibly in some other ...


1

While you seem to be on a good way, your code still hast a global variable it does not need. You can simplify that code a lot by using something like this: OFFSETS = {"w": (0, -1), "Up": (0, -1), # weird coordinate system... "a": (-1, 0), "Left": (-1, 0), "s": (0, 1), "Down": (0, 1), "d": (1, 0), "Right": (1, 0)} def ...


1

random.randrange() It looks like these are just used as an argument to random.choice() for picking random coordinates. random.randrange(start, stop, step) would work. This also might be a good place to create a function that returns a random coordinate. X_START = 10 X_STEP = 90 X_LIMIT = width - 10 Y_START = 10 Y_STEP = 30 Y_LIMIT = 390 def ...


1

Docstrings: You should include a docstring at the beginning of every method, class and module you write. This will allow documentation to identify what your program is supposed to accomplish. Wildcard Import Statements: from ... import * should be avoided. You can end up importing something that you don't use/need, which can cause name collisions and other ...


1

This was great work, especially for a first project. I made a bunch of changes and tried to comment my reasoning where things stood out. Here's a few things to note: Your code was at the size where you could go either way, but I decided to split it up into modules. I made Point and Rgb implement Copy since they are just very small collections of numbers. ...


1

Here is an attempt at an updated version based on @visualmelon suggestions, but not sure If I just ended up making bigger mess of it then before or not, partly because I'm not very familiar with interfaces and not sure how to properly use it to make this simpler (I would happily take some more suggestions), though this version is a bit more fleshed out then ...


1

In getOverlaps I think you should find the gcd(small, large) and divide with that instead of testing for large % small <> 0 (if I understand the project right). E.g.: spokes 12 and 15 -> gcd = 3 -> 180 / 3 = 60 rotations -> rotation angle: 360 / 60 = 6 IMO you overdo the use of the |> operator a little: let input = () |> Console....


1

This is an interesting project. Is your goal to simplify the use of CoreGraphics from Python? What's the advantage of using your python module over just importing Quartz and using it directly? That's not intended as a criticism, but a serious question. The answer will inform how you design the interface for your library. Naming One thing I'd like to point ...


Only top voted, non community-wiki answers of a minimum length are eligible