整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

52天奇速记完高考3500词汇第15天

52天奇速记完高考3500词汇第15天

. 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?你能告诉我鲁迅是什么时候出生的吗?

5. corner [ 5kC:nE ] n. 角落, (街道)拐角处, 偏僻处, 困境vt.使陷入绝境, 把...难住Children’s Day is just around the corner. 儿童节就要到了。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.你应纠正你写作中的错误。

2. correction [ kE5rekFEn ] n. 纠正 The correction is necessary for our development.在我们的发展过程中纠正错误是必不可少的。

3. incorrect [ 7inkE5rekt ] in-correct adj. 不正确的I’m sorry your answer is incorrect.恐怕你的答案并不正确。

4. direct [ di5rekt, dai5rekt ] di-rect vt. 指导(让做正确),指点 adj. 直接的Who directs the firm these days?现在谁当导演?

5. direction [ di5rekFEn, dai5rekFEn ] n. 方向,指导 The travelers come in all directions.旅客来自四面八方。

6. director [ di5rektE, dai5rektE ] n. 主任, 主管, 导演 Mr. Zhang Yimou has set up his status as a successful director.张艺谋先生作为一名成功的导演已确立了他的地位。

7. indirect [ 7indi5rekt, indai5rekt ] adj. 间接的 The teacher just gave us an indirect answer.老师只是给了我们一个间接的回答。

8. rectangle [ 5rektAN^l ] rect-angle(角)n. 正方形(四个角都是直角) Can you draw a rectangle with one hand and a circle with the other?你能一手画方一手画圆吗?

另类阅读: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.每个人都在追逐成功,但成功属于那些既动手又动脑的人。

2. succeed [ sEk5si:d ] vi, 成功, 继...之后, 继任 注意: succeed in doing something. Finally we succeeded in getting to the top.最后我们成功地到达了顶峰。

3. successful [ sEk5sesful ] adj. 成功的 Many factors make a successful writer.多种因素造就了一名成功的作家。

4. successfully [sEk5sesfJlI] adv. 成功地 China has launched manned space travel successfully.中国已成功地进行了载人太空飞行。

5. unsuccessful [ 5QnsEk5sesful ] adj. 不成功的 The project turned out to be unsuccessful.那项工程结果并不成功。

6. successor [ sEk5sesE ] n.继承者, 接任者, 后续的事物 The successors of the films are not all successful. 电影的续集并非都成功。

7. ex- 表示“out”, excess [ ik5ses, 5ekses ] n. & v. 过度,超过 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.进行, 继续下去, 发生 The speech contest proceeded. 演讲比赛继续。

9. process [ prE5ses ] A series of actions, changes, or functions bringing about a result n. 过程, 作用, 方法 vt.加工, 处理 I’m afraid the process is too complicated for you.恐怕这种方法对你过于复杂。

10. procedure [ prE5si:dVE ] A manner of proceeding n.程序, 手续 Finishing the procedure, he felt too tired. 完成手续后,他感到太累。

11. access [ 5Akses ] ac-cess n. 通路, 访问, 入门 vt.存取, 接近 No access to the house is given to common civilians.普通人不许进那房子。

12. accessible [ Ek5sesEbl ] adj. 易接近的, 可到达的, 易受影响的, 可理解的 The palace is not accessible for us.那宫殿我们去不了。

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.我们每个人咳嗽过。

2. fever [ 5fi:vE ] n. 发烧, 发热, 狂热 The boy is running a high fever. Send for a doctor at once!孩子在发高烧。马上找医生来!

3. headache [5hedeIk] n.头疼 Is the war in Iraq a glory or a headache for Jorge W Bush?伊拉克战争对布什来说是荣光还是头疼?

4. backache [5bAkeIk] n. 背疼 The backache makes it hard to turn over.背疼之后,翻身不便。

5. suffer [ 5sQfE ] suf-fer vt.遭受, 经历, 忍受 vi.受痛苦, 受损害 Whenever a war breaks out, it’s the civilians who suffer.每一场战争都是老百姓遭殃。

6. suffering [ 5sQfEriN ] n. 痛苦 Who brought all these sufferings to the ordinary people?是谁把这些痛苦加在老百姓身上的?

7. ill [ il ] adj. 有病的(作表语), 坏的, 恶意的 Hearing the ill boy fell ill, we couldn’t help having a pity over him.听说那个爱捣乱的男子病倒了,我们还是忍不住同情他。

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. 对讨厌他的空洞单调的讲话。

10. sickness [ 5siknis ] The condition of being sick; illness n. 病 Fortunately his sickness is not serious.幸运的是他的病不严重。

11. disease [ di5zi:z ] ease, 安逸, 安心 disease, 不安逸,有病 n. 病 Doctors deal with physical diseases. Then, who can deal with social diseases?医生解决身体毛病,那么,谁能解决社会毛病?

12. dizzy [ 5dizi ] 联想disease, 有病的人头晕的。 adj. 晕眩的, 昏乱的 Looking down from the tower top, I found myself dizzy.在塔顶上往下看,我头晕目眩。

13. patient [ 5peiFEnt ] n. 病人, 患者 adj. 忍耐的, 耐心的 The doctor is supposed to be patient to any patient.医生对任何病人都应该有耐心。

14. patience [ 5peiFEns ] n. 耐心 Patience is one of the conditions of the final success. 耐心是最终成功的条件之一。 格言: Patience is a virtue.耐心即是宝。

15. bacterium [ bAk5tiEriEm ] n. 细菌 注意复数:bacteria Bacteria are almost everywhere.细菌几乎无处不在。

