-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurbanumintro.pde
131 lines (106 loc) · 3.2 KB
/
urbanumintro.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
PImage img;
ArrayList<Text> texts = new ArrayList<Text>();
ArrayList<Image> images = new ArrayList<Image>();
int margin = 0;
void setup() {
String path = sketchPath;
String[] filenames = listFileNames(path + "/img");
println(filenames);
size(1024, 768);
// Create the font
textFont(createFont("Georgia", 36));
// The image file must be in the data folder of the current sketch
// to load successfully
texts.add(new Text("När Bohuslän tillhörde Norge och Halland tillhörde Danmark var Göta älv Sveriges väg väster ut i Europa för varor och krigsskepp. Vid älven behövs en stad. Först byggs Gamla Lödöse vid Lilla Edet. Sedan kom Nya Lödöse, där stadsdelen Gamlestan ligger i dag.", new PVector(width/2, height/2), 14));
texts.add(new Text("Fire", new PVector(50, 50), 14));
for (int i = 0; i < filenames.length; i++) {
//loadImage("/img/"+filenames[i]);
images.add(new Image("/img/"+filenames[i], new PVector(random(1024), random(200))));
}
strokeWeight(100);
stroke(0, 0, 255);
noFill();
}
int count = 0;
void draw() {
background(255);
// Displays the image at its actual size at point (0,0)
//image(img, 0, 0);
// Displays the image at point (0, height/2) at half of its size
//image(img, 0, height/2, img.width/2, img.height/2);
for (Image im : images)
{
image(im.img, im.location.x, im.location.y, width-im.location.x, im.img.width/im.img.height * (width-im.location.x));
im.location.x += im.direction.x;
im.location.y += im.direction.y;
if (im.location.x < 0 - margin)
im.location.x = width + margin;
if (im.location.x > width + margin)
im.location.x = 0 - margin;
if (im.location.y < 0 - margin)
im.location.y = height + margin;
if (im.location.y > height + margin)
im.location.y = 0 - margin;
}
for (Text t : texts)
{
textSize(t.size);
fill(0);
text(t.text, t.location.x, t.location.y);
t.location.x += t.direction.x;
t.location.y += t.direction.y;
if (t.location.x < 0 - margin)
t.location.x = width + margin;
if (t.location.x > width + margin)
t.location.x = 0 - margin;
if (t.location.y < 0 - margin)
t.location.y = height + margin;
if (t.location.y > height + margin)
t.location.y = 0 - margin;
}
text(count, 10, 10);
text(frameRate, 10, 30);
count++;
count = count % 360;
}
class Image
{
PVector location;
PVector size;
PVector direction;
PImage img;
Image(String filename, PVector startLocation)
{
println("Loading image: "+filename);
img = loadImage(filename);
location = startLocation;
float angle = random(TWO_PI);
angle = 0;
direction = new PVector(cos(angle), sin(angle));
}
}
class Text
{
String text;
PVector location;
int size;
PVector direction;
Text(String string, PVector startLocation, int startSize)
{
text = string;
location = startLocation;
size = startSize;
float angle = random(TWO_PI);
direction = new PVector(cos(angle), sin(angle));
}
}
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
} else {
// If it's not a directory
return null;
}
}