Javascript |
|||||||||
Plot Constellation
this code is created first by chatGPT on Jan 27 2023 (meaning using chatGPT 3.5) and then modified a little bit my me. The initial request that I put into chatGPT is as follows :
NOTE : It is not guaranteed that you would have the same code as I got since chatGPT produce the answers differently depending on the context. And it may produce the different answers everytime you ask even with the exact the same question. NOTE : I noticed that chatGPT misses some of the requirement or misinterprets. The part highlighted in red are the parts that are missed or misinterpreted. In many case, chatGPT generated real number random data instead of complex number and uniform random number instead of gaussian noise. But if you ask again with the specific requirement (e.g, you should add gaussian noise instead of uniform noise etc), then chatGPT would fix it. NOTE : If you don't have any of your own idea for the request, copy my request and paste it into the chatGPT and put additional requests based on the output for the previous request. I would suggest to create a new thread in the chatGPT and put my request and then continue to add your own request.
Usage : Click on [Constellation] button. Whenever you click on it, you will get different constellation.
NOTE : I downloaded the math.js library from Mathjs homepage and placed in local path : mathjs/math.js NOTE : I took me longer time for me to debug this code than other examples. It seems chatGPT is not well trained with the details of handling the details of canvas. Sometimes there seem to be some bugs in canvas object itself. For example, if I put the number 2.0 or 1.99 in highlighted part (actually 2.0 is logically correct number), I got unexpected rectangles and blank part in the coordinate plane. I spent long time to figure this out but still don't know why it should be like this. for (let i = -2.0; i <= 2.0; i += 0.2) { ctx.moveTo(i, -1.98); ctx.lineTo(i, 1.98); ctx.moveTo(-1.98, i); ctx.lineTo(1.98, i); } Another tricky point was about ctx.lineWidth = 1/(canvas.width/4); when I scale up the coordnate using scale() method, I noticed that the linewidth got scaled up accordinly. so I got super thick grid lines. so I needed to scaledown lineWidth before scaling up with scale() method.
|
|||||||||