16. virus [ 5vaiErEs ] n. 病毒 People have found the virus causing SARS.人们发现了引起非典的病毒。

5.count counter account accountant discount county country

记忆:1. count [kaJnt] n. 数, 计算 Having counted the books, he realized they were far from enough.他数完书后,意识到它们远远不够。

2. counter [ 5kauntE ] n.计算器, 计数器, 计算者, 柜台 The customer can drink by the counter of the bar.顾客可在在酒吧的柜台边喝酒。

3. account [ E5kaunt ] ac-count n.计算, 帐目, 说明, 理由 vi. 说明 The accounts are very clear. 帐目非常清楚。He paid the money into his bank account.

4. accountant [ E5kauntEnt ] account-ant n.会计(员), 会计师 The accountant’s innocence has been proved once more.会计的清白又一点得到证实。

5. discount [ 5diskaunt ] dis-count n.折扣 The more you buy, the larger discount we can offer. 你买得越多,我们给你打折越多。

6. country [ 5kQntri ] n. 国家, 国土 It’s everyone’s duty to protect his country. 保卫祖国,匹夫有责。

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. 过程, 进程, 路线, 课程, 一道菜 He was quite doubtful during the course of the experiment.在实验过程中他一直都很怀疑。

2. cause [ kC:z ] n. 原因, 事业 vt.引起 What caused him to act so rashly?什么东西使得他行动如此草率?

3. result [ ri5zQlt ] n. 结果, 成效, 计算结果 vi. 起因, 由于, 导致 result in以...为结果,result from 起因于 What you are today is the result of what you did yesterday.你今天的状况是你昨天行动的结果。

4. consequence [ 5kCnsikwEns ] con-sequ-ence 词根sequ, 即follow, consequence, 跟在后面的, n.结果, 推理 If you continue this way, you must consider its consequence.如果你继续这样,你要考虑它的后果。

5. effect [ i5fekt ] 词根fect 含义为“做,创造”,前缀e-, 表示“出”,effect, 做出来的,n.结果, 效果, 作用, 影响 The medicine has no effect on my cold.这种药对我的感冒不起作用。

6. effective [ i5fektiv ] adj. 有效的 Some effective measure must be taken at once.必须马上采取有效措施。

7. affect [ E5fekt ] 前缀af-即ab-的变体,vt.影响, 感动 When we are quiet in heart, nothing outside can affect us.心静自然凉。

8. affection [ E5fekFEn ] n.友爱, 爱情, 影响 How can I show my deep affection to her?我怎样才能表达对她的深深爱恋呢?

9. perfect [ 5pE:fikt ] 前缀per- 表示“完成”,perfect,做完了的,完美的 Nothing is perfect and nobody is perfect.金无赤足,人无完人。

10. influence [ 5influEns ] in-flu-ence, 词根flu表示“流动”,influence, 在里面流过,有影响,n.影响 vt.影响, 改变 His experiences in his childhood influenced him more than anything else.他童年时代的经历对他影响最大。

11. effort n. 努力 Great efforts should be made to ensure the project goes on well.应该付出努力保证工程的顺利进行。

7.cover discover discovery discoverer uncover expose betray detect detective recover lid

记忆:1. cover [ 5kQvE ] n. 盖子, 封面 vt. 覆盖,报道 What do you think of the phenomenon that beautiful women take up nearly all magazine covers? 美女几乎占据了所有的杂志封面,你对这一现象怎么看? 格言:You can't tell a book by its cover. 不能以貌取人。

2. discover [ dis5kQvE ] vt. 发现, 发觉 Some people doubt whether it is Columbus who first discovered America.一些人怀疑是不是由哥伦布首先发现美洲的。

3. discovery [ dis5kQvEri ] n. 发现 His discovery resulted in a industrial revolution.他的发现引起了一场工业革命。

4. discoverer [ dis5kQvErE ] n. 发现者 Who was the discoverer of Radium?谁是镭的发现者?

5. uncover [ Qn5kQvE ] vt.揭开, 揭露 Uncovering the basket, she was moved to find her favorite fish there.她揭开篮子,发现里面是她最爱吃的鱼,很受感动。

6. recover [ ri5kQvE ] re-cover vi. 痊愈, 复原 I hope you can recover soon.我希望你很快康复。

7. expose [ iks5pEuz ] 词根pose表示“放”;ex-, 外;expose, 放在外面,vt.使暴露, 使曝光 As a reporter, I think it’s my duty to expose the scandal and praise the kindness.作为记者,我认为我有责任扬善惩恶。

8. betray [ bi5trei ] be-tray vt.出卖, 背叛, 泄露 When you betray your motherland, you are not worthy of being human.如果你背叛祖国,你就不是人。

9. detect [ di5tekt ]  词根tect含义是“遮蔽,掩盖”;前缀de-含义为“反,去”,detect, 去掉遮掩,探测,侦探 In my childhood, I dreamed that I could invent some equipment to detect mushrooms in the wild.童年时候,我梦想我能发明一种设备来探测野外的蘑菇。

10. detective [ di5tektiv ] n. 侦探 Holms is the best-known detective. However, he was not a real man.福尔摩斯是最有名的侦探,但他却非真人。

11. protect [ prE5tekt ] 前缀pro-为“先”,事先遮盖起来,保护 Everyone should form the sense of protecting life, no matter whose it is.每个人都应有保护生命的意识,不论那是谁的生命。

12. lid [ lid ] n. 盖子 Sorry, but the lid refuses to be removed. 对不起,但盖子挪不动。

