Skip to content

Commit 7b3d511

Browse files
committed
more mods and additions
1 parent 7ee306e commit 7b3d511

15 files changed

+3079
-0
lines changed

basics/math/noise_animation.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
4+
class NoiseAnimation < Processing::App
5+
6+
AMOUNT = 2.5
7+
SCALE = 0.03
8+
RADIUS = 0.45
9+
FRAMES = 100
10+
11+
def field(x, y)
12+
count = frame_count - 1
13+
value1 = 400.0 * noise(SCALE * x, SCALE * y, RADIUS * cos(TWO_PI * 1.0 * count / FRAMES),
14+
RADIUS * sin(TWO_PI * 1.0 * count / FRAMES))
15+
value2 = 400.0 * noise(1000 + SCALE * x, SCALE * y, RADIUS * cos(TWO_PI * 1.0 * count / FRAMES),
16+
RADIUS * sin(TWO_PI * 1.0 * count / FRAMES))
17+
# int value2 = (int) Math.round(value)
18+
parameter1 = value1 / FRAMES
19+
parameter2 = value2 / FRAMES
20+
# if(random(100)<1) println(parameter)
21+
Vec2D.new(AMOUNT * parameter1, AMOUNT * parameter2)
22+
end
23+
24+
def settings
25+
size(500, 500)
26+
end
27+
28+
def setup
29+
sketch_title 'Noise Animation'
30+
end
31+
32+
def draw
33+
background(0)
34+
grid(width - 300, height - 300, 5, 5) do |i, j|
35+
stroke(255, 25)
36+
no_fill
37+
pos = Vec2D.new(i + 150, j + 150)
38+
point(pos.x, pos.y)
39+
200.times do
40+
res = field(pos.x, pos.y)
41+
res *= 0.15
42+
pos += res
43+
point(pos.x, pos.y)
44+
end
45+
point(pos.x, pos.y)
46+
end
47+
# puts frame_count
48+
save_frame(data_path('fr###.tiff'))
49+
50+
return unless frame_count == FRAMES
51+
52+
# save_frame(data_path('expt6.png'))
53+
no_loop
54+
puts 'finished'
55+
end
56+
end
57+
58+
NoiseAnimation.new

basics/math/noise_image.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'picrate'
2+
# OpenSimplex2 has a range -1.0 to 1.0
3+
class NoiseImage < Processing::App
4+
SCALE = 0.02
5+
6+
def setup
7+
sketch_title 'Noise Image'
8+
background(0)
9+
stroke(255)
10+
no_fill
11+
end
12+
13+
def draw
14+
background(0)
15+
scale = 0.02
16+
load_pixels
17+
grid(500, 500) do |x, y|
18+
col = noise(SCALE * x, SCALE * y) > 0 ? 255 : 0
19+
pixels[x + width * y] = color(col, 0, 0)
20+
end
21+
update_pixels
22+
save(data_path('noise_image.png'))
23+
end
24+
25+
def settings
26+
size 500, 500
27+
end
28+
end
29+
30+
NoiseImage.new

library/pdf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pdf

