发信人: Spirit (妖精雨·雨之魂·天凉好个妖), 信区: ANSI
标 题: 第二章·B类作业
发信站: 日月光华 (2007年02月02日20:42:11 星期五), 站内信件
B类作业(建议版主学员或有兴趣的学员完成)
3.简化以下代码。(书面提交,提交简化后代码及显示效果)
*[1m*[4m*[5m*[33;45;31mA*[0m*[44;45;32mB*[0m*[42;32mC*[0m
正确的答案是:
代码:*[1;4;5;31;45mA*[0;45;32mB*[42mC*[m
效果:ABC
这题大家的答案五花八门@@..真正做对的只有三位同学。若不是
对ANSI的显示方式非常熟悉,基本上不可能做对。
说一下主要的问题:
对于A的优化只要把结尾是m的几项合并就可以了,基本上都没问题
对于B的优化,部分同学写成了*[0m*[45;32m或*[m*[45;32m。
其实同样以*[?m结尾的是可以合并的,但有一点需要注意,*[0m*[45;32m
和*[m*[45;32m虽然看起来相似,但显示效果却是不一样的。
不过,在作代码简化的时候应当具体问题具体分析。
对于C的优化,不少同学用了*[0m来恢复原先状态。其实大可不必。
因为B和C的前景色一致,B又是非高亮显示,只需要改变一下背景色而已。
那么什么时候需要用*[0m恢复显示呢?通常当前一个字符使用了高亮、
下划线、闪烁,而后一个字符不需要这些特性的时候我们使用这个字符。
另一种情况是为了缩减代码,如果需要同时改变前景、背景色到*[0;40;37m
时,我们用*[0m比用*[40;37m节省。这时候需要注意一下高低亮的问题。
这个作业做的不好的也不用灰心,其实每个人都多多少少有点问题,
只有daviddvd、change、NSgan三位同学完全作对了,多加练习一定能做好:)
对于代码规范的意义,我就不罗列大家的作业了。大家都有一定的认
识,我只在这里谈谈我的看法。
代码的规范化分两个部分,一个是简化,另一个是规范化。简化是规
范化的一个部分,因为规范化只能通过手动进行,所以去掉废代码的作品
简化的工作量比较小。规范化的好处是,作品在不同的term下的显示效果
相同。这个保证了ansi作品的最佳显示效果。另外规范化的代码的可读性
强,这个给手动修改带来了方便。
注意一下什么样是规范的代码
1.没有废代码,同样的设置用";"连写
1.1 没有多于的属性设置,如*[41;43m,应当用*[43m代替
1.2 同一属性不重复设置,如*[33mA*[33mB,应当用*[33mAB代替
1.3 相邻的空格前景设置忽略,如果A*[31m *[33mB,用A*[33m B代替
2.行初设置高、低亮
使用默认方式显示会造成高亮的时候效果的差异。在行首如果第
一个字符是低亮字符,也应当用*[0m设定一下。
3.每行行末用*[m
为什么末尾是*[m而不是*[0m呢?
*[0m是恢复所有特殊状态(*[1m、*[4m、*[5m和*[7m),后文
按低亮方式显示。*[m是恢复上述特殊状态,后文按term默认设置
显示。
使用*[0m,那么低亮效果会影响下一行,这个在ANSI作品
翻页显示的时候会造成显示效果的差异。
4.行中用*[0m,少用*[m
用到*[m之后,需要注意是否正确设定了高低亮效果。
5.当一行代码超过255时,尽量考虑精简代码,少用移位方式
移位虽然能完美的表现作品,但是很多小白无法正确复制。
如果实在无法精简,对于自己的作品,可以考虑修改作品,若是
复制他人的作品,那么只能考虑移位了:(
顺便说一下,但是AnsiEditor直接copy出的代码是以*[0m结尾的,
想要为一幅作品去掉废代码时,比较取巧的方式是,先copy到AE上,
再复制到Fterm自带的yaae上,这样的代码会比较精简又规范:)
下面罗列一下大家的作业:
1.*[1;4;5;45;31mA*[0;45;32mB*[0;42;32mC*[0m
这个答案的有10位,其中只有两位最后用了*[m而不是*[0m
2.*[1;4;5;45;31mA*[0m*[45;32mB*[0m*[42;32mC*[0m
*[1;4;5;45;31mA*[m*[45;32mB*[m*[42;32mC*[m
这个答案有9位同学,六位第一种,三位第二种。
3.*[1;4;5;45;31mA*[0m*[45;32mB*[42;32mC*[0m
*[1;4;5;45;31mA*[0;45;32mB*[42;32mC*[0m
这个有四位同学
4.*[1;4;5;45;31mA*[0m*[45;32mB*[42mC*[0m
*[1;4;5;31;45mA*[m*[32;45mB*[42mC*[m
这个比较接近标准答案了,只有两位同学
下面这几位同学的作业有点小问题
Redleaves *[1;4;5;33;45;31mA*[m*[45;32mB[m*[42;32mC*[m
~~ ~~这两个只有第二个起作用,第一个应该去掉
fifiisgenius *[1;4;5;33;45;31mA*[44;45;32mB*[42;32mC*[m
~~~~~这两个也应该去掉一个
every *[1;4;5;31mA*[0;32mBC*[m
这个完全不对了。。。
happyif *[1;4;5;45;31mA*[0m*[45;32mB*[0m*[42m *[0m
这位忽略了最后一个C,其实前景背景一个颜色经常用于暗藏签名
看不出来但却是需要的
rabitzhang *[4m*[5;1;45;31mA*[0;45;32mB*[42;32mC*[m
~~~~*[4m可以和后面的合并
--
※ 来源:·日月光华 bbs.fudan.edu.cn·[FROM: 218.83.252.199]
Sender: Spirit Fairy Rain, Soul of Rain, It’s a Cool Day, What a Monster, Message Area: ANSI
Title: Chapter 2 Class B Homework
Sending site: Sun and Moon Guanghua Friday, February 2, 2007 20:42:11, site mail
Class assignments are recommended to be completed by moderator students or interested students.
3. Simplify the following code and submit it in writing. Submit the simplified code and display effect.
*[1m*[4m*[5m*[33;45;31mA*[0m*[44;45;32mB*[0m*[42;32mC*[0m
The correct answer is
Code *[1;4;5;31;45mA*[0;45;32mB*[42mC*[m
Effect ABC
Everyone’s answers to this question are varied@@..Only three students really got it right. If not
I am very familiar with the ANSI display method and it is basically impossible to get it right.
Let’s talk about the main issues
For the optimization of A, just merge several items ending in m. Basically, there will be no problem.
For the optimization of B, some students wrote *[0m*[45;32m or *[m*[45;32m
In fact, those that also end with *[?m can be merged, but there is one thing to note: *[0m*[45;32m
Although it looks similar to *[m*[45;32m, the display effect is different.
However, when simplifying the code, specific problems should be analyzed in detail.
For the optimization of C, many students use *[0m to restore the original state. In fact, it is not necessary.
Because the foreground colors of B and C are the same, and B is not highlighted, you just need to change the background color.
So when do you need to use *[0m to restore the display? Usually the current character is highlighted.
Underline flashes and we use this character when the next character does not need these characteristics.
Another situation is to reduce the code. If you need to change the foreground and background color at the same time to *[0;40;37m
When we use *[0m instead of *[40;37m, we need to pay attention to the issue of high and low brightness.
Don’t be discouraged if you don’t do well in this assignment. In fact, everyone has some problems to one degree or another.
Only three students from daviddvd change NSgan did it completely right. If you practice more, you will be able to do it well:
Regarding the significance of code standards, I won’t list everyone’s homework. Everyone has a certain understanding.
I'm just here to talk about my views
Code standardization is divided into two parts. One is simplification and the other is standardization. Simplification is standardization.
A part of normalization. Because normalization can only be done manually, works that remove useless code
The workload of simplification is relatively small. The benefit of standardization is the display effect of works under different terms.
The same, this ensures the best display effect of ANSI works and the readability of standardized code.
Strong This brings convenience to manual modification
Pay attention to what is standard code
1. There is no waste code. Use ";" to write the same settings.
1.1 There are no more attribute settings than *[41;43m, which should be replaced by *[43m
1.2 Do not set the same attribute repeatedly. For example, *[33mA*[33mB should be replaced by *[33mAB
1.3 The foreground setting of adjacent spaces is ignored. If A*[31m *[33mB, replace it with A*[33m B
2. Set high and low brightness at the beginning of the row
Using the default display method will cause differences in highlighting effects. If the first line is
If a character is a low-brightness character, it should also be set with *[0m
3. Use *[m at the end of each line
Why is it *[m at the end instead of *[0m?
*[0m is to restore all special states *[1m *[4m *[5m and *[7m later
Display in low light mode *[m is to restore the above special state. Press the term default setting later.
show
Use *[0m then the low light effect will affect the next line. This is in ANSI works
Turning pages will cause differences in display effects.
4. Use *[0m in the line and less *[m
After using *[m, you need to pay attention to whether the high and low brightness effects are set correctly.
5. When a line of code exceeds 255, try to streamline the code and use less shifting.
Although shifting can perfectly express the work, many novices cannot copy it correctly.
If it is really impossible to streamline your work, you can consider revising it. If
If you copy someone else's work, you can only consider shifting it:
By the way, the code copied directly by AnsiEditor ends with *[0m
When you want to remove useless code from a work, the trickier way is to copy it to AE first.
Then copy it to yaae that comes with Fterm. This code will be more streamlined and standardized:
Here’s a list of everyone’s homework
1.*[1;4;5;45;31mA*[0;45;32mB*[0;42;32mC*[0m
There are 10 people who answered this question, and only two of them used *[m instead of *[0m at the end.
2.*[1;4;5;45;31mA*[0m*[45;32mB*[0m*[42;32mC*[0m
*[1;4;5;45;31mA*[m*[45;32mB*[m*[42;32mC*[m
There are 9 students who answered this question, six in the first category and three in the second category.
3.*[1;4;5;45;31mA*[0m*[45;32mB*[42;32mC*[0m
*[1;4;5;45;31mA*[0;45;32mB*[42;32mC*[0m
There are four classmates here
4.*[1;4;5;45;31mA*[0m*[45;32mB*[42mC*[0m
*[1;4;5;31;45mA*[m*[32;45mB*[42mC*[m
This is closer to the standard answer. Only two students
There are some small problems with the homework of the following students:
Redleaves *[1;4;5;33;45;31mA*[m*[45;32mB[m*[42;32mC*[m
Of these two, only the second one works. The first one should be removed.
fifiisgenius *[1;4;5;33;45;31mA*[44;45;32mB*[42;32mC*[m
One of these two should also be removed.
every *[1;4;5;31mA*[0;32mBC*[m
This is completely wrong
happyif *[1;4;5;45;31mA*[0m*[45;32mB*[0m*[42m *[0m
This guy ignored the last C. In fact, the same color in the foreground and background is often used to hide signatures.
You can’t see it but it’s needed
rabitzhang *[4m*[5;1;45;31mA*[0;45;32mB*[42;32mC*[m
*[4m can be merged with the following ones
Source: Sun and Moon Guanghua bbs.fudan.edu.cn [FROM: 218.83.252.199]