8;cream scream stream butter milk yoghurt

记忆:1. cream [ kri:m ] n. 乳酪, 奶油, (护肤)面霜 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.一看到蛇,女孩惊叫起来。

3. stream [ stri:m ] n. 溪, 川, 流, 一股 The water in that stream is quite clear and sort of sweet.那小溪里的水清彻见底,有点甜。

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.一天一杯牛奶,医生不用再见。

6. yoghurt [`jC^Et,`jEJ-] n. 酸乳 Yoghurt has become popular because of its special taste.酸乳因其味道独特而受人喜爱。

9. crop drop stop fall fell felt

记忆:1. crop [ krCp ] n. 农作物 vt. 收割 Not every farmer lives on crops.并非每个农民都以庄稼为生。

2. drop [ drCp ] d, 音“滴,掉”,v.滴下, 落下 n. 落下, 下降, 滴 You can’t drop English though your English is quite poor at present.虽然你目前英语差,但是你不能放弃英语。

3. drip [ drip ] n. 水滴 v. (使)滴下 Some water is dripping from the roof.一些水正从屋顶上滴下来。

4. stop [ stCp ] n. 停止, 车站 vi. 停止 Nobody can stop me loving my country. 没人能阻拦我爱我的祖国!

5. fall [ fC:l ] n. 秋天, 落下 vi. 倒下, 落下 Four fools fell asleep on a fall afternoon. 在一个秋天下午四个傻瓜睡着了。 fall to the ground掉到地上 fall off sth从……上掉下来 fall ill生病了 fall asleep睡着了 fall in love with sb爱上

6. fell [ fel ] vt. 砍伐 How can you fell so many trees at a time?你一次怎能砍倒那么多树?

7. felt [ felt ] feel的过去式,感到 I felt embarrassed when I saw her.我看到她时感到有些尴尬。

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.别挤!排好队,每个人都能得到他想要的东西。

2. crowded [ 5kraudid ] adj. 拥挤的, 塞满的 The buses used to be too crowded when holidays came.过去当假期来临的时候,公共汽车曾很拥挤。

3. squeeze [ skwi:z ] v. 压榨, 挤, 挤榨 Don't squeeze my finger. It hurts!别挤压我的手指,很疼!

4. coward [ 5kauEd ] cow, 奶牛;d, 音“倒”, coward, 看见温顺的奶牛呵也倒的人,胆小鬼;n.懦弱的人, 胆小的人 A young rat scared him so! I have never seen such a coward.一只小老鼠就把他吓成这样!我从来没有见过这样胆小的人。

5. people [ 5pi:pl ] n. 人们 The government should be of the people, by the people and for the people.政府应是民有,民治,民享。

6. population [ 7pCpju5leiFEn ] popul表示人;population, 人口 What’s the population in your hometown? 你家乡有多少人?

7. 加形容词后缀-ar, popular [ 5pCpjulE ] adj. 通俗的, 流行的, 受欢迎的 When scientists are more popular than the singers with the young, the nation will be unconquerable. 如果科学家比歌手更受年轻人欢迎,那么这个民族是不可战胜的。

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.要做事,但不要做事务的奴隶。

2. slavery [ 5sleivEri ] n. 奴隶身分, 奴隶制度 The slavery should be abolished completely.应该彻底废除奴隶制。

3. cruel [ 5kruEl ] 音似“刻肉”,在肉体上刻划,残酷;adj. 残酷的, 悲惨的 What made a young boy with such a cruel heart?什么东西使得一个小男孩心肠如此残忍?

4. cruelty [5kru:EltI] n. 残忍, 残酷 The mercy on the devil is the cruelty to the kind.对坏人的同情就是对好人的残忍。

5. savage [ 5sAvidV ] sav-age sav-音似“杀无”,杀的一个不留,野蛮凶狠 adj. 野蛮的, 凶猛的, 残忍的 Be careful of the savage in the area.当心这一带的野人。

6. kind [ kaind ] adj. 善良的 The kind shouldn’t be regard as the weak.善良不应被看作是软弱。 be kind to sb It’s kind of sb to do sth

7. mercy [ 5mE:si ] mer-cy联想:妹儿是有同情心的, n. 仁慈, 宽恕, 怜悯 Have mercy on others and you will get more in the future.对别人有同情心,你将得到更多的回报。

8. merciful [ 5mE:siful ] adj. 仁慈的, 慈悲的 A merciful heart is to be treasured.应珍惜仁慈之心。

12. cry tear sob weep laugh laughter smile

记忆:1. cry [ krai ] vi. 哭, 流泪 n. 叫, 喊 n. 哭泣, 喊声 It’s no use crying over spilt milk.后悔无用。

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.男孩还在抽泣。他不久会好一些。

4. weep [ wi:p ] n. 哭, 哭泣, 滴下 vi. 哭泣, 流泪 A healthy society never allows a hero weeping.一个健康的社会绝不会让英雄流泪。

5. laugh [ lB:f ] vi. 笑, 讥笑 Laughing help keeping us healthy.大笑有助于我们的健康。 格言: He laughs best who laughs last. 最后笑的人笑得最好。

6. laughter [ 5lB:ftE ] n. 笑, 笑声 burst into laughter 突然大笑起来 Her laughter is my greatest delight.她的笑声是我最大的欢乐。 格言: Laughter is the best medicine.笑声是最佳的药。

7. smile [ smail ] n.& vi. 微笑 When you smile, the life smiles, too.你笑的时候,生活也在笑。

13. cup glass glasses cut carve sculpture split

