1.çè±ä»£ç ç¼ç¨python(ç«ç°è±ä»£ç ç¼ç¨python)
çè±ä»£ç ç¼ç¨python(ç«ç°è±ä»£ç ç¼ç¨python)
æ¾çè±ç代ç
#-*-coding:utf-8-*-importmath,unity 源码学习random,timeimportthreadingimporttkinterastkimportreuuidFireworks=[]maxFireworks=8height,width=,classfirework(object):def__init__(self,color,speed,width,height):=uuid.uuid1()self.radius=random.randint(2,4)~4åç´ self.color=colorself.speed=speed.5-3.5ç§self.status=0ï¼status=0ï¼çç¸åï¼status=1ï¼å½statusæ¶ï¼çè±ççå½æç»æ¢self.nParticle=random.randint(,)self.center=[random.randint(0,width-1),random.randint(0,height-1)]self.oneParticle=[]ï¼%ç¶ææ¶ï¼self.rotTheta=random.uniform(0,2*math.pi)ï¼x=a*cos(theta),y=b*sin(theta)=[a,b]
pythonç«é ·çè±è¡¨ç½æºä»£ç æ¯å¤å°ï¼å¦å®æ¬æç¨åï¼ä½ ä¹è½ååºè¿æ ·ççè±ç§ã
å¦ä¸å¾ç¤ºï¼æ们è¿ééè¿è®©ç»é¢ä¸ä¸ä¸ªç²ååè£ä¸ºXæ°éçç²åæ¥æ¨¡æçç¸ææãç²åä¼åçï¼è¨èâï¼æææ¯å®ä»¬ä¼ä»¥æé移å¨ä¸ç¸äºä¹é´çè§åº¦ç¸çãè¿æ ·å°±è½è®©æ们以ä¸ä¸ªåå¤è¨èçååå½¢å¼æ¨¡æåºçè±ç»½æ¾çç»é¢ã
ç»è¿ä¸å®æ¶é´åï¼ç²åä¼è¿å ¥ï¼èªç±è½ä½âé¶æ®µï¼ä¹å°±æ¯ç±äºéåå ç´ å®ä»¬å¼å§å è½å°å°é¢ï¼ä»¿è¥ç»½æ¾åççççè±ã
åºæ¬ç¥è¯ï¼ç¨PythonåTkinter设计çè±ã
è¿éä¸åä¸è¡èææ°å¦ç¥è¯å ¨ä¸¢åºæ¥ï¼æ们边å代ç 边说ç论ãé¦å ï¼ç¡®ä¿ä½ å®è£ åå¯¼å ¥äºTkinterï¼å®æ¯Pythonçæ åGUIåºï¼å¹¿æ³åºç¨äºåç§åæ ·ç项ç®åç¨åºå¼åï¼å¨Pythonä¸ä½¿ç¨Tkinterå¯ä»¥å¿«éçå建GUIåºç¨ç¨åºã
importtkinterastk
fromPILimportImage,ImageTk
fromtimeimporttime,sleep
fromrandomimportchoice,uniform,randint
frommathimportsin,cos,radians
é¤äºTkinterä¹å¤ï¼ä¸ºäºè½è®©çé¢ææ¼äº®çèæ¯ï¼æ们ä¹å¯¼å ¥PILç¨äºå¾åå¤çï¼ä»¥åå¯¼å ¥å ¶å®ä¸äºå ï¼æ¯å¦timeï¼randomåmathãå®ä»¬è½è®©æ们æ´å®¹æçæ§å¶çè±ç²åçè¿å¨è½¨è¿¹ã
Tkinteråºç¨çåºæ¬è®¾ç½®å¦ä¸ï¼
root=tk.Tk()
为äºè½åå§åTkinterï¼æä»¬å¿ é¡»å建ä¸ä¸ªTk()æ ¹é¨ä»¶ï¼rootwidgetï¼ï¼å®æ¯ä¸ä¸ªçªå£ï¼å¸¦ææ é¢æ åç±çªå£ç®¡çå¨æä¾çå ¶å®è£ 饰ç©ãè¯¥æ ¹é¨ä»¶å¿ é¡»å¨æ们åå»ºå ¶å®å°é¨ä»¶ä¹åå°±å建å®æ¯ï¼èä¸åªè½æä¸ä¸ªæ ¹é¨ä»¶ã
w=tk.Label(root,text="HelloTkinter!")
è¿ä¸è¡ä»£ç å å«äºLabelé¨ä»¶ã该Labelè°ç¨ä¸ç第ä¸ä¸ªåæ°å°±æ¯ç¶çªå£çååï¼å³æ们è¿éç¨çï¼æ ¹âãå ³é®ååæ°ï¼textâæææ¾ç¤ºçæåå 容ãä½ ä¹å¯ä»¥è°ç¨å ¶å®å°é¨ä»¶ï¼Buttonï¼Canvasççã
w.pack()
root.mainloop()
æ¥ä¸æ¥çè¿ä¸¤è¡ä»£ç å¾éè¦ãè¿éçæå æ¹æ³æ¯åè¯Tkinterè°æ´çªå£å¤§å°ä»¥éåºæç¨çå°é¨ä»¶ãçªå£ç´å°æ们è¿å ¥Tkinteräºä»¶å¾ªç¯ï¼è¢«root.mainloop()è°ç¨æ¶æä¼åºç°ãå¨æä»¬å ³éçªå£åï¼èæ¬ä¼ä¸ç´å¨åçå¨äºä»¶å¾ªç¯ã
å°çè±ç»½æ¾è½¬è¯æ代ç
ç°å¨æ们设计ä¸ä¸ªå¯¹è±¡ï¼è¡¨ç¤ºçè±äºä»¶ä¸çæ¯ä¸ªç²åãæ¯ä¸ªç²åé½ä¼æä¸äºéè¦çå±æ§ï¼æ¯é äºå®çå¤è§å移å¨ç¶åµï¼å¤§å°ï¼é¢è²ï¼ä½ç½®ï¼é度ççã
跨年çè±ä»£ç ï½ç¨Pythonéä½ ä¸åºè·¨å¹´çè±ç§å·²ç»æ¥è¿å°¾å£°äºï¼å³å°å°æ¥ï¼æ¬ææ们ç¨Pythonéä½ ä¸åºè·¨å¹´çè±ç§ã
æ们ç¨å°çPython模åå æ¬ï¼tkinterãPILãtimeãrandomãmathï¼å¦æ第ä¸æ¹æ¨¡å没æè£ çè¯ï¼pipinstallä¸ä¸å³å¯ï¼ä¸é¢çä¸ä¸ä»£ç å®ç°ã
导åº
çè±é¢è²
å®ä¹çè±ç±»
çæ¾çè±
å¯å¨
çä¸ä¸ææï¼
年跨年çè±ä»£ç å¯å¤å¶
çè±ä»£ç å¦ä¸ï¼
packagelove;
importjava.applet.Applet;
importjava.awt.Color;
importjava.awt.Graphics;
importjava.net.URL;
importjava.util.Random;
çè±
@authorenjoy
@SuppressWarnings("serial")
publicclassQextendsAppletimplementsRunnable
publicintspeed,variability,Max_Number,Max_Energy,Max_Patch,
Max_Length,G;
publicStringsound;
privateintwidth,height;
privateThreadthread=null;
privateBeaClassDemobcd[];
publicvoidinit()?
inti;
this.setSize(,);
width=getSize().width-1;
height=getSize().height-1;
speed=1;?//çè±ç»½æ¾çé度
variability=;
Max_Number=;?//å¯ååºçè±çæ大æ°ç®
Max_Energy=width+;
Max_Patch=;?//æ大çæç¹æ°
Max_Length=;?//æç¹çæ大è·ç¦»
G=;?//åå°é¢å¼¯æ²çå度
bcd=newBeaClassDemo[Max_Number];
for(i=0;iMax_Number;i++)
bcd[i]=newBeaClassDemo(width,height,G);
}
publicvoidstart(){
if(thread==null){
thread=newThread(this);
thread.start();
}
}
@SuppressWarnings("deprecation")
publicvoidstop(){
if(thread!=null){
thread.stop();
thread=null;
}
}
@SuppressWarnings({ "unused","static-access"})
publicvoidrun(){
inti;
intE=(int)(Math.random()*Max_Energy*3/4)+Max_Energy/4+1;
intP=(int)(Math.random()*Max_Patch*3/4)?//çè±çæç¹æ°
+Max_Patch/4+1;
intL=(int)(Math.random()*Max_Length*3/4)?//çè±å¯åå°åºçè·ç¦»
+Max_Length/4+1;
longS=(long)(Math.random()*);
booleansleep;
Graphicsg=getGraphics();
URLu=null;
while(true){
try{
thread.sleep(/speed);
catch(InterruptedExceptionx){
sleep=true;
for(i=0;iMax_Number;i++)
sleep=sleepbcd[i].sleep;
if(sleepMath.random()*variability){
E=(int)(Math.random()*Max_Energy*3/4)+Max_Energy/4
+1;
P=(int)(Math.random()*Max_Patch*3/4)+Max_Patch/4
+1;
L=(int)(Math.random()*Max_Length*3/4)+Max_Length/4
+1;
S=(long)(Math.random()*);
for(i=0;iMax_Number;i++){
if(bcd[i].sleepMath.random()*Max_Number*L1)
bcd[i].init(E,P,L,S);
bcd[i].start();
bcd[i].show(g);
publicvoidpaint(Graphicsg)?
g.setColor(Color.black);
g.fillRect(0,0,width+1,height+1);
classBeaClassDemo
publicbooleansleep=true;
privateintenergy,patch,length,width,height,G,Xx,Xy,Ex[],Ey[],x,
y,Red,Blue,Green,t;
privateRandomrandom;
publicBeaClassDemo(inta,intb,intg)
width=a;
height=b;
G=g;
publicvoidinit(inte,intp,intl,longseed)?
inti;
energy=e;
patch=p;
length=l;
//å建ä¸ä¸ªå¸¦ç§åçéæºæ°çæå¨
random=newRandom(seed);
Ex=newint[patch];
Ey=newint[patch];
Red=(int)(random.nextDouble()*)+;
Blue=(int)(random.nextDouble()*)+;
Green=(int)(random.nextDouble()*)+;
Xx=(int)(Math.random()*width/2)+width/4;
Xy=(int)(Math.random()*height/2)+height/4;
for(i=0;ipatch;i++){
Ex[i]=(int)(Math.random()*energy)-energy/2;
Ey[i]=(int)(Math.random()*energy*7/8)-energy/8;
publicvoidstart
t=0;
sleep=false;
publicvoidshow(Graphicsg)?
if(!sleep)
if(tlength)
inti,c;
doubles;
Colorcolor;
c=(int)(random.nextDouble()*)-+Red;
if(c=0c)
Red=c;
c=(int)(random.nextDouble()*)-+Blue;
if(c=0c)
Blue=c;
c=(int)(random.nextDouble()*)-+Green;
if(c=0c)
Green=c;
color=newColor(Red,Blue,Green);
for(i=0;ipatch;i++)
s=(double)t/;
x=(int)(Ex[i]*s);
y=(int)(Ey[i]*s-G*s*s);
g.setColor(color);
g.drawLine(Xx+x,Xy-y,Xx+x,Xy-y);
if(t=length/2)
intj;
for(j=0;j2;j++)
s=(double)((t-length/2)*2+j)/;
x=(int)(Ex[i]*s);
y=(int)(Ey[i]*s-G*s*s);
g.setColor(Color.black);
g.drawLine(Xx+x,Xy-y,Xx+x,Xy-y);
常ç¨çç¼ç¨è¯è¨ã
ç¼ç¨è¯è¨ä¸ï¼Cè¯è¨
Cè¯è¨æ¯ä¸çä¸ææµè¡ã使ç¨æ广æ³çé«çº§ç¨åºè®¾è®¡è¯è¨ä¹ä¸ãå¨æä½ç³»ç»åç³»ç»ä½¿ç¨ç¨åºä»¥åéè¦å¯¹ç¡¬ä»¶è¿è¡æä½çåºåï¼ç¨Cè¯è¨ææ¾ä¼äºå ¶å®é«çº§è¯è¨ï¼è®¸å¤å¤§ååºç¨è½¯ä»¶é½æ¯ç¨Cè¯è¨ç¼åçã
ç¼ç¨è¯è¨äº:java
Javaæ¯ä¸ç§å¯ä»¥æ°å跨平å°åºç¨è½¯ä»¶çé¢å对象çç¨åºè®¾è®¡è¯è¨ï¼æ¯ç±SunMicrosystemså ¬å¸äºå¹´5ææ¨åºçJavaç¨åºè®¾è®¡è¯è¨åJavaå¹³å°ï¼å³JavaSE,JavaEE,JavaMEï¼çæ»ç§°ã
ç¼ç¨è¯è¨ä¸:c++
C++è¿ä¸ªè¯å¨ä¸å½å¤§éçç¨åºåååä¸é常被读åâCå å âï¼è西æ¹çç¨åºåé常读åâCplusplus","CPPâãå®æ¯ä¸ç§ä½¿ç¨é常广æ³ç计ç®æºç¼ç¨è¯è¨ãC++æ¯ä¸ç§éææ°æ®ç±»åæ£æ¥çãæ¯æå¤éç¼ç¨èå¼çéç¨ç¨åºè®¾è®¡è¯è¨ã