挂一个无耻搬运工:码农教程。
真的打心底里瞧不起为了蹭热度全网照抄代码的某些人。
再次此声明:代码不是python语言,求某些搬运工不要到处搬运害人。

 def setup():
size(600,600)
global x, y, vx, vy, bx, by, curBall, aliveBall
global COLOR, c, bc
#球需要有速度,位置,颜色三个属性
#对应x,y坐标、x,y速度、c #上方球由于固定,可以只有位置和颜色属性
#对应bx,by和bc x, y = width/2, height-15
#初始化球在中下位置,速度为0,颜色随机给一个
vx, vy = 0, 0
bx, by = [], []
curBall = []
aliveBall = []
COLOR = [color(227,41,54),color(41,188,227),color(41,227,48),color(250,239,13)]
#COLOR颜色列表,c和bc表示列表中的第几个颜色,而不是直接表示颜色
c = int(random(len(COLOR)))
bc = []
for i in range(20):
for j in range(10):
bx.append(i*30)
by.append( j*30)
curBall.append(len(curBall))#显示的球
aliveBall.append(len(aliveBall))#活着的球
bc.append(int(random(len(COLOR))))#死了的球 def draw():
global x, y, vx, vy, bx, by, curBall, aliveBall
global COLOR, c, bc background(255)
def findDead(i):
d = [i]#打中了第i号球,d[]记录接下来找到的应该死掉的球
def tmp(i):
for j in curBall:
#找和i相邻且同色的球,
#首先排除掉已经找到的球,然后需要颜色编号相同,其次需要距离小于两球半径之和
if j not in d and bc[j]==bc[i] and dist(bx[i],by[i],bx[j],by[j])<31:
d.append(j)#确认过眼神,找到对的球j,用小本本记下来
#接下来再找刚刚找到的球的下一个应该死掉的球
tmp(j)
tmp(i)
#这样一直找下一个该死的泡泡龙
#就得到了所有该死的球 (逃
return d #画会动的球
fill(COLOR[c])
ellipse(x,y,30,30) for i in curBall:
#画每个还没死的球
fill(COLOR[bc[i]])
ellipse(bx[i], by[i], 30, 30)
#检查有没有被撞到
if dist(bx[i], by[i], x, y)<30:
if bc[i] == c:
#某个同色球被撞到
#找它旁边该死的球,以及旁边该死的球的旁边的该死的球,以及*******
tmp = findDead(i)
#找到了这一次所有该死的球
#把他们从生死簿上重新做标记
#地狱+1
#人间-1
for t in tmp:
aliveBall.remove(t)
#不管有没有撞到该死的球,都应该飞回原点 (逃
x, y = width/2, height-15
vx, vy = 0, 0
#顺便换个马甲再来
c = int(random(len(COLOR)))
curBall = aliveBall[:]
#更新一下,现在显示的球全是没死的球
x += vx
y += vy
#左右碰壁就反弹
if x>width-15 or x<15:
vx = -vx
# 上面碰壁也反弹
if y<15:
vy = -vy
#下面碰壁就还原
if y>height-15:
x, y = width/2, height-15
vx, vy = 0, 0
#换个马甲
c = int(random(len(COLOR))) def mousePressed():
global vx, vy
#按下鼠标就发射,给个速度就可
vx = (mouseX-width/2)/100.0
vy = (mouseY-height+15)/100.0