记忆:1. cup [ kQp ] n. 杯子, 酒杯, 奖杯 vt.使成杯状 Fetch me another five cups, please.请再给我取五个杯子来。

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.带深度眼镜的那个人是来自清华大学的教授。

4. cut [ kQt ] vt. 切(割、削), 剪, n.削减, 删节, 伤口, 切口 Wrap your cut with this bandage quickly. 快点用这绷带把你的伤口包起来。

5. carve [ kB:v ] vt. 雕刻, 切开 He carved a face in the trunk. 他在树干上雕刻了一张脸。

6. sculpture [ 5skQlptFE ] cu, 音似“刻”n. 雕刻, 雕刻品, 雕塑, 雕塑品 The city sculptures are another attraction to me.城市雕塑是另一个吸引我的地方。

7. split [ split ] p, 音“劈”,v. 劈开 n. 裂开, 裂痕 The woodcutter split the trunk into halves.樵夫把树干劈成了两半。

14. danger dangerous emergency safety safe safely save rescue secure security

记忆:1. danger [ 5deindVE ] n. 危险, 危险物 Look out! There is danger ahead.小心,前面有危险!

2. dangerous [ 5deindVrEs ] adj. 危险的 The tiger in danger is still a dangerous animal.处于危险境地的老虎仍是危险的动物。

3. emergency [ i5mE:dVnsi ] emerg-ency emerge,出现;emergency, 突然出现 n. 紧急情况, 突然事件 The special police forces keep alert all the time in case of any emergency.特种警察部队一直保持着警惕,以防任何紧急情况的出现。

4. emerge [ i5mE:dV ] vi. 显现, 浮现, (由某种状态)脱出, (事实)显现出来 The truth will emerge sooner or later.真相尽早出浮出水面。

5. safe [ seif ] adj. 安全的 n. 保险箱 Precautious attacking can’t keep the county really safe.先发制人并不能真正保证国家的安全。

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. 解救, 保存, 节省, 储蓄 vi. 挽救, 节省 prep. 除...之外 How can I thank you enough for saving my life?你救了我的命,我真不知该怎样感谢你。 格言:Saving is getting. 节省就是获得。

9. rescue [ 5reskju: ] vt. & n. 援救, 营救 The firemen have tried their best to rescue the man trapped 消防队员已尽了力去营救受困的那个人。

10. secure [ si5kjuE ] se-cure, 治好的, adj. 安全的, 可靠的 You may be relaxed now. The secret is absolutely secure.你可以放松点。那个秘密绝对安全。

11. security [ si5kjuEriti ] n.安全 National security is the first matter for any government.国家安全是任何政府的首要问题。

15. dare daring afraid fright frighten frightened fear fearful

记忆:1. dare [ dZE ] vi. 敢, 胆敢 He dares to challenge any famous singer.他敢于向任何著名的歌手折挑战。

2. daring [ 5dZEriN ] adj. 大胆的 The daring words surprised his parents.那番大胆的话让他父母吃了一惊。

3. afraid [ E5freid ] adj. 害怕, 担心 I’m afraid to see his angry face.我不敢看他生气的脸。

4. fear [ fiE ] n. 恐怖, 害怕, 担心 v. 害怕, 畏惧 What I fear is not bears but tears.我怕的不是大笨熊,而是眼泪。 格言:Fear of death is worse than death itself. 对死亡的恐惧比死亡本身更可怕。

5. fearful [ 5fiEful ] adj. 可怕的, 恐怕的 A dark night may be fearful for a lonely girl.也许对一个孤独的女孩来说,漆黑的夜晚是可怕的。

6. fearless [5fIElIs] adj. 勇敢的, 无畏的 Mandela is a fearless fighter to get rid of racial discrimination.曼德拉为消除种族歧视进行了无畏的战斗。

7. fright [ frait ] f+right 不对的,让人惊骇的 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.真奇怪,那时候我居然很害怕!

记单词有困难的同学,推荐学习《奇速英语24个故事串记中学3500词汇》 ,让你在轻松愉快的故事中掌握单词的读音、汉语意思和拼写哦!单词逆袭链接:

24个故事第一讲链接:http://v.qq.com/page/g/s/7/g0139goxls7.html

24个故事第二讲链接:http://v.qq.com/page/y/4/7/y0140zjnc47.html ;

24个故事第三讲链接:http://v.qq.com/page/c/a/c/c0140y0r0ac.html

奇速英语官方旗舰店:http://abc366.taobao.com

记得小时候的万花尺吧?这么画:

一点也不费脑筋,就可以出来这么多丰富多彩的复杂几何图形。

具体而言,可以用万花尺玩具(如图2-1所示)来绘制数学曲线。这种玩具由两个不同尺寸的塑料齿轮组成,一大一小。小的齿轮有几个孔。把钢笔或铅笔放入一个孔,然后在较大齿轮(内部有齿)内旋转里面的小齿轮,保持笔与外轮接触,可以画出无数复杂而奇妙的对称图案。

图2-1 万花尺

现在,在电脑里,用Python也可以这么玩了,让我们看看Python的万花尺效果吧。(不用急,程序在后哦)

$ python spiro.py

默认情况下,spiro.py程序绘制随机螺线,如图2-5所示。按S键保存绘制。

图2-5 spiro.py的运行示例

再次运行程序,这次在命令行传入参数,画出特定的螺线。

$ python spiro.py --sparams 300 100 0.9

图2-6展示了输出结果。如你所见,这段代码根据用户指定的参数绘制了一条螺线,图2-5和它不同,展示了几个随机螺线的动画。

图2-6 用具体参数运行spiro.py的示例

