Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
. corn popcorn wheat born corner
記憶:1. corn [ kC:n ] n. <美>玉米The young corn is delicious.嫩玉米非常可口。
2. popcorn [ 5pCpkC:n ] n. 爆米花 Popcorn is popular with various people.爆米花受到各種人的歡迎。
3. wheat [ wi:t, hw- ] n. 小麥 Bread is mainly made from wheat.面包主要是用小麥做的。
4. born [ bC:n ] adj. 天生的, 出生 Could you tell me when Luxun was born?你能告訴我魯迅是什么時(shí)候出生的嗎?
5. corner [ 5kC:nE ] n. 角落, (街道)拐角處, 偏僻處, 困境vt.使陷入絕境, 把...難住Children’s Day is just around the corner. 兒童節(jié)就要到了。around the corner 很快的,臨近的 in the corner在角落里 at/on the corner在拐角處
另類閱讀:The born cook in the corner can cook corn and wheat in scores of ways.
2. correct correction incorrect direct direction indirect rectangle
記憶:詞根rect [ 5rektE ]含義是“正,直”
1. cor是con的變體,correct [ kE5rekt ] adj.正確的 vt. 糾正 You should correct the mistakes in your writing.你應(yīng)糾正你寫(xiě)作中的錯(cuò)誤。
2. correction [ kE5rekFEn ] n. 糾正 The correction is necessary for our development.在我們的發(fā)展過(guò)程中糾正錯(cuò)誤是必不可少的。
3. incorrect [ 7inkE5rekt ] in-correct adj. 不正確的I’m sorry your answer is incorrect.恐怕你的答案并不正確。
4. direct [ di5rekt, dai5rekt ] di-rect vt. 指導(dǎo)(讓做正確),指點(diǎn) adj. 直接的Who directs the firm these days?現(xiàn)在誰(shuí)當(dāng)導(dǎo)演?
5. direction [ di5rekFEn, dai5rekFEn ] n. 方向,指導(dǎo) The travelers come in all directions.旅客來(lái)自四面八方。
6. director [ di5rektE, dai5rektE ] n. 主任, 主管, 導(dǎo)演 Mr. Zhang Yimou has set up his status as a successful director.張藝謀先生作為一名成功的導(dǎo)演已確立了他的地位。
7. indirect [ 7indi5rekt, indai5rekt ] adj. 間接的 The teacher just gave us an indirect answer.老師只是給了我們一個(gè)間接的回答。
8. rectangle [ 5rektAN^l ] rect-angle(角)n. 正方形(四個(gè)角都是直角) Can you draw a rectangle with one hand and a circle with the other?你能一手畫(huà)方一手畫(huà)圓嗎?
另類閱讀:After the boy corrected the rectangle he drew, the teacher saw no incorrect lines. She praised him and gave him more directions.
3. success succeed successful successfully unsuccessful successor excess proceed process procedure access accessible
記憶:1. 詞根ced, ceed, cess, 含義是“行,讓步”前綴suc 即sub的變體,下面,success [ sEk5ses ] 走在了下面,成功, Everyone is after success. But success belongs to those who use both his hands and brains.每個(gè)人都在追逐成功,但成功屬于那些既動(dòng)手又動(dòng)腦的人。
2. succeed [ sEk5si:d ] vi, 成功, 繼...之后, 繼任 注意: succeed in doing something. Finally we succeeded in getting to the top.最后我們成功地到達(dá)了頂峰。
3. successful [ sEk5sesful ] adj. 成功的 Many factors make a successful writer.多種因素造就了一名成功的作家。
4. successfully [sEk5sesfJlI] adv. 成功地 China has launched manned space travel successfully.中國(guó)已成功地進(jìn)行了載人太空飛行。
5. unsuccessful [ 5QnsEk5sesful ] adj. 不成功的 The project turned out to be unsuccessful.那項(xiàng)工程結(jié)果并不成功。
6. successor [ sEk5sesE ] n.繼承者, 接任者, 后續(xù)的事物 The successors of the films are not all successful. 電影的續(xù)集并非都成功。
7. ex- 表示“out”, excess [ ik5ses, 5ekses ] n. & v. 過(guò)度,超過(guò) The noise is in excess of what we can stand.我們受不了那噪音。
8. pro- 表示“向前” proceed [ prE5si:d ] To go forward or onward, especially after an interruption vi.進(jìn)行, 繼續(xù)下去, 發(fā)生 The speech contest proceeded. 演講比賽繼續(xù)。
9. process [ prE5ses ] A series of actions, changes, or functions bringing about a result n. 過(guò)程, 作用, 方法 vt.加工, 處理 I’m afraid the process is too complicated for you.恐怕這種方法對(duì)你過(guò)于復(fù)雜。
10. procedure [ prE5si:dVE ] A manner of proceeding n.程序, 手續(xù) Finishing the procedure, he felt too tired. 完成手續(xù)后,他感到太累。
11. access [ 5Akses ] ac-cess n. 通路, 訪問(wèn), 入門(mén) vt.存取, 接近 No access to the house is given to common civilians.普通人不許進(jìn)那房子。
12. accessible [ Ek5sesEbl ] adj. 易接近的, 可到達(dá)的, 易受影響的, 可理解的 The palace is not accessible for us.那宮殿我們?nèi)ゲ涣恕?/p>
4.cough fever headache backache suffer suffering ill illness sick sickness dizzy disease patient patience bacterium virus
記憶:1. cough [ kC:f ] co,音“咳”,咳嗽 Every one of us has ever suffered from cough.我們每個(gè)人咳嗽過(guò)。
2. fever [ 5fi:vE ] n. 發(fā)燒, 發(fā)熱, 狂熱 The boy is running a high fever. Send for a doctor at once!孩子在發(fā)高燒。馬上找醫(yī)生來(lái)!
3. headache [5hedeIk] n.頭疼 Is the war in Iraq a glory or a headache for Jorge W Bush?伊拉克戰(zhàn)爭(zhēng)對(duì)布什來(lái)說(shuō)是榮光還是頭疼?
4. backache [5bAkeIk] n. 背疼 The backache makes it hard to turn over.背疼之后,翻身不便。
5. suffer [ 5sQfE ] suf-fer vt.遭受, 經(jīng)歷, 忍受 vi.受痛苦, 受損害 Whenever a war breaks out, it’s the civilians who suffer.每一場(chǎng)戰(zhàn)爭(zhēng)都是老百姓遭殃。
6. suffering [ 5sQfEriN ] n. 痛苦 Who brought all these sufferings to the ordinary people?是誰(shuí)把這些痛苦加在老百姓身上的?
7. ill [ il ] adj. 有病的(作表語(yǔ)), 壞的, 惡意的 Hearing the ill boy fell ill, we couldn’t help having a pity over him.聽(tīng)說(shuō)那個(gè)愛(ài)搗亂的男子病倒了,我們還是忍不住同情他。
8. illness [ 5ilnis ] Disease of body or mind; poor health n. 病 The leaves of it can help cure many illnesses. 它的葉子有助于治療多種疾病。
9. sick [ sik ] adj. 不舒服, 有病的, 惡心的, 厭惡的 I’m sick of his dull and empty talk. 對(duì)討厭他的空洞單調(diào)的講話。
10. sickness [ 5siknis ] The condition of being sick; illness n. 病 Fortunately his sickness is not serious.幸運(yùn)的是他的病不嚴(yán)重。
11. disease [ di5zi:z ] ease, 安逸, 安心 disease, 不安逸,有病 n. 病 Doctors deal with physical diseases. Then, who can deal with social diseases?醫(yī)生解決身體毛病,那么,誰(shuí)能解決社會(huì)毛病?
12. dizzy [ 5dizi ] 聯(lián)想disease, 有病的人頭暈的。 adj. 暈眩的, 昏亂的 Looking down from the tower top, I found myself dizzy.在塔頂上往下看,我頭暈?zāi)垦!?/p>
13. patient [ 5peiFEnt ] n. 病人, 患者 adj. 忍耐的, 耐心的 The doctor is supposed to be patient to any patient.醫(yī)生對(duì)任何病人都應(yīng)該有耐心。
14. patience [ 5peiFEns ] n. 耐心 Patience is one of the conditions of the final success. 耐心是最終成功的條件之一。 格言: Patience is a virtue.耐心即是寶。
15. bacterium [ bAk5tiEriEm ] n. 細(xì)菌 注意復(fù)數(shù):bacteria Bacteria are almost everywhere.細(xì)菌幾乎無(wú)處不在。
16. virus [ 5vaiErEs ] n. 病毒 People have found the virus causing SARS.人們發(fā)現(xiàn)了引起非典的病毒。
5.count counter account accountant discount county country
記憶:1. count [kaJnt] n. 數(shù), 計(jì)算 Having counted the books, he realized they were far from enough.他數(shù)完書(shū)后,意識(shí)到它們遠(yuǎn)遠(yuǎn)不夠。
2. counter [ 5kauntE ] n.計(jì)算器, 計(jì)數(shù)器, 計(jì)算者, 柜臺(tái) The customer can drink by the counter of the bar.顧客可在在酒吧的柜臺(tái)邊喝酒。
3. account [ E5kaunt ] ac-count n.計(jì)算, 帳目, 說(shuō)明, 理由 vi. 說(shuō)明 The accounts are very clear. 帳目非常清楚。He paid the money into his bank account.
4. accountant [ E5kauntEnt ] account-ant n.會(huì)計(jì)(員), 會(huì)計(jì)師 The accountant’s innocence has been proved once more.會(huì)計(jì)的清白又一點(diǎn)得到證實(shí)。
5. discount [ 5diskaunt ] dis-count n.折扣 The more you buy, the larger discount we can offer. 你買得越多,我們給你打折越多。
6. country [ 5kQntri ] n. 國(guó)家, 國(guó)土 It’s everyone’s duty to protect his country. 保衛(wèi)祖國(guó),匹夫有責(zé)。
7. county [ 5kaunti ] n. 縣 Shuangliu is one of the richest counties in Sichuan Province.雙流是四川省最富的縣之一。
6.course cause result consequence effect effective affect affection perfect influence effort
記憶:1. course [ kC:s ] n. 過(guò)程, 進(jìn)程, 路線, 課程, 一道菜 He was quite doubtful during the course of the experiment.在實(shí)驗(yàn)過(guò)程中他一直都很懷疑。
2. cause [ kC:z ] n. 原因, 事業(yè) vt.引起 What caused him to act so rashly?什么東西使得他行動(dòng)如此草率?
3. result [ ri5zQlt ] n. 結(jié)果, 成效, 計(jì)算結(jié)果 vi. 起因, 由于, 導(dǎo)致 result in以...為結(jié)果,result from 起因于 What you are today is the result of what you did yesterday.你今天的狀況是你昨天行動(dòng)的結(jié)果。
4. consequence [ 5kCnsikwEns ] con-sequ-ence 詞根sequ, 即follow, consequence, 跟在后面的, n.結(jié)果, 推理 If you continue this way, you must consider its consequence.如果你繼續(xù)這樣,你要考慮它的后果。
5. effect [ i5fekt ] 詞根fect 含義為“做,創(chuàng)造”,前綴e-, 表示“出”,effect, 做出來(lái)的,n.結(jié)果, 效果, 作用, 影響 The medicine has no effect on my cold.這種藥對(duì)我的感冒不起作用。
6. effective [ i5fektiv ] adj. 有效的 Some effective measure must be taken at once.必須馬上采取有效措施。
7. affect [ E5fekt ] 前綴af-即ab-的變體,vt.影響, 感動(dòng) When we are quiet in heart, nothing outside can affect us.心靜自然涼。
8. affection [ E5fekFEn ] n.友愛(ài), 愛(ài)情, 影響 How can I show my deep affection to her?我怎樣才能表達(dá)對(duì)她的深深愛(ài)戀呢?
9. perfect [ 5pE:fikt ] 前綴per- 表示“完成”,perfect,做完了的,完美的 Nothing is perfect and nobody is perfect.金無(wú)赤足,人無(wú)完人。
10. influence [ 5influEns ] in-flu-ence, 詞根flu表示“流動(dòng)”,influence, 在里面流過(guò),有影響,n.影響 vt.影響, 改變 His experiences in his childhood influenced him more than anything else.他童年時(shí)代的經(jīng)歷對(duì)他影響最大。
11. effort n. 努力 Great efforts should be made to ensure the project goes on well.應(yīng)該付出努力保證工程的順利進(jìn)行。
7.cover discover discovery discoverer uncover expose betray detect detective recover lid
記憶:1. cover [ 5kQvE ] n. 蓋子, 封面 vt. 覆蓋,報(bào)道 What do you think of the phenomenon that beautiful women take up nearly all magazine covers? 美女幾乎占據(jù)了所有的雜志封面,你對(duì)這一現(xiàn)象怎么看? 格言:You can't tell a book by its cover. 不能以貌取人。
2. discover [ dis5kQvE ] vt. 發(fā)現(xiàn), 發(fā)覺(jué) Some people doubt whether it is Columbus who first discovered America.一些人懷疑是不是由哥倫布首先發(fā)現(xiàn)美洲的。
3. discovery [ dis5kQvEri ] n. 發(fā)現(xiàn) His discovery resulted in a industrial revolution.他的發(fā)現(xiàn)引起了一場(chǎng)工業(yè)革命。
4. discoverer [ dis5kQvErE ] n. 發(fā)現(xiàn)者 Who was the discoverer of Radium?誰(shuí)是鐳的發(fā)現(xiàn)者?
5. uncover [ Qn5kQvE ] vt.揭開(kāi), 揭露 Uncovering the basket, she was moved to find her favorite fish there.她揭開(kāi)籃子,發(fā)現(xiàn)里面是她最愛(ài)吃的魚(yú),很受感動(dòng)。
6. recover [ ri5kQvE ] re-cover vi. 痊愈, 復(fù)原 I hope you can recover soon.我希望你很快康復(fù)。
7. expose [ iks5pEuz ] 詞根pose表示“放”;ex-, 外;expose, 放在外面,vt.使暴露, 使曝光 As a reporter, I think it’s my duty to expose the scandal and praise the kindness.作為記者,我認(rèn)為我有責(zé)任揚(yáng)善懲惡。
8. betray [ bi5trei ] be-tray vt.出賣, 背叛, 泄露 When you betray your motherland, you are not worthy of being human.如果你背叛祖國(guó),你就不是人。
9. detect [ di5tekt ] 詞根tect含義是“遮蔽,掩蓋”;前綴de-含義為“反,去”,detect, 去掉遮掩,探測(cè),偵探 In my childhood, I dreamed that I could invent some equipment to detect mushrooms in the wild.童年時(shí)候,我夢(mèng)想我能發(fā)明一種設(shè)備來(lái)探測(cè)野外的蘑菇。
10. detective [ di5tektiv ] n. 偵探 Holms is the best-known detective. However, he was not a real man.福爾摩斯是最有名的偵探,但他卻非真人。
11. protect [ prE5tekt ] 前綴pro-為“先”,事先遮蓋起來(lái),保護(hù) Everyone should form the sense of protecting life, no matter whose it is.每個(gè)人都應(yīng)有保護(hù)生命的意識(shí),不論那是誰(shuí)的生命。
12. lid [ lid ] n. 蓋子 Sorry, but the lid refuses to be removed. 對(duì)不起,但蓋子挪不動(dòng)。
8;cream scream stream butter milk yoghurt
記憶:1. cream [ kri:m ] n. 乳酪, 奶油, (護(hù)膚)面霜 Cream is rich in fat. You’d better not have too much.奶油富含脂肪,你最好不要吃得太多。
2. scream [ skri:m ] v. 尖聲叫, 尖聲喊叫 n. 尖叫聲, 喊叫聲 The girl screamed at the sight of the snake.一看到蛇,女孩驚叫起來(lái)。
3. stream [ stri:m ] n. 溪, 川, 流, 一股 The water in that stream is quite clear and sort of sweet.那小溪里的水清徹見(jiàn)底,有點(diǎn)甜。
4. butter [ 5bQtE ] n. 黃油, 牛油 The birthcake is covered with butter.生日蛋糕上面覆蓋著一層黃油。
5. milk [ milk ] n. 乳, 牛奶 v. 擠(奶) A cup of milk a day keeps the doctor away.一天一杯牛奶,醫(yī)生不用再見(jiàn)。
6. yoghurt [`jC^Et,`jEJ-] n. 酸乳 Yoghurt has become popular because of its special taste.酸乳因其味道獨(dú)特而受人喜愛(ài)。
9. crop drop stop fall fell felt
記憶:1. crop [ krCp ] n. 農(nóng)作物 vt. 收割 Not every farmer lives on crops.并非每個(gè)農(nóng)民都以莊稼為生。
2. drop [ drCp ] d, 音“滴,掉”,v.滴下, 落下 n. 落下, 下降, 滴 You can’t drop English though your English is quite poor at present.雖然你目前英語(yǔ)差,但是你不能放棄英語(yǔ)。
3. drip [ drip ] n. 水滴 v. (使)滴下 Some water is dripping from the roof.一些水正從屋頂上滴下來(lái)。
4. stop [ stCp ] n. 停止, 車站 vi. 停止 Nobody can stop me loving my country. 沒(méi)人能阻攔我愛(ài)我的祖國(guó)!
5. fall [ fC:l ] n. 秋天, 落下 vi. 倒下, 落下 Four fools fell asleep on a fall afternoon. 在一個(gè)秋天下午四個(gè)傻瓜睡著了。 fall to the ground掉到地上 fall off sth從……上掉下來(lái) fall ill生病了 fall asleep睡著了 fall in love with sb愛(ài)上
6. fell [ fel ] vt. 砍伐 How can you fell so many trees at a time?你一次怎能砍倒那么多樹(shù)?
7. felt [ felt ] feel的過(guò)去式,感到 I felt embarrassed when I saw her.我看到她時(shí)感到有些尷尬。
10. crowd crowded squeeze coward people population popular populous
記憶:1. crowd [ kraud ] n. 人群, 一堆(東西), 一伙 v. 群集, 擁擠 Don’t crowd! Wait in line and everyone can get what he wants.別擠!排好隊(duì),每個(gè)人都能得到他想要的東西。
2. crowded [ 5kraudid ] adj. 擁擠的, 塞滿的 The buses used to be too crowded when holidays came.過(guò)去當(dāng)假期來(lái)臨的時(shí)候,公共汽車曾很擁擠。
3. squeeze [ skwi:z ] v. 壓榨, 擠, 擠榨 Don't squeeze my finger. It hurts!別擠壓我的手指,很疼!
4. coward [ 5kauEd ] cow, 奶牛;d, 音“倒”, coward, 看見(jiàn)溫順的奶牛呵也倒的人,膽小鬼;n.懦弱的人, 膽小的人 A young rat scared him so! I have never seen such a coward.一只小老鼠就把他嚇成這樣!我從來(lái)沒(méi)有見(jiàn)過(guò)這樣膽小的人。
5. people [ 5pi:pl ] n. 人們 The government should be of the people, by the people and for the people.政府應(yīng)是民有,民治,民享。
6. population [ 7pCpju5leiFEn ] popul表示人;population, 人口 What’s the population in your hometown? 你家鄉(xiāng)有多少人?
7. 加形容詞后綴-ar, popular [ 5pCpjulE ] adj. 通俗的, 流行的, 受歡迎的 When scientists are more popular than the singers with the young, the nation will be unconquerable. 如果科學(xué)家比歌手更受年輕人歡迎,那么這個(gè)民族是不可戰(zhàn)勝的。
8. 加表示“充滿”的形容詞后綴-ous, populous [ 5pCpjulEs ] adj. 人口多的, 人口稠密的 Big cities are often populous.大城市常常人口稠密。
11. slave slavery cruel cruelty savage kind mercy merciful
記憶:1. slave [ sleiv ] n. 奴隸 Slaves should be liberated both politically and mentally.奴隸既要從政治上解放,也要從精神上解放。 格言: Do business,but be not a slave to it.要做事,但不要做事務(wù)的奴隸。
2. slavery [ 5sleivEri ] n. 奴隸身分, 奴隸制度 The slavery should be abolished completely.應(yīng)該徹底廢除奴隸制。
3. cruel [ 5kruEl ] 音似“刻肉”,在肉體上刻劃,殘酷;adj. 殘酷的, 悲慘的 What made a young boy with such a cruel heart?什么東西使得一個(gè)小男孩心腸如此殘忍?
4. cruelty [5kru:EltI] n. 殘忍, 殘酷 The mercy on the devil is the cruelty to the kind.對(duì)壞人的同情就是對(duì)好人的殘忍。
5. savage [ 5sAvidV ] sav-age sav-音似“殺無(wú)”,殺的一個(gè)不留,野蠻兇狠 adj. 野蠻的, 兇猛的, 殘忍的 Be careful of the savage in the area.當(dāng)心這一帶的野人。
6. kind [ kaind ] adj. 善良的 The kind shouldn’t be regard as the weak.善良不應(yīng)被看作是軟弱。 be kind to sb It’s kind of sb to do sth
7. mercy [ 5mE:si ] mer-cy聯(lián)想:妹兒是有同情心的, n. 仁慈, 寬恕, 憐憫 Have mercy on others and you will get more in the future.對(duì)別人有同情心,你將得到更多的回報(bào)。
8. merciful [ 5mE:siful ] adj. 仁慈的, 慈悲的 A merciful heart is to be treasured.應(yīng)珍惜仁慈之心。
12. cry tear sob weep laugh laughter smile
記憶:1. cry [ krai ] vi. 哭, 流淚 n. 叫, 喊 n. 哭泣, 喊聲 It’s no use crying over spilt milk.后悔無(wú)用。
2. tear [ tiE ] n. 眼淚, vi. 流淚, 撕破 [tZE] vt. 扯, 撕 Life doesn’t believe tears.生活不相信眼淚。
3. sob [ sCb ] n. 嗚咽, 哭泣 n. 嗚咽, 哭泣 The boy is still sobbing. He will get better soon.男孩還在抽泣。他不久會(huì)好一些。
4. weep [ wi:p ] n. 哭, 哭泣, 滴下 vi. 哭泣, 流淚 A healthy society never allows a hero weeping.一個(gè)健康的社會(huì)絕不會(huì)讓英雄流淚。
5. laugh [ lB:f ] vi. 笑, 譏笑 Laughing help keeping us healthy.大笑有助于我們的健康。 格言: He laughs best who laughs last. 最后笑的人笑得最好。
6. laughter [ 5lB:ftE ] n. 笑, 笑聲 burst into laughter 突然大笑起來(lái) Her laughter is my greatest delight.她的笑聲是我最大的歡樂(lè)。 格言: Laughter is the best medicine.笑聲是最佳的藥。
7. smile [ smail ] n.& vi. 微笑 When you smile, the life smiles, too.你笑的時(shí)候,生活也在笑。
13. cup glass glasses cut carve sculpture split
記憶:1. cup [ kQp ] n. 杯子, 酒杯, 獎(jiǎng)杯 vt.使成杯狀 Fetch me another five cups, please.請(qǐng)?jiān)俳o我取五個(gè)杯子來(lái)。
2. glass [ ^lB:s ] n. 玻璃, 玻璃制品, 玻璃杯 The crystal palace is made of glass.水晶宮是用玻璃做的。
3. glasses n. 眼鏡 The man with a pair of thick glasses is a professor from Tsinghua University.帶深度眼鏡的那個(gè)人是來(lái)自清華大學(xué)的教授。
4. cut [ kQt ] vt. 切(割、削), 剪, n.削減, 刪節(jié), 傷口, 切口 Wrap your cut with this bandage quickly. 快點(diǎn)用這繃帶把你的傷口包起來(lái)。
5. carve [ kB:v ] vt. 雕刻, 切開(kāi) He carved a face in the trunk. 他在樹(shù)干上雕刻了一張臉。
6. sculpture [ 5skQlptFE ] cu, 音似“刻”n. 雕刻, 雕刻品, 雕塑, 雕塑品 The city sculptures are another attraction to me.城市雕塑是另一個(gè)吸引我的地方。
7. split [ split ] p, 音“劈”,v. 劈開(kāi) n. 裂開(kāi), 裂痕 The woodcutter split the trunk into halves.樵夫把樹(shù)干劈成了兩半。
14. danger dangerous emergency safety safe safely save rescue secure security
記憶:1. danger [ 5deindVE ] n. 危險(xiǎn), 危險(xiǎn)物 Look out! There is danger ahead.小心,前面有危險(xiǎn)!
2. dangerous [ 5deindVrEs ] adj. 危險(xiǎn)的 The tiger in danger is still a dangerous animal.處于危險(xiǎn)境地的老虎仍是危險(xiǎn)的動(dòng)物。
3. emergency [ i5mE:dVnsi ] emerg-ency emerge,出現(xiàn);emergency, 突然出現(xiàn) n. 緊急情況, 突然事件 The special police forces keep alert all the time in case of any emergency.特種警察部隊(duì)一直保持著警惕,以防任何緊急情況的出現(xiàn)。
4. emerge [ i5mE:dV ] vi. 顯現(xiàn), 浮現(xiàn), (由某種狀態(tài))脫出, (事實(shí))顯現(xiàn)出來(lái) The truth will emerge sooner or later.真相盡早出浮出水面。
5. safe [ seif ] adj. 安全的 n. 保險(xiǎn)箱 Precautious attacking can’t keep the county really safe.先發(fā)制人并不能真正保證國(guó)家的安全。
6. safely [`seIflI] adv. 安全地 The ship landed safely in the end.船最后平安靠岸了。
7. safety [ 5seifti ] n. 安全,安全地帶 He hurried to take the boy to safety.他急忙把孩子帶到安全地帶。
8. save [ seiv ] vt. 解救, 保存, 節(jié)省, 儲(chǔ)蓄 vi. 挽救, 節(jié)省 prep. 除...之外 How can I thank you enough for saving my life?你救了我的命,我真不知該怎樣感謝你。 格言:Saving is getting. 節(jié)省就是獲得。
9. rescue [ 5reskju: ] vt. & n. 援救, 營(yíng)救 The firemen have tried their best to rescue the man trapped 消防隊(duì)員已盡了力去營(yíng)救受困的那個(gè)人。
10. secure [ si5kjuE ] se-cure, 治好的, adj. 安全的, 可靠的 You may be relaxed now. The secret is absolutely secure.你可以放松點(diǎn)。那個(gè)秘密絕對(duì)安全。
11. security [ si5kjuEriti ] n.安全 National security is the first matter for any government.國(guó)家安全是任何政府的首要問(wèn)題。
15. dare daring afraid fright frighten frightened fear fearful
記憶:1. dare [ dZE ] vi. 敢, 膽敢 He dares to challenge any famous singer.他敢于向任何著名的歌手折挑戰(zhàn)。
2. daring [ 5dZEriN ] adj. 大膽的 The daring words surprised his parents.那番大膽的話讓他父母吃了一驚。
3. afraid [ E5freid ] adj. 害怕, 擔(dān)心 I’m afraid to see his angry face.我不敢看他生氣的臉。
4. fear [ fiE ] n. 恐怖, 害怕, 擔(dān)心 v. 害怕, 畏懼 What I fear is not bears but tears.我怕的不是大笨熊,而是眼淚。 格言:Fear of death is worse than death itself. 對(duì)死亡的恐懼比死亡本身更可怕。
5. fearful [ 5fiEful ] adj. 可怕的, 恐怕的 A dark night may be fearful for a lonely girl.也許對(duì)一個(gè)孤獨(dú)的女孩來(lái)說(shuō),漆黑的夜晚是可怕的。
6. fearless [5fIElIs] adj. 勇敢的, 無(wú)畏的 Mandela is a fearless fighter to get rid of racial discrimination.曼德拉為消除種族歧視進(jìn)行了無(wú)畏的戰(zhàn)斗。
7. fright [ frait ] f+right 不對(duì)的,讓人驚駭?shù)?n. 驚駭, 吃驚 The fright on his face is quite obvious.他臉上的驚訝感十分明顯。
8. frighten [ 5fraitn ] vt. 使驚嚇 Don't frighten the boy with your disgusting story!別用你那討厭的故事嚇住孩子。
9. frightened [5fraIt(E)nd] adj. 受驚的, 受恐嚇的 It’s strange that I should find myself frightened at that time.真奇怪,那時(shí)候我居然很害怕!
記單詞有困難的同學(xué),推薦學(xué)習(xí)《奇速英語(yǔ)24個(gè)故事串記中學(xué)3500詞匯》 ,讓你在輕松愉快的故事中掌握單詞的讀音、漢語(yǔ)意思和拼寫(xiě)哦!單詞逆襲鏈接:
24個(gè)故事第一講鏈接:http://v.qq.com/page/g/s/7/g0139goxls7.html
24個(gè)故事第二講鏈接:http://v.qq.com/page/y/4/7/y0140zjnc47.html ;
24個(gè)故事第三講鏈接:http://v.qq.com/page/c/a/c/c0140y0r0ac.html
奇速英語(yǔ)官方旗艦店:http://abc366.taobao.com
記得小時(shí)候的萬(wàn)花尺吧?這么畫(huà):
一點(diǎn)也不費(fèi)腦筋,就可以出來(lái)這么多豐富多彩的復(fù)雜幾何圖形。
具體而言,可以用萬(wàn)花尺玩具(如圖2-1所示)來(lái)繪制數(shù)學(xué)曲線。這種玩具由兩個(gè)不同尺寸的塑料齒輪組成,一大一小。小的齒輪有幾個(gè)孔。把鋼筆或鉛筆放入一個(gè)孔,然后在較大齒輪(內(nèi)部有齒)內(nèi)旋轉(zhuǎn)里面的小齒輪,保持筆與外輪接觸,可以畫(huà)出無(wú)數(shù)復(fù)雜而奇妙的對(duì)稱圖案。
圖2-1 萬(wàn)花尺
現(xiàn)在,在電腦里,用Python也可以這么玩了,讓我們看看Python的萬(wàn)花尺效果吧。(不用急,程序在后哦)
$ python spiro.py
默認(rèn)情況下,spiro.py程序繪制隨機(jī)螺線,如圖2-5所示。按S鍵保存繪制。
圖2-5 spiro.py的運(yùn)行示例
再次運(yùn)行程序,這次在命令行傳入?yún)?shù),畫(huà)出特定的螺線。
$ python spiro.py --sparams 300 100 0.9
圖2-6展示了輸出結(jié)果。如你所見(jiàn),這段代碼根據(jù)用戶指定的參數(shù)繪制了一條螺線,圖2-5和它不同,展示了幾個(gè)隨機(jī)螺線的動(dòng)畫(huà)。
圖2-6 用具體參數(shù)運(yùn)行spiro.py的示例
這么神奇又好玩的萬(wàn)花尺,在Python里怎么玩呢?
不要走開(kāi),讓我們繼續(xù)下面的Python之旅。
在這個(gè)項(xiàng)目中,我們將用Python來(lái)創(chuàng)建動(dòng)畫(huà),像萬(wàn)花尺一樣繪制曲線。我們的spiro.py程序?qū)⒂肞ython和參數(shù)方程來(lái)描述程序的萬(wàn)花尺齒輪的運(yùn)動(dòng),并繪制曲線(我稱之為螺線)。我們可以將完成的畫(huà)圖保存為PNG圖像文件,并用命令行選項(xiàng)來(lái)指定參數(shù)或生成隨機(jī)螺線。
在這個(gè)項(xiàng)目中,我們將學(xué)習(xí)如何在計(jì)算機(jī)上繪制螺線。還將學(xué)習(xí)以下幾點(diǎn):
在本節(jié)中,你將看到用參數(shù)方程來(lái)畫(huà)圓的簡(jiǎn)單例子。參數(shù)方程將曲線上點(diǎn)的坐標(biāo)表示為一個(gè)變量的函數(shù),該變量稱為參數(shù)。參數(shù)方程讓繪制曲線變得容易,因?yàn)橹灰獙?shù)代入方程就能產(chǎn)生曲線。
注意
如果你現(xiàn)在不想學(xué)習(xí)這部分?jǐn)?shù)學(xué)知識(shí),可以跳到下一部分,討論針對(duì)萬(wàn)花尺項(xiàng)目的方程。
我們開(kāi)始考慮用半徑 r 來(lái)描述一個(gè)圓的方程,圓心位于二維平面的原點(diǎn)。 x 、 y 坐標(biāo)滿足該方程的所有點(diǎn)構(gòu)成了圓。
現(xiàn)在,請(qǐng)考慮下面的方程:
x=r cos( θ )
y=r sin( θ )
這些方程是圓的參數(shù)表示,其中角 θ 是參數(shù)。這些方程中(X,Y)的任何值,都滿足前面描述的圓的方程,X 2 + Y 2=R 2 。如果讓 θ 從0變到2π,可以用這些方程來(lái)計(jì)算圓上對(duì)應(yīng)的 x 和 y 坐標(biāo)。圖2-2展示了這種方案。
圖2-2 用參數(shù)方程描述圓
記住,這兩個(gè)方程適用于圓心在坐標(biāo)系原點(diǎn)的圓。將圓心轉(zhuǎn)換到點(diǎn)( a , b ),就可以將圓置于 xy 平面的任何位置。所以更一般的參數(shù)方程就變成 x=a + r cos( θ )和 y=b + r cos( θ )。現(xiàn)在,讓我們來(lái)看看描述螺線的方程。
圖2-3展示了類似萬(wàn)花尺運(yùn)動(dòng)的數(shù)學(xué)模型。該模型沒(méi)有齒輪,因?yàn)橥婢咧械凝X輪只是為了防止打滑,而在這里不必?fù)?dān)心打滑。
圖2-3 萬(wàn)花尺數(shù)學(xué)模型
在圖2-3中,C是較小的圓的圓心,P是筆尖。較大的圓半徑為 R ,較小的圓半徑為 r 。半徑之比表示如下:
將線段PC與小圓半徑 r 之比作為變量l(l=PC / r ),它決定了筆尖離小圓圓心有多遠(yuǎn)。然后,組合這些變量來(lái)表示P的運(yùn)動(dòng),得到如下的參數(shù)方程:
注意
這些曲線稱為內(nèi)旋輪線和外旋輪線。雖然方程可能看起來(lái)有點(diǎn)嚇人,但推導(dǎo)是非常簡(jiǎn)單的。如果你想探索其中的數(shù)學(xué),請(qǐng)參見(jiàn)維基百科。
圖2-4展示了如何用這些方程,基于參數(shù)的變化,產(chǎn)生一條曲線。通過(guò)改變參數(shù) R 、 r 和 l ,可以產(chǎn)生變化無(wú)窮的迷人曲線。
圖2-4 示例曲線
將曲線繪制為一系列點(diǎn)之間的線段。如果這些點(diǎn)足夠接近,圖看起來(lái)就像平滑的曲線。真正玩過(guò)萬(wàn)花尺就知道,這取決于使用的參數(shù),萬(wàn)花尺可能需要許多轉(zhuǎn)數(shù)來(lái)完成。要確定何時(shí)停止繪圖,就要利用萬(wàn)花尺的周期性(即萬(wàn)花尺圖案多久開(kāi)始重復(fù)),研究?jī)?nèi)外圓的半徑之比:
分子分母除以它們的最大公約數(shù)(GCD),化簡(jiǎn)該分?jǐn)?shù),分子就告訴我們需要多少圈才能完成曲線。例如,在圖2-4中,( r , R )的GCD是5。
下面是該分?jǐn)?shù)化簡(jiǎn)后的形式:
這告訴我們,13圈后,曲線將開(kāi)始重復(fù)。44告訴我們小圓圍繞其中心旋轉(zhuǎn)的圈數(shù),它提示了曲線的形狀。在圖2-4中數(shù)一下,會(huì)看到圖形中花瓣或葉的數(shù)目恰好是44!
一旦用簡(jiǎn)化形式表示了半徑比 r / R ,畫(huà)出螺線的參數(shù) θ 范圍就是[0,2πr]。這告訴我們何時(shí)停止繪制特定的螺線。不知道該角度的結(jié)束范圍,就會(huì)循環(huán)不止,不必要地重復(fù)該曲線。
我們可以用Python的turtle模塊來(lái)創(chuàng)建圖案。這是一個(gè)簡(jiǎn)單的繪圖程序,模型是一只海龜拖著尾巴穿過(guò)沙灘,留下圖案。turtle模塊包括了一些方法,用于設(shè)置筆(海龜?shù)奈舶停┑奈恢煤皖伾约捌渌杏玫睦L圖函數(shù)。如你所見(jiàn),只要少量繪圖函數(shù),就可以創(chuàng)建漂亮的螺線。
例如,這個(gè)程序用turtle畫(huà)圓。輸入以下代碼,保存為drawcircle.py,在Python中運(yùn)行它:
import math ① import turtle # draw the circle using turtle def drawCircleTurtle(x, y, r): # move to the start of circle ② turtle.up() ③ turtle.setpos(x + r, y) ④ turtle.down() # draw the circle ⑤ for i in range(0, 365, 5): ⑥ a=math.radians(i) ⑦ turtle.setpos(x + r*math.cos(a), y + r*math.sin(a)) ⑧ drawCircleTurtle(100, 100, 50) ⑨ turtle.mainloop()
在①行,從導(dǎo)入turtle模塊開(kāi)始。接下來(lái),定義drawCircleTurtle()方法,它在②行調(diào)用up()。這告訴Python提筆。換句話說(shuō),讓筆離開(kāi)虛擬的紙,這樣移動(dòng)海龜也不會(huì)畫(huà)圖。開(kāi)始繪圖之前,先定位海龜。
在③行,將海龜?shù)奈恢迷O(shè)置為橫軸上的第一個(gè)點(diǎn):(x + r, y),其中(x,y)是該圓的圓心。現(xiàn)在準(zhǔn)備好畫(huà)圖了,所以在④行調(diào)用down()。在⑤行,利用range(0, 365, 5)開(kāi)始循環(huán),以5為步長(zhǎng)遞增變量i,從0到360,變量i是角度參數(shù),將傳入圓的參數(shù)方程,但首先在⑥行將它從度轉(zhuǎn)為弧度(大多數(shù)計(jì)算機(jī)程序的角度計(jì)算需要弧度)。
在⑦行,利用前面討論過(guò)的參數(shù)方程計(jì)算圓的坐標(biāo),并設(shè)置相應(yīng)的海龜位置,這樣就從海龜上一個(gè)位置畫(huà)線到新計(jì)算的位置(從技術(shù)上講,產(chǎn)生的是N邊多邊形,但因?yàn)橛昧撕苄〉慕嵌龋琋將非常大,多邊形看起來(lái)像一個(gè)圓)。
在⑧行,調(diào)用drawCircleTurtle()來(lái)畫(huà)圓,在⑨行,調(diào)用mainloop(),它保持tkinter窗口打開(kāi),讓你可以欣賞你畫(huà)的圓(Tkinter是Python默認(rèn)的GUI庫(kù))。
現(xiàn)在,我們準(zhǔn)備好畫(huà)一些螺線了!
我們將利用下面的模塊創(chuàng)建螺線:
首先,定義類Sipro,來(lái)繪制這些曲線。我們會(huì)用這個(gè)類一次畫(huà)一條曲線(利用draw()方法),并利用一個(gè)定時(shí)器和update()方法,產(chǎn)生一組隨機(jī)螺線的動(dòng)畫(huà)。為了繪制Spiro對(duì)象并產(chǎn)生動(dòng)畫(huà),我們將使用SpiroAnimator類。
要查看完整的項(xiàng)目代碼,請(qǐng)直接跳到2.4節(jié)。
下面是Spiro構(gòu)造函數(shù):
# a class that draws a Spirograph class Spiro: # constructor def __init__(self, xc, yc, col, R, r, l): # create the turtle object ① self.t=turtle.Turtle() # set the cursor shape ② self.t.shape('turtle') # set the step in degrees ③ self.step=5 # set the drawing complete flag ④ self.drawingComplete=False # set the parameters ⑤ self.setparams(xc, yc, col, R, r, l) # initialize the drawing ⑥ self.restart()
在①行,Spiro構(gòu)造函數(shù)創(chuàng)建一個(gè)新的turtle對(duì)象,這將有助于我們同時(shí)繪制多條螺線。在②行,將光標(biāo)的形狀設(shè)置為海龜(在 https://docs.python.org/3.3/library/ turtle.html ,你可以在turtle文檔中找到其他選項(xiàng))。在③行,將參數(shù)繪圖角度的增量設(shè)置為5度,在④行,設(shè)置了一個(gè)標(biāo)志,將在動(dòng)畫(huà)中使用它,它會(huì)產(chǎn)生一組螺線。
在⑤和⑥行,調(diào)用設(shè)置函數(shù),接下來(lái)討論該函數(shù)。
現(xiàn)在讓我們看看getParams()方法,它幫助初始化Spiro對(duì)象,如下所示:
# set the parameters def setparams(self, xc, yc, col, R, r, l): # the Spirograph parameters ① self.xc=xc self.yc=yc ② self.R=int(R) self.r=int(r) self.l=l self.col=col # reduce r/R to its smallest form by dividing with the GCD ③ gcdVal=gcd(self.r, self.R) ④ self.nRot=self.r//gcdVal # get ratio of radii self.k=r/float(R) # set the color self.t.color(*col) # store the current angle ⑤ self.a=0
在①行,保存曲線中心的坐標(biāo)。然后在②行,將每個(gè)圓的半徑( R 和 r )轉(zhuǎn)換為整數(shù)并保存這些值。在③行,用Python模塊fractions內(nèi)置的gcd()方法來(lái)計(jì)算半徑的GCD。我們將用這些信息來(lái)確定曲線的周期性,在④行將它保存為self.nRot。最后,在⑤行,保存當(dāng)前的角度,我們將用它來(lái)創(chuàng)建動(dòng)畫(huà)。
接下來(lái),restart()方法重置Spiro對(duì)象的繪制參數(shù),讓它準(zhǔn)備好重畫(huà):
# restart the drawing def restart(self): # set the flag ① self.drawingComplete=False # show the turtle ② self.t.showturtle() # go to the first point ③ self.t.up() ④ R, k, l=self.R, self.k, self.l a=0.0 ⑤ x=R*((1-k)*math.cos(a) + l*k*math.cos((1-k)*a/k)) y=R*((1-k)*math.sin(a) - l*k*math.sin((1-k)*a/k)) ⑥ self.t.setpos(self.xc + x, self.yc + y) ⑦ self.t.down()
這里用了布爾標(biāo)志drawingComplete,來(lái)確定繪圖是否已經(jīng)完成,在①行初始化該標(biāo)志。繪制多個(gè)Spiro對(duì)象時(shí),這個(gè)標(biāo)志是有用的,因?yàn)樗梢宰粉櫮硞€(gè)特定的螺線是否完成。在②行,顯示海龜光標(biāo),以防它被隱藏。在③行提起筆,這樣就可以在⑥行移動(dòng)到第一個(gè)位置而不畫(huà)線。在④行,使用了一些局部變量,以保持代碼緊湊。然后,在⑤行,計(jì)算角度a設(shè)為0時(shí)的 x 和 y 坐標(biāo),以獲得曲線的起點(diǎn)。最后,在⑦行,我們已完成,并落筆。Setpos()調(diào)用將繪制實(shí)際的線。
draw()方法用連續(xù)的線段繪制該曲線。
# draw the whole thing def draw(self): # draw the rest of the points R, k, l=self.R, self.k, self.l ① for i in range(0, 360*self.nRot + 1, self.step): a=math.radians(i) ② x=R*((1-k)*math.cos(a) + l*k*math.cos((1-k)*a/k)) y=R*((1-k)*math.sin(a) - l*k*math.sin((1-k)*a/k)) self.t.setpos(self.xc + x, self.yc + y) # drawing is now done so hide the turtle cursor ③ self.t.hideturtle()
在①行,迭代遍歷參數(shù)i的完整范圍,它以度表示,是360乘以nRot。在②行,計(jì)算參數(shù)i的每個(gè)值對(duì)應(yīng)的 X 和 Y 坐標(biāo)。在③行,隱藏光標(biāo),因?yàn)槲覀円淹瓿衫L制。
update()方法展示了一段一段繪制曲線來(lái)創(chuàng)建動(dòng)畫(huà)時(shí)所使用的繪圖方法。
# update by one step def update(self): # skip the rest of the steps if done ① if self.drawingComplete: return # increment the angle ② self.a +=self.step # draw a step R, k, l=self.R, self.k, self.l # set the angle ③ a=math.radians(self.a) x=self.R*((1-k)*math.cos(a) + l*k*math.cos((1-k)*a/k)) y=self.R*((1-k)*math.sin(a) - l*k*math.sin((1-k)*a/k)) self.t.setpos(self.xc + x, self.yc + y) # if drawing is complete, set the flag ④ if self.a >=360*self.nRot: self.drawingComplete=True # drawing is now done so hide the turtle cursor self.t.hideturtle()
在①行,update()方法檢查drawingComplete標(biāo)志是否設(shè)置。如果沒(méi)有設(shè)置,則繼續(xù)執(zhí)行代碼其余的部分。在②行,update()增加當(dāng)前的角度。從③行開(kāi)始,它計(jì)算當(dāng)前角度對(duì)應(yīng)的(X,Y)位置并將海龜移到那里,在這個(gè)過(guò)程中畫(huà)出線段。
討論萬(wàn)花尺方程時(shí),我提到了曲線的周期性。在一定的角度后,萬(wàn)花尺的圖案開(kāi)始重復(fù)。在④行,檢查角度是否達(dá)這條特定曲線計(jì)算的完整范圍。如果是這樣,就設(shè)置drawingComplete標(biāo)志,因?yàn)槔L圖完成了。最后,隱藏海龜光標(biāo),你可以看到自己美麗的創(chuàng)作。
SpiroAnimator類讓我們同時(shí)繪制隨機(jī)的螺線。該類使用一個(gè)計(jì)時(shí)器,每次繪制曲線的一段。這種技術(shù)定期更新圖像,并允許程序處理事件,如按鍵、鼠標(biāo)點(diǎn)擊,等等。但是,這種計(jì)時(shí)器技術(shù)需要對(duì)繪制代碼進(jìn)行一些調(diào)整。
# a class for animating Spirographs class SpiroAnimator: # constructor def __init__(self, N): # set the timer value in milliseconds ① self.deltaT=10 # get the window dimensions ② self.width=turtle.window_width() self.height=turtle.window_height() # create the Spiro objects ③ self.spiros=[] for i in range(N): # generate random parameters ④ rparams=self.genRandomParams() # set the spiro parameters ⑤ spiro=Spiro(*rparams) self.spiros.append(spiro) # call timer ⑥ turtle.ontimer(self.update, self.deltaT)
在①行,該SpiroAnimator構(gòu)造函數(shù)將DeltaT設(shè)置為10,這是以毫秒為單位的時(shí)間間隔,將用于定時(shí)器。在②行,保存海龜窗口的尺寸。然后在③行創(chuàng)建一個(gè)空數(shù)組,其中將填入一些Spiro對(duì)象。這些封裝的萬(wàn)花尺繪制,然后循環(huán)N次(N傳入給構(gòu)造函數(shù)SpiroAnimator),在⑤行創(chuàng)建一個(gè)新的Spiro對(duì)象,并將它添加到Spiro對(duì)象的列表中。這里的rparams是一個(gè)元組,需要傳入到Spiro構(gòu)造函數(shù)。但是,構(gòu)造函數(shù)需要一個(gè)參數(shù)列表,所以用Python的*運(yùn)算符將元組轉(zhuǎn)換為參數(shù)列表。
最后,在⑥行,設(shè)置turtle.ontimer()方法每隔DeltaT毫秒調(diào)用update()。
請(qǐng)注意,在④行調(diào)用了一個(gè)輔助方法,名為genRandomParams()。接下來(lái)就看看這個(gè)方法。
我們用genRandomParams()方法來(lái)生成隨機(jī)參數(shù),在每個(gè)Spiro對(duì)象創(chuàng)建時(shí)發(fā)送給它,來(lái)生成各種曲線。
# generate random parameters def genRandomParams(self): width, height=self.width, self.height ① R=random.randint(50, min(width, height)//2) ② r=random.randint(10, 9*R//10) ③ l=random.uniform(0.1, 0.9) ④ xc=random.randint(-width//2, width//2) ⑤ yc=random.randint(-height//2, height//2) ⑥ col=(random.random(), random.random(), random.random()) ⑦ return (xc, yc, col, R, r, l)
為了生成隨機(jī)數(shù),利用來(lái)自Python的random模塊的兩個(gè)方法:randint(),它返回指定范圍內(nèi)的隨機(jī)整數(shù),以及uniform(),它對(duì)浮點(diǎn)數(shù)做同樣的事。在①行,將R設(shè)置為50至窗口短邊一半長(zhǎng)度的隨機(jī)整數(shù),在②行,將r設(shè)置為R的10%至90%之間。
然后,在③行,將l設(shè)置為0.1至0.9之間的隨機(jī)小數(shù)。在④和⑤行,在屏幕邊界內(nèi)隨機(jī)選擇 x 和 y 坐標(biāo),選擇屏幕上的一個(gè)隨機(jī)點(diǎn)作為螺線的中心。在⑥行隨機(jī)設(shè)置為紅、綠和藍(lán)顏色的成分,為曲線指定隨機(jī)的顏色。最后,在⑦行,所有計(jì)算的參數(shù)作為一個(gè)元組返回。
我們將用另一個(gè)restart()方法來(lái)重新啟動(dòng)程序。
# restart spiro drawing def restart(self): for spiro in self.spiros: # clear spiro.clear() # generate random parameters rparams=self.genRandomParams() # set the spiro parameters spiro.setparams(*rparams) # restart drawing spiro.restart()
它遍歷所有的Spiro對(duì)象,清除以前繪制的每條螺線,分配新的螺線參數(shù),然后重新啟動(dòng)程序。
下面的代碼展示了SproAnimator中的update()方法,它由定時(shí)器調(diào)用,以動(dòng)畫(huà)的形式更新所有的Spiro對(duì)象:
def update(self): # update all spiros ① nComplete=0 for spiro in self.spiros: # update ② spiro.update() # count completed spiros ③ if spiro.drawingComplete: nComplete +=1 # restart if all spiros are complete ④ if nComplete==len(self.spiros): self.restart() # call the timer ⑤ turtle.ontimer(self.update, self.deltaT)
update()方法使用一個(gè)計(jì)數(shù)器nComplete來(lái)記錄已畫(huà)的Spiro對(duì)象的數(shù)目。在①行初始化后,它遍歷Spiro對(duì)象的列表,在②行更新它們,如果一個(gè)Spiro完成,就在③行將計(jì)數(shù)器加1。
在循環(huán)外的④行,檢查計(jì)數(shù)器,看看是否所有對(duì)象都已畫(huà)完。如果已畫(huà)完,調(diào)用restart()方法重新開(kāi)始新的螺線動(dòng)畫(huà)。在⑤行restart()的末尾,調(diào)用計(jì)時(shí)器方法,它在DeltaT毫秒后再次調(diào)用update()。
最后,使用下面的方法來(lái)打開(kāi)或關(guān)閉海龜光標(biāo)。這可以讓繪圖更快。
# toggle turtle cursor on and off def toggleTurtles(self): for spiro in self.spiros: if spiro.t.isvisible(): spiro.t.hideturtle() else: spiro.t.showturtle()
使用saveDrawing()方法,將繪制保存為PNG圖像文件。
# save drawings as PNG files def saveDrawing(): # hide the turtle cursor ① turtle.hideturtle() # generate unique filenames ② dateStr=(datetime.now()).strftime("%d%b%Y-%H%M%S") fileName='spiro-' + dateStr print('saving drawing to %s.eps/png' % fileName) # get the tkinter canvas ③ canvas=turtle.getcanvas() # save the drawing as a postscipt image ④ canvas.postscript(file=fileName + '.eps') # use the Pillow module to convert the postscript image file to PNG ⑤ img=Image.open(fileName + '.eps') ⑥ img.save(fileName + '.png', 'png') # show the turtle cursor ⑦ turtle.showturtle()
在①行,隱藏海龜光標(biāo),這樣就不會(huì)在最后的圖形中看到它。然后,在②行,使用datetime(),利用當(dāng)前時(shí)間和日期(以“日—月—年—時(shí)—分—秒”的格式),以生成圖像文件的唯一名稱。將這個(gè)字符串加在spiro-后面,生成文件名。
turtle程序采用tkinter創(chuàng)建的用戶界面(UI)窗口,在③和④行,利用tkinter的canvas對(duì)象,將窗口保存為嵌入式PostScript(EPS)文件格式。由于EPS是矢量格式,你可以用高分辨率打印它,但PNG用途更廣,所以在⑤行用Pillow打開(kāi)EPS文件,并在⑥行將它保存為PNG文件。最后,在⑦行,取消隱藏海龜光標(biāo)。
像第1章中一樣,在main()方法中用argparse來(lái)解析傳入程序的命令行選項(xiàng)。
① parser=argparse.ArgumentParser(description=descStr) # add expected arguments ② parser.add_argument('--sparams', nargs=3, dest='sparams', required=False, help="The three arguments in sparams: R, r, l.") # parse args ③ args=parser.parse_args()
在①行,創(chuàng)建參數(shù)解析器對(duì)象,在②行,向解析器添加--sparams可選參數(shù)。在③行,調(diào)用函數(shù)進(jìn)行實(shí)際的解析。
接下來(lái),代碼設(shè)置了一些turtle參數(shù)。
# set the width of the drawing window to 80 percent of the screen width ① turtle.setup(width=0.8) # set the cursor shape to turtle ② turtle.shape('turtle') # set the title to Spirographs! ③ turtle.title("Spirographs!") # add the key handler to save our drawings ④ turtle.onkey(saveDrawing, "s") # start listening ⑤ turtle.listen() # hide the main turtle cursor ⑥ turtle.hideturtle()
在①行,用setup()將繪圖窗口的寬度設(shè)置為80%的屏幕寬度(你也可以給setup指定高度和原點(diǎn)參數(shù))。在②行,設(shè)置光標(biāo)形狀為海龜,在③行,設(shè)置程序窗口的標(biāo)題為Spirographs!,在④行,利用onkey()和saveDrawing,在按下S時(shí)保存圖畫(huà)。然后,在⑤行,調(diào)用listen()讓窗口監(jiān)聽(tīng)用戶事件。最后,在⑥行,隱藏海龜光標(biāo)。
命令行參數(shù)解析后,代碼的其余部分進(jìn)行如下:
# check for any arguments sent to --sparams and draw the Spirograph ① if args.sparams: ② params=[float(x) for x in args.sparams] # draw the Spirograph with the given parameters col=(0.0, 0.0, 0.0) ③ spiro=Spiro(0, 0, col, *params) ④ spiro.draw() else: # create the animator object ⑤ spiroAnim=SpiroAnimator(4) # add a key handler to toggle the turtle cursor ⑥ turtle.onkey(spiroAnim.toggleTurtles, "t") # add a key handler to restart the animation ⑦ turtle.onkey(spiroAnim.restart, "space") # start the turtle main loop ⑧ turtle.mainloop()
在①行,首先檢查是否有參數(shù)賦給--sparams。如果有,就從字符串中提取它們,用“列表解析”將它們轉(zhuǎn)換成浮點(diǎn)數(shù)②(列表解析是一種Python結(jié)構(gòu),讓你以緊湊而強(qiáng)大的方式創(chuàng)建一個(gè)列表,例如,a=[2*x for x in range(1, 5)]創(chuàng)建前4個(gè)偶數(shù)的列表)。
在③行,利用任何提取的參數(shù)來(lái)構(gòu)造Spiro對(duì)象(利用Python的*運(yùn)算符,它將列表轉(zhuǎn)換為參數(shù))。然后,在④行,調(diào)用draw(),繪制螺線。
現(xiàn)在,如果命令行上沒(méi)有指定參數(shù),就進(jìn)入隨機(jī)模式。在⑤行,創(chuàng)建一個(gè)SpiroAnimator對(duì)象,向它傳入?yún)?shù)4,告訴它創(chuàng)建4幅圖畫(huà)。在⑥行,利用onkey()來(lái)捕捉按鍵T,這樣就可以用它來(lái)切換海龜光標(biāo)(toggleTurtles),在⑦行,處理空格鍵(space),這樣就可以用它在任何時(shí)候重新啟動(dòng)動(dòng)畫(huà)。最后,在⑧行,調(diào)用mainloop()告訴tkinter窗口保持打開(kāi),監(jiān)聽(tīng)事件。
可以從公眾號(hào)pythondada輸入萬(wàn)花尺索取完成代碼。
些函數(shù)系統(tǒng)也幫忙打包好,以xxx.dll文件存放在ext、extras文件夾中,需要開(kāi)啟配置才能使用。這些函數(shù)稱為擴(kuò)展函數(shù)(extend)。
一、解決中文截取亂碼mb_substr
echo mb_substr("中abc",0,2,"utf-8");
二、圖片處理函數(shù)GD2
GD(graphic device,圖形設(shè)備),負(fù)責(zé)在屏幕和打印機(jī)上輸出信息。GD2是GDI的后續(xù)版本。要使用GD2,首先應(yīng)該把網(wǎng)頁(yè)打散作為圖像(header),接著創(chuàng)建Graphics類對(duì)象(簡(jiǎn)單的來(lái)說(shuō),Graphics類對(duì)象就相當(dāng)于畫(huà)布,沒(méi)畫(huà)布我們?cè)谑裁吹胤嚼L圖呢?),然后調(diào)用一系列繪圖方法即可,最后再生成圖片、釋放資源(destroy)。看下面的代碼
步驟:
1、聲明:把當(dāng)前頁(yè)面通過(guò)寫(xiě)代碼的方式作為圖片生成,語(yǔ)法:
header(“content-type:image/jpeg”);
2、繪圖
3、生成圖片(注意格式對(duì)應(yīng))
語(yǔ)法: imagejpeg();
4、釋放資源(銷毀材料)
語(yǔ)法:imagedestory();
其中繪圖重要函數(shù)
//畫(huà)點(diǎn)
Imagesetpixel
//畫(huà)線
Imageline
//畫(huà)矩形
Imagerectangle
//畫(huà)圓
Imageellipse
//畫(huà)實(shí)心矩形
Imagefilledrectangle
//畫(huà)實(shí)心圓
imagefilledellipse
//畫(huà)文字 不支持中文
Imagestring
//畫(huà)豎排文字
Imagestringup
//畫(huà)文字支持中文
Imagettftext
所有的繪畫(huà)工作完成,可以使用img標(biāo)簽調(diào)用!!!
<img src=”xxxx.php”>
示例源碼:
<?php
header("content-type:image/jpeg");
//執(zhí)行繪圖
//創(chuàng)建畫(huà)布
$im=imagecreate(200,100);
//填充背景色
imagecolorallocate($im,100,100,100);
//定義顏色
$red=imagecolorallocate($im,255,255,255);
//畫(huà)點(diǎn)
imagesetpixel($im,5,5,$red);
//畫(huà)線
imageline($im,0,50,200,50,$red);
//畫(huà)矩形
imagerectangle($im,100,10,130,40,$red);
//畫(huà)圓
imageellipse($im,50,50,10,30,$red);
//畫(huà)實(shí)心的矩形
imagefilledrectangle($im,70,10,100,40,$red);
//畫(huà)實(shí)心圓
imagefilledellipse($im,40,20,10,30,$red);
//定義字體
$font="STXINGKA.TTF";
//畫(huà)文字
imagestring($im,$font,100,30,'I LIKE TEACHER HE!',$red);
//畫(huà)豎排文字
imagestringup($im,$font,180,90,'I LOVE TEACHER HE!',$red);
//畫(huà)支持中文的文字
imagettftext($im,14,30,80,70,$red,$font,'我愛(ài)何老師!');
//生成圖片
imagejpeg($im);
//想一想為什么在生成圖片之后無(wú)法繪畫(huà)
imagesetpixel($im,15,15,$red);
//釋放資源
imagedestroy($im);
?>
TIPS:練習(xí)下多邊形的多點(diǎn)坐標(biāo),可以使用圖片熱點(diǎn)技術(shù)。
利用GD2和前面的知識(shí)畫(huà)標(biāo)準(zhǔn)驗(yàn)證碼:
<?php
header("content-type:image/jpeg");
include_once("CheckNum.php");
$chnCount=6;//驗(yàn)證碼位數(shù)
$chn=CreateCheckNumber($chnCount,7);
$fontSize=40;//字體的大小(寬度)
$width=ceil($chnCount*($fontSize+0.5));//驗(yàn)證碼寬度
$height=$fontSize*2-2;//驗(yàn)證碼高度
$im=imagecreate($width,$height);
imagecolorallocate($im,243,243,243);
$fontColor=imagecolorallocate($im,70,147,251);
$font='STXINGKA.TTF';
imagettftext($im,$fontSize,0,($width-$fontSize*$chnCount+$fontSize)/2,($height-$fontSize)/2+$fontSize,$fontColor,$font,$chn);
//畫(huà)邊框 注意邊框粗細(xì)
imagerectangle($im,0,0,$width-1,$height-1,$fontColor);
//畫(huà)干擾線
$lineColor=imagecolorallocate($im,249,62,89);
for($i=0;$i<2;$i++)
imageline($im,0,rand(1,$height-1),$width,rand(1,$height-1),$lineColor);
//畫(huà)干擾點(diǎn)
for($i=0;$i<100;$i++){
$pixelColor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im,rand(1,$width-1),rand(1,$height-1),$pixelColor);
}
imagejpeg($im);
imagedestroy($im);
?>
文字水印:
以現(xiàn)有的圖片作為畫(huà)布再畫(huà)上文字。
Imagecreatefromjpeg
<?php
header("content-type:image/gif");
//以現(xiàn)有的圖片作為背景來(lái)創(chuàng)建畫(huà)布
$im=imagecreatefromgif("menggou.gif");
$color=imagecolorallocate($im,255,255,255);
$font='STKAITI.TTF';
imagestring($im,$font,5,5,'http://www.xuewanwang.com',$color);
imagegif($im);
imagedestroy($im);
?>
圖片水印:
把.png圖片作為水印使用imagecopy函數(shù)即可。
獲取圖片的寬度和高度
Imagesx、imagesy
<?php
header("content-type:image/jpeg");
//創(chuàng)建背景,作業(yè):根據(jù)背景圖創(chuàng)建對(duì)應(yīng)格式的畫(huà)布
$bgurl="bg.jpg";//改變背景圖片格式
//$extName=mb_substr($bgurl,strrpos($bgurl,'.'),strlen($bgurl)-strrpos($bgurl,'.'));//背景圖片擴(kuò)展名
$extName=strrchr($bgurl,'.');
switch(strtolower($extName)){
case '.jpg':$bg=imagecreatefromjpeg($bgurl);break;
}
$water=imagecreatefrompng('logo.png');
//獲取水印圖片的寬高度
$w=imagesx($water);
$h=imagesy($water);
//作業(yè):要求水印圖片出現(xiàn)在右上角、做下角、右下角、居中
imagecopy($bg,$water,0,0,0,0,$w,$h);
//作業(yè)完善:背景圖片水印圖片的2倍及以上大才生成水印,否則不生成是原圖
imagejpeg($bg);
imagedestroy($bg);
?>
作業(yè):
1、在網(wǎng)站根目錄下放4個(gè)圖片,分別命名為1.gif.png.bmp.jPg、 2.gif、3.png、4.bmp 生成圖片水印
2、圖片水印圖片可以在不同的位置出現(xiàn),定義變量控制為左上角、右上角、左下角、右下角、居中
3、背景圖片水印圖片的2倍及以上大才生成水印,否則不生成是原圖。
統(tǒng)計(jì)圖:
柱狀圖實(shí)現(xiàn)思路:
用戶傳遞的參數(shù)為數(shù)組,數(shù)組中元素個(gè)數(shù)為多少個(gè)單位;縱方向一般劃分10個(gè)等距離單位意味數(shù)組100%,數(shù)組中的值在縱方向按百分比顯示;縮放柱狀圖控制單位距離。
實(shí)現(xiàn)效果如下:
完整代碼:
<?php
header("content-type:image/jpeg");
/* 建議按300*550來(lái)縮放,否則會(huì)變形 */
$pSize=50;//單位距離,控制縮放
$pNameArr=explode(',',$_REQUEST['dw']);//單位名稱
$arr=explode(',',$_REQUEST['sj']);//需要生成統(tǒng)計(jì)圖的數(shù)組數(shù)據(jù)
$im=imagecreate($pSize*(count($arr)+2),$pSize*(10+1));
imagecolorallocate($im,243,243,243);
$black=imagecolorallocate($im,0,0,0);
//畫(huà)X軸
imageline($im,0,imagesy($im)-1,imagesx($im),imagesy($im)-1,$black);
//畫(huà)Y軸
imageline($im,1,0,1,imagesy($im),$black);
//算出數(shù)組元素中所有元素的值
$sum=0;
foreach($arr as $v){
$sum+=$v;
}
//畫(huà)X軸上等距線
$lheight=10;//等距線高度
//字體
$font="../fonts/STKAITI.TTF";
for($i=0;$i<count($arr);$i++){
imageline($im,$pSize*($i+1),imagesy($im)-1,$pSize*($i+1),imagesy($im)-1-$lheight,$black);
//畫(huà)矩形
imagerectangle($im,$pSize*($i+1)-$pSize/2+3,imagesy($im)-$arr[$i]/$sum*$pSize*10-1-1,$pSize*($i+1)+$pSize/2-3,imagesy($im)-1,$black);
$rcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagefilledrectangle($im,$pSize*($i+1)-$pSize/2+4,imagesy($im)-$arr[$i]/$sum*$pSize*10-1,$pSize*($i+1)+$pSize/2-4,imagesy($im)-2,$rcolor);
imagettftext($im,16,30,$pSize*($i+1)-$pSize/2+4,imagesy($im)-$arr[$i]/$sum*$pSize*10-4,$rcolor,$font,$arr[$i].$pNameArr[$i]);
}
//畫(huà)Y軸上等距線
for($i=1;$i<=10;$i++){
imageline($im,1,imagesy($im)-$pSize*$i,1+$lheight,imagesy($im)-$pSize*$i,$black);
imagestring($im,2,10,imagesy($im)-$pSize*$i-5,$i*10,$black);
}
imagestringup($im,5,$pSize/2-5,$pSize*5,'(%)',$black);
imagejpeg($im);
imagedestroy($im);
?>
餅狀圖實(shí)現(xiàn)效果如下:
<?php
header("content-type:image/jpeg");
/* 建議按350*200來(lái)縮放,否則會(huì)變形 */
//定義圓半徑
$raduis=100;
$arr=explode(',',$_REQUEST['sj']);//需要生成統(tǒng)計(jì)圖的數(shù)組數(shù)
$pNameArr=explode(',',$_REQUEST['dw']);//單位名稱
//計(jì)算數(shù)組總值
$sum=0;
//$maxFontSize=strlen($arr[0]);//最大文字內(nèi)容長(zhǎng)度
foreach($arr as $v){
$sum+=$v;
//$maxFontSize=strlen($v)>$maxFontSize?strlen($v):$maxFontSize;
}
//foreach($pNameArr as $v)
//$maxFontSize=strlen($v)>$maxFontSize?strlen($v):$maxFontSize;
//字體
$font="../fonts/STKAITI.TTF";
$fontSize=13;//字體大小
$im=imagecreate($raduis*2+180,$raduis*2);
imagecolorallocate($im,243,243,243);
$black=imagecolorallocate($im,0,0,0);
imageellipse($im,$raduis,$raduis,$raduis*2-1,$raduis*2-1,$black);
$startP=0;//起始角度
for($i=0;$i<count($arr);$i++){
$pieColor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagefilledarc($im,$raduis,$raduis,$raduis*2-3,$raduis*2-3,$startP,$startP+$arr[$i]/$sum*360,$pieColor,IMG_ARC_EDGED);
$startP+=$arr[$i]/$sum*360;
//數(shù)據(jù)提示
imagettftext($im,$fontSize,0,$raduis*2+$fontSize*3,$fontSize*($i+1)+6,$pieColor,$font,$arr[$i].$pNameArr[$i].'('.round($arr[$i]/$sum*100).'%)');
imagefilledrectangle($im,$raduis*2+$fontSize,10+$fontSize*$i,$raduis*2+$fontSize*2,6+$fontSize*$i+$fontSize,$pieColor);
}
imagejpeg($im);
imagedestroy($im);
?>
補(bǔ)充:好吧,驗(yàn)證碼比較難看,應(yīng)大家要求,換個(gè)好看點(diǎn)的
復(fù)制代碼
1.<?php
2.session_start();
3.header("content-type:image/png"); //設(shè)置創(chuàng)建圖像的格式
4.$image_width=70; //設(shè)置圖像寬度
5.$image_height=18; //設(shè)置圖像高度
6.srand(microtime()*100000); //設(shè)置隨機(jī)數(shù)的種子
7.for($i=0;$i<4;$i++){ //循環(huán)輸出一個(gè)4位的隨機(jī)數(shù)
8. $new_number.=rand(0,9);
9.}
10.$_SESSION[check_checks]=$new_number; //將獲取的隨機(jī)數(shù)驗(yàn)證碼寫(xiě)入到SESSION變量中
11.
12.$num_image=imagecreate($image_width,$image_height); //創(chuàng)建一個(gè)畫(huà)布
13.imagecolorallocate($num_image,255,255,255); //設(shè)置畫(huà)布的顏色
14.for($i=0;$i<strlen($_SESSION[check_checks]);$i++){ //循環(huán)讀取SESSION變量中的驗(yàn)證碼
15. $font=mt_rand(3,5); //設(shè)置隨機(jī)的字體
16. $x=mt_rand(1,8)+$image_width*$i/4; //設(shè)置隨機(jī)字符所在位置的X坐標(biāo)
17. $y=mt_rand(1,$image_height/4); //設(shè)置隨機(jī)字符所在位置的Y坐標(biāo)
18. $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); //設(shè)置字符的顏色
19. imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color); //水平輸出字符
20.}
21.imagepng($num_image); //生成PNG格式的圖像
22.imagedestroy($num_image); //釋放圖像資源
23.?>
三、header函數(shù)、iconv、get_loaded_extensions函數(shù)
header函數(shù)
1、聲明圖片
Header(“content-type:image/xxxx”);
2、當(dāng)前頁(yè)面強(qiáng)制轉(zhuǎn)碼
header("content-type:text/html;charset=utf-8");
3、強(qiáng)制跳轉(zhuǎn)
header("location:http://www.xuewanwang.com");
……
詳細(xì)請(qǐng)參閱 學(xué)玩網(wǎng) header函數(shù)的用法
注意事項(xiàng):header函數(shù)前不能有空格、回車(\n)、換行(\r)等非法內(nèi)容;也不能包含任何輸出的語(yǔ)句;不能放任何HTML標(biāo)簽,但是可以放到<html>之前。
iconv字符串強(qiáng)制轉(zhuǎn)碼:
iconv("原來(lái)的編碼","轉(zhuǎn)出后的編碼",$str);
Get_loaded_extensions() 判斷是否開(kāi)啟對(duì)應(yīng)函數(shù)庫(kù),返回支持庫(kù)字符串?dāng)?shù)組
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。