processing-python-泡泡龙的更多相关文章

  1. 【320】Python 2.x 与 3.x 的区别

    通过代码移植的报错进行梳理! 1. print 函数的区别 Python 2.x 中可以加空格或者括号,但是 Python 3.x 只能是括号的 # Python 2.x >>> p ...

  2. [转]如何像Python高手(Pythonista)一样编程

    本文转自:http://xianglong.me/article/how-to-code-like-a-pythonista-idiomatic-python 最近在网上看到一篇介绍Pythonic编 ...

  3. [译] 如何像 Python 高手一样编程?

    转自:http://www.liuhaihua.cn/archives/23475.html Harries 发布于 7天前 分类:编程技术 阅读(15) 评论(0) 最近在网上看到一篇介绍Pytho ...

  4. .pyc & Python

    .pyc & Python Python bytecode / 字节码 Python compiles the .py files and saves it as .pyc files , s ...

  5. [转]Haroopad Markdown 编辑器代码语法高亮支持

    代码语法高亮 书写格式为: ` ` ` language_key if (condition){ return true } ` ` ` 在 ` ` ` (三个反引号)之间的是代码,其中languag ...

  6. Embedding Lua in C: Using Lua from inside C.

    Requirments:     1: The Lua Sources.    2: A C compiler - cc/gcc/g++ for Unix, and Visual C++ for Wi ...

  7. haroopad 语法高亮问题

    <!DOCTYPE html> Untitled.html div.oembedall-githubrepos{border:1px solid #DDD;border-radius:4p ...

  8. pandas 之 字符串处理

    import numpy as np import pandas as pd Python has long been a popular raw data manipulation language ...

  9. 简书 markdown 代码高亮标记

    SyntaxHighlight language language_key 1C 1c ActionScript actionscript Apache apache AppleScript a pp ...

  10. 【转】我们为什么要使用 Markdown

    目录 从前码字时我们面临着什么困境 标记语言显神威 到底什么是 Markdown 所以为什么我们要使用 Markdown Markdown 简明语法 段落和换行 标题 区块引用 列表 强调 代码标识和 ...

随机推荐

  1. Look into Bitmap images

    What's a Bitmap image? I'm not going to explain the differences between raster and vector images, no ...

  2. 一个自动修正数据时间和补全缺失数据的MapReduce程序

    原始数据如下图: 程序: Mapper类: public class DemoMapper extends Mapper<LongWritable,Text,IntWritable,Text&g ...

  3. Java虚拟机详解(十)------类加载过程

    在上一篇文章中,我们详细的介绍了Java类文件结构,那么这些Class文件是如何被加载到内存,由虚拟机来直接使用的呢?这就是本篇博客将要介绍的——类加载过程. 1.类的生命周期 类从被加载到虚拟机内存 ...

  4. linux运维与实践

    1.容器云计算节点负载值高,通过top可以看到Load Average:70.1  71.3  70.8,虚拟机有8个cpu: cpu使用率高导致(R状态)? 同时在top中观察一段时间,消耗cpu最 ...

  5. PostGIS 爆管分析之根据爆点找出所有影响阀门

    环境: Win10 ArcMap10.4(用于数据处理) postgresql9.4 postgis2.2.3 pgRouting2.3(postgresql插件) 说明: 做爆管分析的第一步,需要先 ...

  6. PHP数组具有的特性有哪些

    PHP 的数组是一种非常强大灵活的数据类型.以下是PHP数组具有的一些特性: 1.可以使用数字或字符串作为数组键值 1 $arr = [1 => 'ok', 'one' => 'hello ...

  7. Stream系列(一)Filter方法使用

    Filter 是过滤器,也可以当查询方法使用 EmployeeTestCase.java package com.example.demo; import lombok.extern.log4j.Lo ...

  8. Fortran文件读写--查找内容

    program ex implicit none character(len=) A(),B(),C() !A异常.B已开挖.C需标记 integer i,j,N1,N2,count !N1是10号文 ...

  9. 【Android - 控件】之V - SwipeRefreshLayout的使用

    SwipeRefreshLayout是Android V4.V7包中的一个控件,是Google给我们提供的一个下拉刷新的布局控件,可以轻松完成下拉刷新. SwipeRefreshLayout的特点是其 ...

  10. 复习sed实例操作

    第6周复习课(5月2日) 课程内容: 复习 扩展1.打印某行到某行之间的内容http://ask.apelearn.com/question/5592.sed转换大小写 http://ask.apel ...