这么神奇又好玩的万花尺,在Python里怎么玩呢?

不要走开,让我们继续下面的Python之旅。

在这个项目中,我们将用Python来创建动画,像万花尺一样绘制曲线。我们的spiro.py程序将用Python和参数方程来描述程序的万花尺齿轮的运动,并绘制曲线(我称之为螺线)。我们可以将完成的画图保存为PNG图像文件,并用命令行选项来指定参数或生成随机螺线。

在这个项目中,我们将学习如何在计算机上绘制螺线。还将学习以下几点:

  • 用turtle模块创建图形;
  • 使用参数方程;
  • 利用数学方程来生成曲线;
  • 用线段来画曲线;
  • 用定时器来生成图形动画;
  • 将图形保存为图像文件。

 参数方程

在本节中,你将看到用参数方程来画圆的简单例子。参数方程将曲线上点的坐标表示为一个变量的函数,该变量称为参数。参数方程让绘制曲线变得容易,因为只要将参数代入方程就能产生曲线。

注意

如果你现在不想学习这部分数学知识,可以跳到下一部分,讨论针对万花尺项目的方程。

我们开始考虑用半径 r 来描述一个圆的方程,圆心位于二维平面的原点。 x 、 y 坐标满足该方程的所有点构成了圆。

现在,请考虑下面的方程:

x=r cos( θ )

y=r sin( θ )

这些方程是圆的参数表示,其中角 θ 是参数。这些方程中(X,Y)的任何值,都满足前面描述的圆的方程,X 2 + Y 2=R 2 。如果让 θ 从0变到2π,可以用这些方程来计算圆上对应的 x 和 y 坐标。图2-2展示了这种方案。

图2-2 用参数方程描述圆

记住,这两个方程适用于圆心在坐标系原点的圆。将圆心转换到点( a , b ),就可以将圆置于 xy 平面的任何位置。所以更一般的参数方程就变成 x=a + r cos( θ )和 y=b + r cos( θ )。现在,让我们来看看描述螺线的方程。

万花尺方程

图2-3展示了类似万花尺运动的数学模型。该模型没有齿轮,因为玩具中的齿轮只是为了防止打滑,而在这里不必担心打滑。

图2-3 万花尺数学模型

在图2-3中,C是较小的圆的圆心,P是笔尖。较大的圆半径为 R ,较小的圆半径为 r 。半径之比表示如下:

将线段PC与小圆半径 r 之比作为变量l(l=PC / r ),它决定了笔尖离小圆圆心有多远。然后,组合这些变量来表示P的运动,得到如下的参数方程:

注意

这些曲线称为内旋轮线和外旋轮线。虽然方程可能看起来有点吓人,但推导是非常简单的。如果你想探索其中的数学,请参见维基百科。

图2-4展示了如何用这些方程,基于参数的变化,产生一条曲线。通过改变参数 R 、 r 和 l ,可以产生变化无穷的迷人曲线。

图2-4 示例曲线

将曲线绘制为一系列点之间的线段。如果这些点足够接近,图看起来就像平滑的曲线。真正玩过万花尺就知道,这取决于使用的参数,万花尺可能需要许多转数来完成。要确定何时停止绘图,就要利用万花尺的周期性(即万花尺图案多久开始重复),研究内外圆的半径之比:

分子分母除以它们的最大公约数(GCD),化简该分数,分子就告诉我们需要多少圈才能完成曲线。例如,在图2-4中,( r , R )的GCD是5。

下面是该分数化简后的形式:

这告诉我们,13圈后,曲线将开始重复。44告诉我们小圆围绕其中心旋转的圈数,它提示了曲线的形状。在图2-4中数一下,会看到图形中花瓣或叶的数目恰好是44!

一旦用简化形式表示了半径比 r / R ,画出螺线的参数 θ 范围就是[0,2πr]。这告诉我们何时停止绘制特定的螺线。不知道该角度的结束范围,就会循环不止,不必要地重复该曲线。

海龟画图

我们可以用Python的turtle模块来创建图案。这是一个简单的绘图程序,模型是一只海龟拖着尾巴穿过沙滩,留下图案。turtle模块包括了一些方法,用于设置笔(海龟的尾巴)的位置和颜色,以及其他有用的绘图函数。如你所见,只要少量绘图函数,就可以创建漂亮的螺线。

例如,这个程序用turtle画圆。输入以下代码,保存为drawcircle.py,在Python中运行它:

 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()

在①行,从导入turtle模块开始。接下来,定义drawCircleTurtle()方法,它在②行调用up()。这告诉Python提笔。换句话说,让笔离开虚拟的纸,这样移动海龟也不会画图。开始绘图之前,先定位海龟。

在③行,将海龟的位置设置为横轴上的第一个点:(x + r, y),其中(x,y)是该圆的圆心。现在准备好画图了,所以在④行调用down()。在⑤行,利用range(0, 365, 5)开始循环,以5为步长递增变量i,从0到360,变量i是角度参数,将传入圆的参数方程,但首先在⑥行将它从度转为弧度(大多数计算机程序的角度计算需要弧度)。

在⑦行,利用前面讨论过的参数方程计算圆的坐标,并设置相应的海龟位置,这样就从海龟上一个位置画线到新计算的位置(从技术上讲,产生的是N边多边形,但因为用了很小的角度,N将非常大,多边形看起来像一个圆)。

在⑧行,调用drawCircleTurtle()来画圆,在⑨行,调用mainloop(),它保持tkinter窗口打开,让你可以欣赏你画的圆(Tkinter是Python默认的GUI库)。

