fortran/bgi/demo_bgi.f90 · 2039 字节 · 下载原文
! demo_bgi.f90 —— **第 3 层:传统图形接口**(BGI / Borland Graphics Interface)
! demo_bgi.f90 -- **Layer 3: the classic graphics interface** (BGI / Borland Graphics Interface)
!
! 这一层是**固定分辨率 + 16 索引色**的老式图形:`initgraph` 开一块 640×480 的画布,
! 坐标写死、`SetColor(4)` 说的是「4 号色」而不是 RGB。要现代表达请看 ui/demo_ui.f90。
! This layer is **fixed-resolution + 16 indexed colours**: `initgraph` opens a 640x480
! canvas, coordinates are hard-coded, and `SetColor(4)` means "palette index 4", not RGB.
! For the modern layer see ui/demo_ui.f90.
!
! 跑法 / How to run:
! vml run examples/fortran/bgi/demo_bgi.f90
! 桌面出图 / Desktop render:
! vmlcli Examples/fortran/bgi/demo_bgi.f90 --frames /tmp/bgi_frames
!
! ⚠ `initgraph(gd, gm, path)` 的前两个实参在 C 里是**指针**(入参+出参)。
! 本前端没有取地址符,按约定用 `vml_alloc` 拿一块地址:`gd` 与 `gd+4` 分别当两格 int。
! ⚠ The first two arguments of `initgraph(gd, gm, path)` are **pointers** in C (in/out).
! This front end has no address-of operator, so `vml_alloc` supplies two int slots.
!
! BGI 的函数名按 `Lib/fortran/shared.f90` 的声明写法(PascalCase 别名与全小写都在;
! Fortran 不区分大小写,这里用全小写)。
! The BGI names follow the declarations in `Lib/fortran/shared.f90` (Fortran is
! case-insensitive, so the lower-case spelling is used here).
program demo_bgi
implicit none
integer :: gd, gm
gd = vml_alloc(16)
gm = gd + 4
call initgraph(gd, gm, '')
call setbkcolor(0)
call cleardevice()
call setcolor(4) ! 4 = 红 / red
call line(20, 20, 300, 200)
call setcolor(14) ! 14 = 黄 / yellow
call circle(320, 240, 60)
call setcolor(10) ! 10 = 亮绿 / light green
call rectangle(40, 40, 220, 160)
call outtextxy(30, 30, 'demo_bgi.f90')
call ui_2d_present()
call closegraph()
end program demo_bgi