可汗学院的Computer Science课

 

https://www.khanacademy.org/cs/docs   

(需FQ。)

原文:

All of the code in the Khan Academy Computer Science platform is written using JavaScript and Processing.js.

Feel free to browse through the documentation here to learn more about these technologies.

Before digging into the documentation here it'd probably be a good idea to watch the tutorial on How to Read Documentation.

译文:

可汗学院里计算机科学课里的所有代码都是用 Javascript 和 Processing.js 写的.

你可以随意浏览这里的文档以获得更多信息。 

在细读这里的文档之前建议看看 教程“如何阅读文档”

 

今天这篇东西就是教大家如何在本地运行可汗学院CS课里的代码。。

例如:

 

1. 准备工作...(当然也就是下载东西啦...)

 

咱得先去下载Processing.js..

Processing.js的官网:

 

Processing.js下载页:

http://processingjs.org/download/

 

 下载development.

既然需要的东西都准备齐了。。。那么...

 

2.开始动手

(你需要以下3个文件, 最好扔到一个文件夹里。):

  1. processing.js  (我们从官网上下载的那个js文件...我的是processing-1.4.1.js)
  2. anything.html   你自己创建..可随意命名
  3. anything.pde     这个也由你自己创建..可随意命名

 

anything.html里面需要输入:

<html>
<head>
    <title></title>
    <style type="text/css">
    *{
        margin: 0px;
        padding: 0px;
    }
    </style>
    <script type="text/javascript" src="processing-1.4.1.js"></script>   
</head>
<body>
    <canvas data-processing-sources="anything.pde“></canvas>
</body>
</html>

重点在于anything.pde里:

  

void setup()
{
    size(900,500);  
    background(125);
    fill(255);
    noLoop();
    PFont fontA = loadFont("courier");
    textFont(fontA, 14);  
}

void draw(){  
// Winston's handsome features don't need outlines
noStroke();

// face
fill(255, 255, 0);
ellipse(202, 208, 300, 300);

// eyes
fill(46, 46, 41);
ellipse(157, 151, 40, 40);
ellipse(304, 142, 40, 40);

// mouth
fill(252, 65, 65);
ellipse(257, 240, 120, 136);
}

 这里的函数什么的就不解释了。。。(其实我也是刚接触的。。我也在翻文档看函数代表什么意思呢。。)

本篇文章只是为了能在本地运行可汗的东西而已。。。

 更多有关processing.js的细节请查阅官网手册。

 

 

3. 打开看看

 你需要把这个文件夹丢到服务器里去运行。

而不是直接打开*.html文件。

 

笔者用的是wampserver。

(扔到www目录里即可)

 

 其他的不用在意。是我个人的东西,跟教程和processing.js都无关。

我把那3个文件都放在Khan_CS文件夹里了。。(当然,对于你来说,你可以随意命名。。无所谓的。。)

 

我们来看看文件结构(其实也就3个文件嘛...)

 

 我用的是index.html和hello-web.pde

和教程中写的不一致。不过不要纠结这个...(下面是wampserver的默认界面..)

 打开咱的文件夹~~~~(如果你的*.html文件命名的不是index. 可能还需要在点击一下那个*.html文件。

因为打开目录后是默认打开index.html文件的。)

 

 

 

收工。。。其他的也类似。

本文实在讲的很粗率。。见谅。。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2013-01-04 15:24  Orangeink  阅读(491)  评论(1编辑  收藏  举报

导航