现在,我们准备好画一些螺线了!

所需模块

我们将利用下面的模块创建螺线:

  • turtle模块用于绘图;
  • pillow,这是Python图像库(PIL)的一个分支,用于保存螺线图像。

代码

首先,定义类Sipro,来绘制这些曲线。我们会用这个类一次画一条曲线(利用draw()方法),并利用一个定时器和update()方法,产生一组随机螺线的动画。为了绘制Spiro对象并产生动画,我们将使用SpiroAnimator类。

要查看完整的项目代码,请直接跳到2.4节。

 Spiro构造函数

下面是Spiro构造函数:

  # 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构造函数创建一个新的turtle对象,这将有助于我们同时绘制多条螺线。在②行,将光标的形状设置为海龟(在 https://docs.python.org/3.3/library/ turtle.html ,你可以在turtle文档中找到其他选项)。在③行,将参数绘图角度的增量设置为5度,在④行,设置了一个标志,将在动画中使用它,它会产生一组螺线。

在⑤和⑥行,调用设置函数,接下来讨论该函数。

设置函数

现在让我们看看getParams()方法,它帮助初始化Spiro对象,如下所示:

  # 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

在①行,保存曲线中心的坐标。然后在②行,将每个圆的半径( R 和 r )转换为整数并保存这些值。在③行,用Python模块fractions内置的gcd()方法来计算半径的GCD。我们将用这些信息来确定曲线的周期性,在④行将它保存为self.nRot。最后,在⑤行,保存当前的角度,我们将用它来创建动画。

restart()方法

接下来,restart()方法重置Spiro对象的绘制参数,让它准备好重画:

  # 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()

这里用了布尔标志drawingComplete,来确定绘图是否已经完成,在①行初始化该标志。绘制多个Spiro对象时,这个标志是有用的,因为它可以追踪某个特定的螺线是否完成。在②行,显示海龟光标,以防它被隐藏。在③行提起笔,这样就可以在⑥行移动到第一个位置而不画线。在④行,使用了一些局部变量,以保持代码紧凑。然后,在⑤行,计算角度a设为0时的 x 和 y 坐标,以获得曲线的起点。最后,在⑦行,我们已完成,并落笔。Setpos()调用将绘制实际的线。

 draw()方法

draw()方法用连续的线段绘制该曲线。

  # 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()

在①行,迭代遍历参数i的完整范围,它以度表示,是360乘以nRot。在②行,计算参数i的每个值对应的 X 和 Y 坐标。在③行,隐藏光标,因为我们已完成绘制。

 创建动画

update()方法展示了一段一段绘制曲线来创建动画时所使用的绘图方法。

  # 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标志是否设置。如果没有设置,则继续执行代码其余的部分。在②行,update()增加当前的角度。从③行开始,它计算当前角度对应的(X,Y)位置并将海龟移到那里,在这个过程中画出线段。

讨论万花尺方程时,我提到了曲线的周期性。在一定的角度后,万花尺的图案开始重复。在④行,检查角度是否达这条特定曲线计算的完整范围。如果是这样,就设置drawingComplete标志,因为绘图完成了。最后,隐藏海龟光标,你可以看到自己美丽的创作。

SpiroAnimator类

SpiroAnimator类让我们同时绘制随机的螺线。该类使用一个计时器,每次绘制曲线的一段。这种技术定期更新图像,并允许程序处理事件,如按键、鼠标点击,等等。但是,这种计时器技术需要对绘制代码进行一些调整。

  # 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构造函数将DeltaT设置为10,这是以毫秒为单位的时间间隔,将用于定时器。在②行,保存海龟窗口的尺寸。然后在③行创建一个空数组,其中将填入一些Spiro对象。这些封装的万花尺绘制,然后循环N次(N传入给构造函数SpiroAnimator),在⑤行创建一个新的Spiro对象,并将它添加到Spiro对象的列表中。这里的rparams是一个元组,需要传入到Spiro构造函数。但是,构造函数需要一个参数列表,所以用Python的*运算符将元组转换为参数列表。

最后,在⑥行,设置turtle.ontimer()方法每隔DeltaT毫秒调用update()。

请注意,在④行调用了一个辅助方法,名为genRandomParams()。接下来就看看这个方法。

genRandomParams()方法

我们用genRandomParams()方法来生成随机参数,在每个Spiro对象创建时发送给它,来生成各种曲线。

  # 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)

为了生成随机数,利用来自Python的random模块的两个方法:randint(),它返回指定范围内的随机整数,以及uniform(),它对浮点数做同样的事。在①行,将R设置为50至窗口短边一半长度的随机整数,在②行,将r设置为R的10%至90%之间。

然后,在③行,将l设置为0.1至0.9之间的随机小数。在④和⑤行,在屏幕边界内随机选择 x 和 y 坐标,选择屏幕上的一个随机点作为螺线的中心。在⑥行随机设置为红、绿和蓝颜色的成分,为曲线指定随机的颜色。最后,在⑦行,所有计算的参数作为一个元组返回。

 重新启动程序

我们将用另一个restart()方法来重新启动程序。

# 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对象,清除以前绘制的每条螺线,分配新的螺线参数,然后重新启动程序。

 update()方法

下面的代码展示了SproAnimator中的update()方法,它由定时器调用,以动画的形式更新所有的Spiro对象:

  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()方法使用一个计数器nComplete来记录已画的Spiro对象的数目。在①行初始化后,它遍历Spiro对象的列表,在②行更新它们,如果一个Spiro完成,就在③行将计数器加1。

