麻省理工学院的计划画线

发布于 2024-10-28 11:57:19 字数 267 浏览 1 评论 0原文

有没有人使用麻省理工学院的方案成功地使拉线工作?

https ://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-ZH-15.html#%_sec_2.2.4

Has anyone been successful in getting draw-line working using MIT-scheme?

https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

苦笑流年记忆 2024-11-04 11:57:19

关键词是:

例如,假设我们有一个绘制线过程,它在屏幕上的两个指定点之间绘制一条线。

换句话说,不存在画线——这纯粹是假设。

The key words are:

For instance, suppose we have a procedure draw-line that draws a line on the screen between two specified points.

In other words, there is no draw-line -- it's purely hypothetical.

¢蛋碎的人ぎ生 2024-11-04 11:57:19

我使用了 scmutils由杰拉尔德·苏斯曼提供。这是他的经典力学课程中使用的数值和代数包,并且对 绘制图表

假设你已经定义了 make-vectmake-seg

(define line (make-seg (make-vect 2 3) (make-vect 4 1)))

(define win1 (frame -5 5 -5 5))

(define (draw-line frame a b)
  (plot-line frame (xcor a) (ycor a) (xcor b) (ycor b))
)

这是我实现图片语言后得到的

乔治平方极限

I used scmutils provided by Gerald Sussman. It's a numerical and algebraic package used in his class on classical mechanics and has low-level support for plotting graphs.

Assuming you have defined make-vect and make-seg

(define line (make-seg (make-vect 2 3) (make-vect 4 1)))

(define win1 (frame -5 5 -5 5))

(define (draw-line frame a b)
  (plot-line frame (xcor a) (ycor a) (xcor b) (ycor b))
)

This is what I got after implementing the picture language

george's square limit

垂暮老矣 2024-11-04 11:57:19

有一个实际的 MIT 计划包由本书作者针对本书该部分的图片语言 (SICP 第 2.2.4 节)。然而,该软件包是在 1993 年编写的,我没有运气让它在我的 Mac OS High Sierra 上运行。

然而,其他人专门为这本书的这一部分制作了一个更新的软件包,包括所有功能,包括画线,您实际上可以制作图片并使用它们。下载racket,并运行以下命令:

(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))  

有关更多信息,请参阅这个非常棒的软件包的用户手册

There was an actual MIT Scheme package made by the authors of the book for the picture language in that part of the book (SICP section 2.2.4). However, the package was written in 1993 and I haven't had any luck getting it to work on my Mac OS High Sierra.

However, a much more recent package by someone else made specifically for that part of the book includes all functions, including draw-line, and you can actually make the pictures and play around with them. Download racket, and run the following:

(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))  

For more, see the user manual for this very awesome package.

傲性难收 2024-11-04 11:57:19

在阅读本书的这一部分时,我决定使用 draw-line 生成可在 HTML 画布上绘制的 JavaScript 代码。

(define (draw-line v1 v2)
  (newline)
  (display "ctx.beginPath();")
  (display (string-append "ctx.moveTo(" (number->string (xcor-vect v1)) "," (number->string (ycor-vect v1)) ");"))
  (display (string-append "ctx.lineTo(" (number->string (xcor-vect v2)) "," (number->string (ycor-vect v2)) ");"))
  (display "ctx.stroke();"))

毕竟,draw-line 的具体实现方式对于使用它的程序来说并不重要,我们只需要一种可视化结果的方法。唯一的缺点是 HTML 画布坐标从左上角开始,而不是从左下角开始,但这也可以通过稍微调整生成的代码来解决。

这是完整的方案代码 https:// github.com/antivanov/scip-exercises/blob/master/scheme/ch2/2.48.49.scm https://github.com/antivanov/scip-exercises/blob/master/scheme/ch2/2.52.scm

按照相同的方法,我能够形象化本章中的其他示例/练习。

When following this part of the book I decided to make draw-line generate JavaScript code that would draw on HTML canvas.

(define (draw-line v1 v2)
  (newline)
  (display "ctx.beginPath();")
  (display (string-append "ctx.moveTo(" (number->string (xcor-vect v1)) "," (number->string (ycor-vect v1)) ");"))
  (display (string-append "ctx.lineTo(" (number->string (xcor-vect v2)) "," (number->string (ycor-vect v2)) ");"))
  (display "ctx.stroke();"))

After all how exactly draw-line is implemented is not important for the procedures that use it and we just need a way to visualize the results. The only downside is that HTML canvas coordinates start in the top left corner, not in the left bottom, but that might also be dealt with by adjusting the code being generated a bit.

Here is the full Scheme code https://github.com/antivanov/scip-exercises/blob/master/scheme/ch2/2.48.49.scm https://github.com/antivanov/scip-exercises/blob/master/scheme/ch2/2.52.scm

Following the same approach I was able to visualize other examples/excercises from the chapter.

睫毛溺水了 2024-11-04 11:57:19

我完成了我的一门课的画家作业。对于 2.47,您实际上不需要担心绘制线。您需要做的就是创建构造函数和选择器:

(define (make-frame origin edge1 edge2)
(list origin edge1 edge2))

(define (origin-frame frame)
(car frame))

(define (edge1-frame frame)
(cadr frame))

(define (edge2-frame frame)
(caddr frame))

I finished this painter assignment for one of my classes. For 2.47, you don't need to worry about draw-line really. All you need to do is make the constructors and selectors:

(define (make-frame origin edge1 edge2)
(list origin edge1 edge2))

(define (origin-frame frame)
(car frame))

(define (edge1-frame frame)
(cadr frame))

(define (edge2-frame frame)
(caddr frame))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文