这个挺有意思:Ruby 的 UI 库向来不怎么样,所以这里用的 Gosu 这个2d游戏引擎(其实是包装了Gosu 的 Chingu),顺便加了点料。
[代码] mona_lisa.rb
01 |
#!/usr/bin/env ruby |
02 |
require "chingu"
|
03 |
04 |
include Gosu |
05 |
include Chingu |
06 |
07 |
class MonaLisa < Chingu::Window
|
08 |
def initialize
|
09 |
super ( 600 , 550 , false )
|
10 |
self .input = { :esc => :exit }
|
11 |
push_game_state(Paint)
|
12 |
end
|
13 |
end |
14 |
15 |
class Pix < Chingu::GameObject
|
16 |
traits :velocity
|
17 |
def initialize(options)
|
18 |
super (options)
|
19 |
end
|
20 |
21 |
def drop
|
22 |
if rand( 2 ) == 0
|
23 |
@velocity_x = rand( 0 .. 2 )
|
24 |
else
|
25 |
@velocity_x = -rand( 0 .. 2 )
|
26 |
end
|
27 |
@velocity_y = rand( 0 .. 3 )
|
28 |
@acceleration_y = 1
|
29 |
end
|
30 |
31 |
def setup
|
32 |
@image = Image[ "rect.png" ]
|
33 |
end
|
34 |
end |
35 |
36 |
class Paint < Chingu::GameState
|
37 |
38 |
def initialize
|
39 |
@ground_y = $window .height+ 20
|
40 |
super
|
41 |
end
|
42 |
43 |
def setup
|
44 |
super
|
45 |
IO .readlines( "media/ml" ). each do |line|
|
46 |
arr = line.chomp.split( "x" )
|
47 |
x = arr[ 0 ].to_i
|
48 |
y = arr[ 1 ].to_i
|
49 |
w = arr[ 2 ].to_i
|
50 |
h = arr[ 3 ].to_i
|
51 |
r = arr[ 4 ][ 0 ... 2 ].to_i( 16 )
|
52 |
g = arr[ 4 ][ 2 ... 4 ].to_i( 16 )
|
53 |
b = arr[ 4 ][ 4 ... 6 ].to_i( 16 )
|
54 |
|
55 |
end
|
56 |
self .input = { :space => :drop }
|
57 |
end
|
58 |
59 |
def drop
|
60 |
Pix. each { |pix| pix.drop }
|
61 |
end
|
62 |
63 |
def update
|
64 |
Pix. each do |p|
|
65 |
if p.y >= @ground_y
|
66 |
slower = p.velocity_y / 3
|
67 |
p.velocity_y = -(slower + rand(slower))
|
68 |
if rand( 2 ) == 0
|
69 |
p.velocity_x = rand( 0 . 4 )
|
70 |
p.acceleration_x = -(rand( 0 . 05 ))
|
71 |
else
|
72 |
p.velocity_x = -rand( 0 . 4 )
|
73 |
p.acceleration_x = (rand( 0 . 05 ))
|
74 |
end
|
75 |
end
|
76 |
end
|
77 |
super
|
78 |
end
|
79 |
end |
80 |
81 |
MonaLisa. new .show
|
相关推荐
使用html实现的蒙娜丽莎的微笑,可以用来学习的例子。适用于各种热爱编程的人员参考。
这是大神用css box-shadow属性制作的纯css蒙娜丽莎的微笑,整个作品用css绘制了5000多个点,制作的蒙娜丽莎惟妙惟肖,达芬奇看了一定为之抓狂。
鄂教版七年级上语文:第18课《蒙娜丽莎微笑揭秘》同步练习精选.doc
七年级语文上:第18课《蒙娜丽莎微笑揭秘》同步练习(鄂教版).doc
蒙娜丽莎的微笑作文.doc
PaintMonaLisaSmile 是 Java 版绘制蒙娜丽莎的微笑工具。
没错,今天我们要分享的就是这个使用纯CSS3,没有使用任何图片的蒙娜丽莎画像,实现原理是利用CSS3的阴影特性,逐层用不同的颜色渲染,从而形成这幅蒙娜丽莎巨作,当然有点模糊是肯定的,毕竟是通过投影渲染的,...
《蒙娜丽莎》的神秘微笑之谜.ppt
浙江省温州市瓯海区实验八年级历史与社会下册《蒙娜丽莎的微笑、教皇奶牛的解放》教案 人教版.doc
(2020年秋季版)七年级道德与法治下册 第一单元 人与人之间 第三课 交往有艺术 精品阅读 蒙娜丽莎的微笑素材 教科版.doc
TweenMax.js实现蒙娜丽莎画像像素波动的动画效果源码.zip
p5.js实现的点彩画法动画蒙娜丽莎画像效果源码.zip
蒙娜丽莎:2019年年度报告.PDF
蒙娜丽莎:2019年半年度报告.PDF
蒙娜丽莎-002918-深度:产品力、渠道及成本管控优异的瓷砖行业龙头
蒙娜丽莎:首次公开发行股票并上市招股说明书.PDF
蒙娜丽莎抠图插件Ultimatte AdvantEdge v1.6安装方法:1.首先运行Ultimatte AdvantEdge.EXE安装程序。 2.安装完后选择不要重启 ! ! ! 把crack中的文件复制到安装目录下覆盖完成破解。 3.然后运行 PS 如果提示找不...
PS合成搞笑凤姐版的蒙娜丽莎照片,非常仔细,望大家观看
蒙娜丽莎-002918-B端C端均衡发展,产能优势持续加码.pdf