在循环外的④行,检查计数器,看看是否所有对象都已画完。如果已画完,调用restart()方法重新开始新的螺线动画。在⑤行restart()的末尾,调用计时器方法,它在DeltaT毫秒后再次调用update()。

显示或隐藏光标

最后,使用下面的方法来打开或关闭海龟光标。这可以让绘图更快。

 # 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()

在①行,隐藏海龟光标,这样就不会在最后的图形中看到它。然后,在②行,使用datetime(),利用当前时间和日期(以“日—月—年—时—分—秒”的格式),以生成图像文件的唯一名称。将这个字符串加在spiro-后面,生成文件名。

turtle程序采用tkinter创建的用户界面(UI)窗口,在③和④行,利用tkinter的canvas对象,将窗口保存为嵌入式PostScript(EPS)文件格式。由于EPS是矢量格式,你可以用高分辨率打印它,但PNG用途更广,所以在⑤行用Pillow打开EPS文件,并在⑥行将它保存为PNG文件。最后,在⑦行,取消隐藏海龟光标。

解析命令行参数和初始化

像第1章中一样,在main()方法中用argparse来解析传入程序的命令行选项。

① 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()

在①行,创建参数解析器对象,在②行,向解析器添加--sparams可选参数。在③行,调用函数进行实际的解析。

接下来,代码设置了一些turtle参数。

  # 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()将绘图窗口的宽度设置为80%的屏幕宽度(你也可以给setup指定高度和原点参数)。在②行,设置光标形状为海龟,在③行,设置程序窗口的标题为Spirographs!,在④行,利用onkey()和saveDrawing,在按下S时保存图画。然后,在⑤行,调用listen()让窗口监听用户事件。最后,在⑥行,隐藏海龟光标。

命令行参数解析后,代码的其余部分进行如下:

  # 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()

在①行,首先检查是否有参数赋给--sparams。如果有,就从字符串中提取它们,用“列表解析”将它们转换成浮点数②(列表解析是一种Python结构,让你以紧凑而强大的方式创建一个列表,例如,a=[2*x for x in range(1, 5)]创建前4个偶数的列表)。

在③行,利用任何提取的参数来构造Spiro对象(利用Python的*运算符,它将列表转换为参数)。然后,在④行,调用draw(),绘制螺线。

现在,如果命令行上没有指定参数,就进入随机模式。在⑤行,创建一个SpiroAnimator对象,向它传入参数4,告诉它创建4幅图画。在⑥行,利用onkey()来捕捉按键T,这样就可以用它来切换海龟光标(toggleTurtles),在⑦行,处理空格键(space),这样就可以用它在任何时候重新启动动画。最后,在⑧行,调用mainloop()告诉tkinter窗口保持打开,监听事件。

完整代码

可以从公众号pythondada输入万花尺索取完成代码。

些函数系统也帮忙打包好,以xxx.dll文件存放在ext、extras文件夹中,需要开启配置才能使用。这些函数称为扩展函数(extend)。

一、解决中文截取乱码mb_substr

echo mb_substr("中abc",0,2,"utf-8");

二、图片处理函数GD2

GD(graphic device,图形设备),负责在屏幕和打印机上输出信息。GD2是GDI的后续版本。要使用GD2,首先应该把网页打散作为图像(header),接着创建Graphics类对象(简单的来说,Graphics类对象就相当于画布,没画布我们在什么地方绘图呢?),然后调用一系列绘图方法即可,最后再生成图片、释放资源(destroy)。看下面的代码

步骤:

1、声明:把当前页面通过写代码的方式作为图片生成,语法:

header(“content-type:image/jpeg”);

2、绘图

3、生成图片(注意格式对应)

语法: imagejpeg();

4、释放资源(销毁材料)

语法:imagedestory();

其中绘图重要函数

//画点

Imagesetpixel

//画线

Imageline

//画矩形

Imagerectangle

//画圆

Imageellipse

//画实心矩形

Imagefilledrectangle

//画实心圆

imagefilledellipse

//画文字 不支持中文

Imagestring

//画竖排文字

Imagestringup

//画文字支持中文

Imagettftext

所有的绘画工作完成,可以使用img标签调用!!!

<img src=”xxxx.php”>

示例源码:

<?php

header("content-type:image/jpeg");

//执行绘图

//创建画布

$im=imagecreate(200,100);

//填充背景色

imagecolorallocate($im,100,100,100);

//定义颜色

$red=imagecolorallocate($im,255,255,255);

//画点

imagesetpixel($im,5,5,$red);

//画线

imageline($im,0,50,200,50,$red);

//画矩形

imagerectangle($im,100,10,130,40,$red);

//画圆

imageellipse($im,50,50,10,30,$red);

//画实心的矩形

imagefilledrectangle($im,70,10,100,40,$red);

//画实心圆

imagefilledellipse($im,40,20,10,30,$red);

//定义字体

$font="STXINGKA.TTF";

//画文字

imagestring($im,$font,100,30,'I LIKE TEACHER HE!',$red);

//画竖排文字

imagestringup($im,$font,180,90,'I LOVE TEACHER HE!',$red);

//画支持中文的文字

imagettftext($im,14,30,80,70,$red,$font,'我爱何老师!');

//生成图片

imagejpeg($im);

//想一想为什么在生成图片之后无法绘画

imagesetpixel($im,15,15,$red);

//释放资源

imagedestroy($im);

?>

TIPS:练习下多边形的多点坐标,可以使用图片热点技术。

利用GD2和前面的知识画标准验证码:

<?php

header("content-type:image/jpeg");

