+ 27

[SOLVED] Weird design forming in JS Canvas

Here is a code which draws a spiral in the JS canvas. The slider determines the length of each quadrilateral which is in the spiral. But, when the slider is set to its minimum value(i.e., the elements are very closely packed), strange grid like pattens form. I guess this is because of the distance (maybe 1px) between 2 quads. Any idea how to fix it ? https://code.sololearn.com/Wcf3jnf0eqlJ/?ref=app

11th Jun 2018, 7:18 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
11 Respuestas
+ 7
[edit: fixed] I still have a rather clear moiré pattern, which is coming from the (unstroked) black borders of each of your filled elements. I realize you may want the black borders, but you can make the pattern nearly invisible (leaves just a ghost) by setting your borders to the same color as your fill and then adding a stroke() at fill(): // note: strokeStyle at this line doesn't appear to be used without adding stroke() ctx.fillStyle=`hsl(${i/2+128},100%,50%)`; // Xor operator... ctx.strokeStyle=ctx.fillStyle; // <-- add this to blend borders into fill ... ctx.fill(); // your code ctx.stroke(); // <-- add to draw borders not-in-black
12th Jun 2018, 5:14 PM
Kirk Schafer
Kirk Schafer - avatar
+ 12
Solved it. Though not the best way, drawing thrice removes it. (Found on StackOverFlow)
11th Jun 2018, 2:23 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 11
What you are seeing is called a moire pattern and is due to aliasing https://en.m.wikipedia.org/wiki/Aliasing
11th Jun 2018, 7:54 AM
Louis
Louis - avatar
+ 11
nice
11th Jun 2018, 1:50 PM
Charan Leo25
Charan Leo25 - avatar
+ 8
well it may not have been your intention to have moire pattern in the spiral.. but i like it a lot. In fact, if you haven't posted about this "weird design" here, i might have asked you how did u made the awesome pattern....lol..cause before seeing Louis answer i never knew what was moire pattern.
11th Jun 2018, 11:18 AM
Phäñtøm Phôëñïx
Phäñtøm Phôëñïx - avatar
+ 8
You can upscale the pixel resolution(pixel density) to remove this effect. https://code.sololearn.com/WKO0CNJ6ny3L/?ref=app
11th Jun 2018, 5:29 PM
Haris
Haris - avatar
+ 8
👍👍👍
13th Jun 2018, 4:36 AM
Prabhat
Prabhat - avatar
+ 8
👍👍👍
13th Jun 2018, 4:36 AM
Prabhat
Prabhat - avatar
+ 3
The only option left for you is to upscale the px resolution as said by Haris https://code.sololearn.com/Wq4zXGoFoUJP/?ref=app keep up the good work!!
13th Jun 2018, 1:45 AM
Subhanshu Mohan Gupta
Subhanshu Mohan Gupta - avatar
+ 2
Really Good^_^
13th Jun 2018, 5:44 AM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
+ 1
Java script
5th Oct 2020, 12:36 PM
18CCA175 KIRUTHIKA .D
18CCA175 KIRUTHIKA .D - avatar