library/pdf/complex_3D.rb

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
require 'picrate'
2+
3+
class Complex3D < Processing::App#
4+
# Geometry
5+
# by Marius Watz.
6+
#
7+
load_library :pdf
8+
include_package 'processing.pdf'
9+
attr_reader :num, :pt, :style, :dosave
10+
11+
def setup
12+
sketch_title 'Complex 3 D'
13+
background(255)
14+
@dosave = false
15+
@num = 150
16+
@pt = []
17+
@style = []
18+
# Set up arc shapes
19+
index = 0
20+
(0...num).each do |i|
21+
pt << rand(TAU) # Random X axis rotation
22+
pt << rand(TAU) # Random Y axis rotation
23+
pt << rand(60..80) # Short to quarter-circle arcs
24+
pt[pt.length - 1] = rand(8..27) * 10 if rand(100) > 90
25+
pt << rand(2..50) * 5 # Radius. Space them out nicely
26+
pt << rand(4..32) # Width of band
27+
pt[pt.length - 1] = rand(40..60) if (rand(100) > 90) # Width of band
28+
pt << rand(0.005..0.0334)# Speed of rotation
29+
# get colors
30+
prob = rand(100)
31+
case prob
32+
when (0..30)
33+
style[i * 2] = color_blended(rand, 255,0,100, 255,0,0, 210)
34+
when (30..70)
35+
style[i * 2] = color_blended(rand, 0,153,255, 170,225,255, 210)
36+
when (70..90)
37+
style[i * 2] = color_blended(rand, 200,255,0, 150,255,0, 210)
38+
else
39+
style[i * 2] = color(255,255,255, 220)
40+
end
41+
case prob
42+
when (0..50)
43+
style[i * 2] = color_blended(rand, 200,255,0, 50,120,0, 210)
44+
when (50..90)
45+
style[i * 2] = color_blended(rand, 255,100,0, 255,255,0, 210)
46+
else
47+
style[i * 2] = color(255, 255, 255, 220)
48+
style[i * 2 + 1] = rand(100) % 3
49+
end
50+
end
51+
end
52+
53+
def draw
54+
if dosave
55+
# set up PGraphicsPDF for use with beginRaw
56+
pdf = begin_raw(PDF, data_path('pdf_complex_out.pdf'))
57+
# set default Illustrator stroke styles and paint background rect.
58+
pdf.stroke_join(MITER)
59+
pdf.stroke_cap(SQUARE)
60+
pdf.fill(0)
61+
pdf.no_stroke
62+
pdf.rect(0, 0, width, height)
63+
end
64+
background(0)
65+
index = 0
66+
translate(width / 2, height / 2, 0)
67+
rotate_x(PI / 6)
68+
rotate_y(PI / 6)
69+
(0 ... num).each do |i|
70+
push_matrix
71+
rotate_x(pt[index])
72+
rotate_y(pt[index + 1])
73+
index += 2
74+
case (style[i * 2 + 1])
75+
when 0
76+
stroke(style[i * 2])
77+
no_fill
78+
stroke_weight(1)
79+
arc_line(0, 0, pt[index], pt[index + 1], pt[index + 2])
80+
index += 3
81+
when 1
82+
fill(style[i * 2])
83+
no_stroke
84+
arc_line_bars(0, 0, pt[index], pt[index + 1],pt[index + 2])
85+
index += 3
86+
else
87+
fill(style[i * 2])
88+
no_stroke
89+
arc(0, 0, pt[index], pt[index + 1], pt[index + 2])
90+
index += 3
91+
end
92+
# increase rotation
93+
pt[index - 5] += pt[index] / 10
94+
pt[index - 4] += pt[index] / 20
95+
index += 1
96+
pop_matrix
97+
end
98+
if dosave
99+
end_raw
100+
@dosave=false
101+
end
102+
end
103+
104+
# Get blend of two colors
105+
def color_blended(fract, r, g, b, r2, g2, b2, a)
106+
r2 = (r2 - r)
107+
g2 = (g2 - g)
108+
b2 = (b2 - b)
109+
color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a)
110+
end
111+
112+
# Draw arc line
113+
def arc_line(x, y, deg, rad, w)
114+
a = (deg < 360)? deg : 0
115+
numlines = w / 2
116+
(0...numlines).each do
117+
begin_shape
118+
(0...a).each do |i|
119+
vertex(DegLut.cos(i) * rad + x, DegLut.sin(i) * rad + y)
120+
end
121+
end_shape
122+
rad += 2
123+
end
124+
end
125+
126+
# Draw arc line with bars
127+
def arc_line_bars(x, y, deg, rad, w)
128+
a=(deg < 360)? deg / 16 : 0
129+
begin_shape(QUADS)
130+
(0...a).step(4) do |i|
131+
vertex(DegLut.cos(i) * rad + x,DegLut.sin(i) * (rad) + y)
132+
vertex(DegLut.cos(i) * (rad + w) + x,DegLut.sin(i) * (rad + w) + y)
133+
vertex(DegLut.cos((i + 2)) * (rad + w) + x, DegLut.sin((i + 2)) * (rad + w) + y)
134+
vertex(DegLut.cos((i + 2)) * rad + x, DegLut.sin((i + 2)) * rad + y)
135+
end
136+
end_shape
137+
end
138+
139+
# Draw solid arc
140+
def arc(x, y, deg, rad, w)
141+
a = (deg < 360)? deg : 0
142+
begin_shape(QUAD_STRIP)
143+
(0...a).each do |i|
144+
vertex(DegLut.cos(i) * rad + x, DegLut.sin(i) * rad + y)
145+
vertex(DegLut.cos(i) * (rad + w) + x, DegLut.sin(i) * (rad + w) + y)
146+
end
147+
end_shape
148+
end
149+
150+
def mouse_pressed
151+
@dosave = true
152+
end
153+
154+
def settings
155+
size(1024, 768, P3D)
156+
end
157+
end
158+
Complex3D.new