include_once("CheckNum.php");

$chnCount=6;//验证码位数

$chn=CreateCheckNumber($chnCount,7);

$fontSize=40;//字体的大小(宽度)

$width=ceil($chnCount*($fontSize+0.5));//验证码宽度

$height=$fontSize*2-2;//验证码高度

$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);

//画边框 注意边框粗细

imagerectangle($im,0,0,$width-1,$height-1,$fontColor);

//画干扰线

$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);

//画干扰点

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);

?>

文字水印:

以现有的图片作为画布再画上文字。

Imagecreatefromjpeg

<?php

header("content-type:image/gif");

//以现有的图片作为背景来创建画布

$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函数即可。

获取图片的宽度和高度

Imagesx、imagesy

<?php

header("content-type:image/jpeg");

//创建背景,作业:根据背景图创建对应格式的画布

$bgurl="bg.jpg";//改变背景图片格式

//$extName=mb_substr($bgurl,strrpos($bgurl,'.'),strlen($bgurl)-strrpos($bgurl,'.'));//背景图片扩展名

$extName=strrchr($bgurl,'.');

switch(strtolower($extName)){

case '.jpg':$bg=imagecreatefromjpeg($bgurl);break;

}

$water=imagecreatefrompng('logo.png');

//获取水印图片的宽高度

$w=imagesx($water);

$h=imagesy($water);

//作业:要求水印图片出现在右上角、做下角、右下角、居中

imagecopy($bg,$water,0,0,0,0,$w,$h);

//作业完善:背景图片水印图片的2倍及以上大才生成水印,否则不生成是原图

imagejpeg($bg);

imagedestroy($bg);

?>

作业:

1、在网站根目录下放4个图片,分别命名为1.gif.png.bmp.jPg、 2.gif、3.png、4.bmp 生成图片水印

2、图片水印图片可以在不同的位置出现,定义变量控制为左上角、右上角、左下角、右下角、居中

3、背景图片水印图片的2倍及以上大才生成水印,否则不生成是原图。

统计图:

柱状图实现思路:

用户传递的参数为数组,数组中元素个数为多少个单位;纵方向一般划分10个等距离单位意味数组100%,数组中的值在纵方向按百分比显示;缩放柱状图控制单位距离。

实现效果如下:

完整代码:

<?php

header("content-type:image/jpeg");

/* 建议按300*550来缩放,否则会变形 */

$pSize=50;//单位距离,控制缩放

$pNameArr=explode(',',$_REQUEST['dw']);//单位名称

$arr=explode(',',$_REQUEST['sj']);//需要生成统计图的数组数据

$im=imagecreate($pSize*(count($arr)+2),$pSize*(10+1));

imagecolorallocate($im,243,243,243);

$black=imagecolorallocate($im,0,0,0);

//画X轴

imageline($im,0,imagesy($im)-1,imagesx($im),imagesy($im)-1,$black);

//画Y轴

imageline($im,1,0,1,imagesy($im),$black);

//算出数组元素中所有元素的值

$sum=0;

foreach($arr as $v){

$sum+=$v;

}

//画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);

//画矩形

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]);

}

//画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);

?>

饼状图实现效果如下:

<?php

header("content-type:image/jpeg");

/* 建议按350*200来缩放,否则会变形 */

//定义圆半径

$raduis=100;

$arr=explode(',',$_REQUEST['sj']);//需要生成统计图的数组数

$pNameArr=explode(',',$_REQUEST['dw']);//单位名称

//计算数组总值

$sum=0;

//$maxFontSize=strlen($arr[0]);//最大文字内容长度

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;

//数据提示

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);

?>

补充:好吧,验证码比较难看,应大家要求,换个好看点的

复制代码

1.<?php

2.session_start();

3.header("content-type:image/png"); //设置创建图像的格式

4.$image_width=70; //设置图像宽度

5.$image_height=18; //设置图像高度

6.srand(microtime()*100000); //设置随机数的种子

7.for($i=0;$i<4;$i++){ //循环输出一个4位的随机数

8. $new_number.=rand(0,9);

9.}

10.$_SESSION[check_checks]=$new_number; //将获取的随机数验证码写入到SESSION变量中

11.

12.$num_image=imagecreate($image_width,$image_height); //创建一个画布

13.imagecolorallocate($num_image,255,255,255); //设置画布的颜色

14.for($i=0;$i<strlen($_SESSION[check_checks]);$i++){ //循环读取SESSION变量中的验证码

15. $font=mt_rand(3,5); //设置随机的字体

16. $x=mt_rand(1,8)+$image_width*$i/4; //设置随机字符所在位置的X坐标

17. $y=mt_rand(1,$image_height/4); //设置随机字符所在位置的Y坐标

18. $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); //设置字符的颜色

19. imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color); //水平输出字符

20.}

21.imagepng($num_image); //生成PNG格式的图像

22.imagedestroy($num_image); //释放图像资源

23.?>

三、header函数、iconv、get_loaded_extensions函数

header函数

1、声明图片

Header(“content-type:image/xxxx”);

2、当前页面强制转码

header("content-type:text/html;charset=utf-8");

3、强制跳转

header("location:http://www.xuewanwang.com");

……

详细请参阅 学玩网 header函数的用法

注意事项:header函数前不能有空格、回车(\n)、换行(\r)等非法内容;也不能包含任何输出的语句;不能放任何HTML标签,但是可以放到<html>之前

iconv字符串强制转码:

iconv("原来的编码","转出后的编码",$str);

Get_loaded_extensions() 判断是否开启对应函数库,返回支持库字符串数组