Skip to content

Commit 4b368f1

Browse files
committed
more examples
1 parent 56a00ec commit 4b368f1

9 files changed

+659
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The Grafica library by Javier Graciá Carpio #
2+
3+
These examples have been lifted from the grafica library examples, however we use the ruby `csv` library rather the processing `loadTable` to load data. Further the examples have where possible been adapted to look like regular ruby.
4+
5+
### Obtaining Library
6+
7+
Get it [here][grafica] install in `~/.picrate/libraries` or local to sketch
8+
9+
See grafica repo [here][grafica] and website [here][php]
10+
11+
12+
[grafica]:https://github.com/jagracar/grafica
13+
[php]:https://jagracar.com/grafica.php
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to k9 executable, and or opts as required
3+
4+
SAMPLES_DIR="./"
5+
6+
desc 'run demo'
7+
task :default => [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each{|sample| run_sample sample}
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob("*.rb").each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|jruby #{sample_name}", "r") do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
year,month,day,oktoberfest,bundestagswahl
2+
2004,0,1,5,1
3+
2004,1,1,4,1
4+
2004,2,1,6,1
5+
2004,3,1,5,1
6+
2004,4,1,6,1
7+
2004,5,1,8,1
8+
2004,6,1,12,1
9+
2004,7,1,26,0
10+
2004,8,1,84,1
11+
2004,9,1,38,1
12+
2004,10,1,5,1
13+
2004,11,1,4,1
14+
2005,0,1,5,1
15+
2005,1,1,5,1
16+
2005,2,1,5,1
17+
2005,3,1,6,1
18+
2005,4,1,7,2
19+
2005,5,1,9,3
20+
2005,6,1,12,4
21+
2005,7,1,23,16
22+
2005,8,1,81,64
23+
2005,9,1,39,5
24+
2005,10,1,5,2
25+
2005,11,1,4,1
26+
2006,0,1,5,1
27+
2006,1,1,4,1
28+
2006,2,1,5,1
29+
2006,3,1,5,1
30+
2006,4,1,6,0
31+
2006,5,1,7,1
32+
2006,6,1,11,0
33+
2006,7,1,25,0
34+
2006,8,1,76,1
35+
2006,9,1,38,1
36+
2006,10,1,5,1
37+
2006,11,1,3,0
38+
2007,0,1,5,0
39+
2007,1,1,5,0
40+
2007,2,1,5,1
41+
2007,3,1,6,0
42+
2007,4,1,7,0
43+
2007,5,1,9,1
44+
2007,6,1,12,0
45+
2007,7,1,24,0
46+
2007,8,1,79,0
47+
2007,9,1,46,1
48+
2007,10,1,5,1
49+
2007,11,1,3,0
50+
2008,0,1,5,1
51+
2008,1,1,5,1
52+
2008,2,1,5,1
53+
2008,3,1,6,0
54+
2008,4,1,6,0
55+
2008,5,1,7,0
56+
2008,6,1,11,0
57+
2008,7,1,22,0
58+
2008,8,1,77,1
59+
2008,9,1,44,1
60+
2008,10,1,5,1
61+
2008,11,1,3,1
62+
2009,0,1,4,2
63+
2009,1,1,5,1
64+
2009,2,1,5,1
65+
2009,3,1,5,1
66+
2009,4,1,6,2
67+
2009,5,1,8,3
68+
2009,6,1,12,3
69+
2009,7,1,24,12
70+
2009,8,1,91,79
71+
2009,9,1,53,5
72+
2009,10,1,6,2
73+
2009,11,1,4,1
74+
2010,0,1,5,2
75+
2010,1,1,5,1
76+
2010,2,1,6,1
77+
2010,3,1,6,1
78+
2010,4,1,7,1
79+
2010,5,1,8,1
80+
2010,6,1,13,0
81+
2010,7,1,27,0
82+
2010,8,1,100,1
83+
2010,9,1,59,1
84+
2010,10,1,7,1
85+
2010,11,1,4,0
86+
2011,0,1,5,1
87+
2011,1,1,5,1
88+
2011,2,1,5,1
89+
2011,3,1,5,0
90+
2011,4,1,7,1
91+
2011,5,1,8,0
92+
2011,6,1,13,0
93+
2011,7,1,26,0
94+
2011,8,1,95,1
95+
2011,9,1,64,1
96+
2011,10,1,10,1
97+
2011,11,1,6,0
98+
2012,0,1,6,1
99+
2012,1,1,5,1
100+
2012,2,1,5,1
101+
2012,3,1,6,1
102+
2012,4,1,7,1
103+
2012,5,1,8,0
104+
2012,6,1,13,0
105+
2012,7,1,28,0
106+
2012,8,1,97,1
107+
2012,9,1,69,1
108+
2012,10,1,9,1
109+
2012,11,1,5,1
110+
2013,0,1,5,2
111+
2013,1,1,5,1
112+
2013,2,1,5,1
113+
2013,3,1,6,1
114+
2013,4,1,7,2
115+
2013,5,1,8,2
116+
2013,6,1,11,3
117+
2013,7,1,27,16
118+
2013,8,1,64,32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
country,income,health,population
2+
Central African Republic,599,53.8,4900274
3+
Somalia,624,58.7,10787104
4+
Burundi,777,60.4,11178921
5+
Malawi,799,60.22,17215232
6+
"Congo, Dem. Rep.",809,58.3,77266814
7+
Niger,943,62.2,19899120
8+
Liberia,958,63.9,4503438
9+
Eritrea,1129,62.9,5227791
10+
Mozambique,1176,56.4,27977863
11+
Guinea,1225,60.8,12608590
12+
Guinea-Bissau,1386,53.4,1844325
13+
North Korea,1390,71.4,25155317
14+
Madagascar,1400,64.7,24235390
15+
Togo,1433,64.23,7304578
16+
Comoros,1472,64.1,788474
17+
Ethiopia,1520,63.6,99390750
18+
Rwanda,1549,66.53,11609666
19+
Gambia,1644,65.1,1990924
20+
Burkina Faso,1654,62.8,18105570
21+
Uganda,1680,60.8,39032383
22+
Mali,1684,57.6,17599694
23+
Haiti,1710,65.3,10711067
24+
Zimbabwe,1801,60.01,15602751
25+
Kiribati,1824,62.4,112423
26+
Benin,1830,65.5,10879829
27+
Afghanistan,1925,57.63,32526562
28+
Solomon Islands,2047,64.1,583591
29+
Sierra Leone,2085,58.5,6453184
30+
Timor-Leste,2086,72.4,1184765
31+
Chad,2191,57.7,14037472
32+
Senegal,2251,66.1,15129273
33+
Nepal,2352,71.2,28513700
34+
Papua New Guinea,2529,60.6,7619321
35+
Tanzania,2571,63.43,53470420
36+
Tajikistan,2582,71,8481855
37+
Lesotho,2598,48.5,2135022
38+
Cameroon,2897,59.5,23344179
39+
Kenya,2898,66.63,46050302
40+
Vanuatu,2912,65,264652
41+
Sao Tome and Principe,3003,68.8,190344
42+
South Sudan,3047,58,12339812
43+
Djibouti,3139,64.63,887861
44+
Bangladesh,3161,70.1,160995642
45+
Kyrgyz Republic,3245,69,5939962
46+
Cambodia,3267,68.4,15577899
47+
Cote d'Ivoire,3491,60.33,22701556
48+
"Micronesia, Fed. Sts.",3510,67,104460
49+
Marshall Islands,3661,65.1,52993
50+
Mauritania,3877,65.7,4067564
51+
Yemen,3887,67.6,26832215
52+
Sudan,3975,69.5,40234882
53+
Myanmar,4012,67.9,53897154
54+
Zambia,4034,58.96,16211767
55+
Ghana,4099,65.5,27409893
56+
Honduras,4270,72.4,8075060
57+
West Bank and Gaza,4319,75.2,4668466
58+
Syria,4637,70.26,18502413
59+
Nicaragua,4712,76.8,6082032
60+
Pakistan,4743,66.5,188924874
61+
Moldova,4896,72.7,4068897
62+
Tonga,5069,70.5,106170
63+
Lao,5212,66.4,6802023
64+
Samoa,5558,72.2,193228
65+
Uzbekistan,5598,70.1,29893488
66+
Vietnam,5623,76.5,93447601
67+
Nigeria,5727,61.33,182201962
68+
India,5903,66.8,1311050527
69+
Swaziland,6095,51.5,1286970
70+
"Congo, Rep.",6220,61.9,4620330
71+
Bolivia,6295,72.3,10724705
72+
Cape Verde,6514,74.6,520502
73+
Guyana,6816,64.4,767085
74+
Philippines,6876,70.2,100699395
75+
Guatemala,7279,73.1,16342897
76+
Morocco,7319,74.7,34377511
77+
Georgia,7474,73.3,3999812
78+
Angola,7615,61,25021974
79+
Armenia,7763,74.4,3017712
80+
El Salvador,7776,74.1,6126583
81+
Fiji,7925,66.3,892145
82+
Bhutan,7983,70.2,774830
83+
Paraguay,8219,73.9,6639123
84+
Ukraine,8449,72.1,44823765
85+
Belize,8501,70,359287
86+
Jamaica,8606,75.5,2793335
87+
Bosnia and Herzegovina,9833,77.9,3810416
88+
St. Lucia,9997,74.5,184999
89+
Namibia,10040,61,2458830
90+
St. Vincent and the Grenadines,10435,72.9,109462
91+
Dominica,10503,74.6,72680
92+
Indonesia,10504,70.9,257563815
93+
Albania,10620,76,2896679
94+
Sri Lanka,10624,76.5,20715010
95+
Ecuador,10996,75.2,16144363
96+
Egypt,11031,71.3,91508084
97+
Tunisia,11126,77.3,11253554
98+
Grenada,11593,71.7,106825
99+
Jordan,11752,78.3,7594547
100+
Mongolia,11819,65.3,2959134
101+
Peru,11903,77.5,31376670
102+
South Africa,12509,63.72,54490406
103+
"Macedonia, FYR",12547,77,2078453
104+
Colombia,12761,75.8,48228704
105+
Dominican Republic,12837,73.8,10528391
106+
Serbia,12908,78.1,8850975
107+
Barbados,12984,75.8,284215
108+
China,13334,76.9,1376048943
109+
Algeria,13434,76.5,39666519
110+
Costa Rica,14132,80,4807850
111+
Maldives,14408,79.5,363657
112+
Thailand,14512,75.1,67959359
113+
Iraq,14646,72.1,36423395
114+
Montenegro,14833,75.8,625781
115+
Brazil,15441,75.6,207847528
116+
Iran,15573,78.5,79109272
117+
Venezuela,15753,75.8,31108083
118+
Turkmenistan,15865,67.9,5373502
119+
Bulgaria,16371,74.9,7149787
120+
Mexico,16850,74.5,127017224
121+
Azerbaijan,16986,72.9,9753968
122+
Lebanon,17050,78.5,5850743
123+
Suriname,17125,70.5,542975
124+
Botswana,17196,66.4,2262485
125+
Libya,17261,76.2,6278438
126+
Argentina,17344,76.2,43416755
127+
Belarus,17415,70.4,9495826
128+
Mauritius,18350,73.9,1273212
129+
Gabon,18627,60.53,1725292
130+
Romania,19203,76.8,19511324
131+
Turkey,19360,76.5,78665830
132+
Croatia,20260,78,4240317
133+
Uruguay,20438,77.3,3431555
134+
Panama,20485,78.2,3929141
135+
Antigua and Barbuda,21049,75.2,91818
136+
Cuba,21291,78.5,11389562
137+
Chile,22465,79.3,17948141
138+
Bahamas,22818,72.3,388019
139+
Russia,23038,73.13,143456918
140+
Latvia,23282,75.7,1970503
141+
Kazakhstan,23468,68.2,17625226
142+
Hungary,24200,76.2,9855023
143+
Malaysia,24320,75.1,30331007
144+
Poland,24787,77.3,38611794
145+
Greece,25430,79.8,10954617
146+
Seychelles,25684,73.7,96471
147+
Portugal,26437,79.8,10349803
148+
Lithuania,26665,75.4,2878405
149+
Estonia,26812,76.8,1312558
150+
Slovak Republic,27204,76.4,5426258
151+
Slovenia,28550,80.2,2067526
152+
Czech Republic,29437,78.6,10543186
153+
Cyprus,29797,82.6,1165300
154+
Trinidad and Tobago,30113,71.4,1360088
155+
Malta,30265,82.1,418670
156+
Equatorial Guinea,31087,60.63,845060
157+
Israel,31590,82.4,8064036
158+
Spain,32979,81.7,46121699
159+
Italy,33297,82.1,59797685
160+
New Zealand,34186,80.6,4528526
161+
South Korea,34644,80.7,50293439
162+
Japan,36162,83.5,126573481
163+
France,37599,81.9,64395345
164+
United Kingdom,38225,81.4,64715810
165+
Finland,38923,80.8,5503457
166+
Belgium,41240,80.4,11299192
167+
Iceland,42182,82.8,329425
168+
Canada,43294,81.7,35939927
169+
Denmark,43495,80.1,5669081
170+
Germany,44053,81.1,80688545
171+
Australia,44056,81.8,23968973
172+
Bahrain,44138,79.2,1377237
173+
Austria,44401,81,8544586
174+
Sweden,44892,82,9779426
175+
Netherlands,45784,80.6,16924929
176+
Andorra,46577,84.1,70473
177+
Ireland,47758,80.4,4688465
178+
Oman,48226,75.7,4490541
179+
Saudi Arabia,52469,78.1,31540372
180+
United States,53354,79.1,321773631
181+
Switzerland,56118,82.9,8298663
182+
United Arab Emirates,60749,76.6,9156963
183+
Norway,64304,81.6,5210967
184+
Brunei,73003,78.7,423188
185+
Singapore,80794,82.1,5603740
186+
Kuwait,82633,80.7,3892115
187+
Luxembourg,88314,81.1,567110
188+
Qatar,132877,82,2235355
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env jruby
2+
3+
require 'picrate'
4+
5+
class DefaultPlot < Processing::App
6+
load_library :grafica
7+
java_import 'grafica.GPlot'
8+
java_import 'grafica.GPointsArray'
9+
POINTS = 100
10+
11+
def settings
12+
size(500, 350)
13+
end
14+
15+
def setup
16+
sketch_title 'default plot'
17+
background(150)
18+
19+
# Prepare the points for the plot
20+
points = GPointsArray.new(POINTS)
21+
22+
POINTS.times do |i|
23+
points.add(i, 10 * noise(0.1 * i))
24+
end
25+
26+
# Create a new plot and set its position on the screen
27+
plot = GPlot.new(self)
28+
plot.set_pos(25, 25)
29+
30+
# Set the plot title and the axis labels
31+
plot.set_points(points)
32+
plot.getXAxis.setAxisLabelText("x axis")
33+
plot.getYAxis.setAxisLabelText("y axis")
34+
plot.setTitleText("A very simple example")
35+
36+
# Draw it!
37+
plot.default_draw
38+
end
39+
end
40+
41+
DefaultPlot.new

0 commit comments

Comments
 (0)