我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用Haskell用15行写一个Mandelbrot集,但是很难理解。

我的目标是启发学生编程很酷。

我们知道编程很酷,因为你可以创造任何你想象到的东西——它是最终的创意出口。我想激励这些初学者,让他们尽可能多地克服早期学习的困难。

Now, my reasons are selfish. I'm teaching an Intro to Computing course to a group of 60 half-engineering, half business majors; all freshmen. They are the students who came from underprivileged High schools. From my past experience, the group is generally split as follows: a few rock-stars, some who try very hard and kind of get it, the few who try very hard and barely get it, and the few who don't care. I want to reach as many of these groups as effectively as I can. Here's an example of how I'd use a computer program to teach:

Here's an example of what I'm looking for: a 1-line VBS script to get your computer to talk to you: CreateObject("sapi.spvoice").Speak InputBox("Enter your text","Talk it") I could use this to demonstrate order of operations. I'd show the code, let them play with it, then explain that There's a lot going on in that line, but the computer can make sense of it, because it knows the rules. Then I'd show them something like this: 4(5*5) / 10 + 9(.25 + .75) And you can see that first I need to do is (5*5). Then I can multiply for 4. And now I've created the Object. Dividing by 10 is the same as calling Speak - I can't Speak before I have an object, and I can't divide before I have 100. Then on the other side I first create an InputBox with some instructions for how to display it. When I hit enter on the input box it evaluates or "returns" whatever I entered. (Hint: 'oooooo' makes a funny sound) So when I say Speak, the right side is what to Speak. And I get that from the InputBox. So when you do several things on a line, like: x = 14 + y; You need to be aware of the order of things. First we add 14 and y. Then we put the result (what it evaluates to, or returns) into x.

这就是我的目标,有一堆很酷的例子来演示,并在他们玩得开心的时候教他们。我在我室友身上尝试了这个例子,虽然我可能不会把它作为第一课,但她喜欢它,并学到了一些东西。

一些很酷的数学程序,可以做出漂亮的图形或容易理解的形状,这是很好的想法,我将研究这些。这里有一些复杂的actionscript示例,但这有点太高级了,我不能教flash。你还有什么其他的想法吗?


当前回答

嗯,我记得用QBasic制作雪花和火焰时,一个朋友过来教我如何做一个旋转的3D立方体,完全让我震惊。

然后我把火调到立方体上,那真是美好的时光。

我得看看能不能找到那些旧剧本,它们不是很长。

其他回答

Back in computer class in high school, myself and a couple of friends taught the class how to program with Delphi. The class was mostly focused on programming with Pascal, so Delphi was a good next step. We demonstrated the event driven nature of Delphi and its RAD capabilities. At the end of the lesson we showed the class a sample application and asked them to reproduce it. The application asked "Are you drunk?" with two buttons Yes and No. ...I think you know what is coming next...the No button changed locations on mouse over and was almost impossible to click.

学生和老师都从中得到了很大的乐趣。

该程序只需要几行用户编写的代码和一个简单的方程来计算按钮的移动位置。我想其他学生都没发现,但也有几个很接近。

用Python将图像转换为音乐

从我的回答,我如何循环每4行每4个像素,使用Python?:

#!/usr/bin/env python
import easygui # http://easygui.sourceforge.net/
import Image   # http://www.pythonware.com/products/pil/
import numpy   # http://numpy.scipy.org/

filename = easygui.fileopenbox() # pick a file
im = Image.open(filename) # make picture
im.show() # show picture
ar = numpy.asarray(im) # get all pixels
N = 4
pixels = ar[::N,::4]  # every 4th pixel in every N-th row
notes = pixels.sum(axis=2) / 9 + 24 # compute notes [0, 52]
print "number of notes to play:", notes.size

音符可以对应不同的音调。这里我用的是等温标度:

# play the notes
import audiere # http://pyaudiere.org/
import time

d = audiere.open_device()
# Notes in equal tempered scale 
f0, a = 440, 2**(1/12.)
tones = [d.create_tone(f0*a**n) for n in range(-26, 27)] # 53

for y, row in enumerate(notes):
    print N*y # print original row number
    for t in (tones[note] for note in row):
        t.volume = 1.0 # maximum volume
        t.play()
        time.sleep(0.1) # wait around 100 milliseconds
        t.stop()

当我还是个孩子的时候,我对计算机(当时是MSX)有浓厚的兴趣,因此编程(所有的东西都是Basic的变体)。长大后我失去了它,但当我了解到《反恐精英》只是一些粉丝通过修改《半条命》代码而创造出来的mod时,我又重新拥有了它。这让我重新对编程产生了兴趣!

这不是10行代码,但如果你向人们展示某个游戏的源代码,然后修改它,让它做一些不同的事情,并向他们现场演示,这真的会让他们大吃一惊。哇,这其实不是黑魔法!你能做到的!

现在,有相当多的游戏可以做到这一点。我认为所有《雷神之锤》系列(至少1到3)的源代码都已经发布了。我知道你可以为《半条命》和《半条命2》创建mod,我相信其他游戏如《虚幻世界》和《孤岛惊魂》也提供了类似的功能。

一些简单的事情可以激发你的动力:

让武器变得超级强大(例如,无限的弹药,更高的伤害,自动瞄准。等。 添加一个动画风格的动作(飞行,快速奔跑等)。

修改本身不需要太多代码行,但它工作的事实是令人惊讶的。

我给有学习障碍的11-12岁学生上过课。我们使用Hypercard,他们发现他们可以记录物体(图像,盒子等)的位置,因为他们移动它,并播放它(动画)。虽然这不是编码,但他们想做的是:删除其中一个动作,而不重新记录它。我告诉他们,他们必须去查看代码并修改它。

你可以看出谁有计算机/编程的诀窍,当他们更喜欢用代码来做的时候,因为他们有更多的控制权。

在Excel中做一个复杂的宏,然后学习代码在做什么,这可能是通往VBA的门户。

根据年龄群体或兴趣水平的不同,直接进入代码可能很难,但最终是重要的。

我发现最喜欢的(在GWBASIC中)是:

10 input "What is your name ";N$
20 i = int(rnd * 2)
30 if i = 0 print "Hello ";N$;". You are a <fill in insult number 1>"
40 if i = 1 print "Hello ";N$;". You are a <fill in insult number 2>"

我发现初学的学生有一些观念需要修正。

电脑不会读心术。 计算机一次只做一件事,即使它们做得如此之快,它们似乎一次就做完了。 计算机只是愚蠢的机器,只会做被告知的事情。 计算机只能识别特定的东西,而这些东西就像积木一样。 一个关键的概念是,变量是包含一个值的东西,它的名称与该值不同。 你编辑程序的时间和它运行的时间之间的区别。

祝你在课堂上好运。我相信你会做得很好的。

附言:我相信你明白,除了材料和技能,你还在教授一种态度,这也是同样重要的。