library/pdf/large_page.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'picrate'
2+
3+
class LargePage < Processing::App
4+
#
5+
# Large Page.
6+
#
7+
# Saves one frame as a PDF with a size larger
8+
# than the screen. When PDF is used as the renderer
9+
# (the third parameter of size) the display window
10+
# does not open. The file is saved to the sketch folder.
11+
load_libraries 'pdf'
12+
include_package 'processing.pdf'
13+
14+
def setup
15+
sketch_title 'Large Page'
16+
end
17+
18+
def draw
19+
background(255)
20+
stroke(0, 20)
21+
strokeWeight(20.0)
22+
line(200, 0, width / 2, height)
23+
exit # Quit the program
24+
end
25+
26+
def settings
27+
size(2000, 2000, PDF, data_path('Line.pdf'))
28+
end
29+
end
30+
LargePage.new

library/pdf/many_frames.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'picrate'
2+
3+
class ManyFrames < Processing::App
4+
#
5+
# Saves one PDF document of many frames drawn to the screen.
6+
# Starts the file when the mouse is pressed and end the file
7+
# when the mouse is released.
8+
load_library 'pdf'
9+
include_package 'processing.pdf'
10+
11+
def setup
12+
sketch_title 'Many Frames'
13+
frame_rate(24)
14+
background(255)
15+
end
16+
17+
def draw
18+
stroke(0, 20)
19+
stroke_weight(20.0)
20+
line(mouse_x, 0, width-mouse_y, height)
21+
end
22+
23+
def mouse_pressed
24+
begin_record(PDF, data_path('Lines.pdf'))
25+
background(255)
26+
end
27+
28+
def mouse_released
29+
end_record
30+
background(255)
31+
end
32+
33+
def settings
34+
size(600, 600)
35+
end
36+
end
37+
38+
ManyFrames.new

library/pdf/many_pages.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'picrate'
2+
3+
class ManyPages < Processing::App
4+
#
5+
# Saves a new page into a PDF file each loop through draw().
6+
# Pressing the mouse finishes writing the file and exits the program.
7+
#
8+
load_library 'pdf'
9+
include_package 'processing.pdf'
10+
11+
attr_reader :pdf
12+
13+
def setup
14+
sketch_title 'Many Pages'
15+
frame_rate(4)
16+
@pdf = begin_record(PDF, data_path('Lines.pdf'))
17+
begin_record(pdf)
18+
end
19+
20+
def draw
21+
background(255)
22+
stroke(0, 20)
23+
stroke_weight(20.0)
24+
line(mouse_x, 0, width - mouse_y, height)
25+
pdf.nextPage
26+
end
27+
28+
def mouse_pressed
29+
end_record
30+
exit
31+
end
32+
33+
def settings
34+
size(600, 600)
35+
end
36+
end
37+
ManyPages.new

0 commit comments

Comments
 (0)