-
Notifications
You must be signed in to change notification settings - Fork 9
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
Mandelbrot demo: show the image #11
Comments
I had to reduce the image size. This works: program mandelbrot
implicit none
integer , parameter :: rk = 8
integer , parameter :: i_max = 80
integer , parameter :: j_max = 60
integer , parameter :: n_max = 100
real (rk), parameter :: x_centre = -0.5_rk
real (rk), parameter :: y_centre = 0.0_rk
real (rk), parameter :: width = 4.0_rk
real (rk), parameter :: height = 3.0_rk
real (rk), parameter :: dx_di = width / i_max
real (rk), parameter :: dy_dj = -height / j_max
real (rk), parameter :: x_offset = x_centre - 0.5_rk * (i_max + 1) * dx_di
real (rk), parameter :: y_offset = y_centre - 0.5_rk * (j_max + 1) * dy_dj
integer :: image(i_max, j_max)
integer :: i
integer :: j
integer :: n
real (rk) :: x
real (rk) :: y
real (rk) :: x_0
real (rk) :: y_0
real (rk) :: x_sqr
real (rk) :: y_sqr
do j = 1, j_max
y_0 = y_offset + dy_dj * j
do i = 1, i_max
x_0 = x_offset + dx_di * i
x = 0.0_rk
y = 0.0_rk
n = 0
do
x_sqr = x * x
y_sqr = y * y
if (x_sqr + y_sqr > 4.0_rk) then
image(i,j) = 255
exit
end if
if (n == n_max) then
image(i,j) = 0
exit
end if
y = y_0 + 2.0_rk * x * y
x = x_0 + x_sqr - y_sqr
n = n + 1
end do
end do
end do
print '(a)', 'P2'
print '(i0, 1x, i0)', i_max, j_max
print '(i0)', 255
do j = 1, j_max
do i = 1, i_max
print '(i0)', image(i,j)
end do
end do
end program mandelbrot And produces the correct output. Just copy & paste the output into a file |
The last missing piece is how to show the image in the webpage itself as an image. The approach how to do it is described here: |
It seems the initial example code failed due to insufficient memory. We recently increased the memory limit in lfortran/lfortran#126. Probably, the current |
@Shaikh-Ubaid I think that's right. Even the |
Please, could someone possibly share if this issue is complete? |
This is fixed! Thank you so much @Shaikh-Ubaid for implementing it. Here is how it looks like for me now at dev.lfortran.org: |
TODO:
Old:
Here is a code that compiles to WAT at dev.lfortran.org: https://gitlab.com/lfortran/lfortran/-/issues/702#note_1059822597, but the execution window says:
So we need to investigate what is going on.
The text was updated successfully, but these errors were encountered: