Hi, I'm working on a poster (static) in which a given text input was transform into characters and placed onto screen with text() function.
The hard part is--I need to detect a specific word(s) in the characters, say "company", and then kind of transform it along z-axis so the word kinda "falls" into the dark behind. The neighboring characters in the radius (both in-lines and the lines above and below) will have to "fall" to follow the word too, sort of like rocks fallen after one trips down the cliff.
So far, I've only come up with a generic drawing of characters. Please look at my code and advise ASAP. Thanks!!
import processing.opengl.*;
String[] lines;
String message;
PFont f;
float posX;
float posY;
int fontSize;
void setup() {
r = 60;
//arclength = 0;
posX = 0;
posY = 10;
fontSize = 20;
lines = loadStrings("anytext.txt");
message = join(lines, " ");
size(650, 650, OPENGL);
background(0);
f = createFont("Arial",fontSize,true);
textFont(f);
textAlign(CENTER);
smooth();
}
void draw() {
// For every box
for (int i = 0; i < message.length(); i++ ) {
// The character and its width
char currentChar = message.charAt(i);
float w = textWidth(currentChar);
posX += w/2;
pushMatrix();
translate(posX, posY);
fill(255, random(50, 200));
text(currentChar,0,0);
// Check to see if the line hits the end of the window
Hi, it's me again Nkjao. I'm working on a photomosaic project, which requires me to divide a source image into grids of 25x25 pixel tiles. Then I average that area of color pixels and return it to fill that tile.
I'm not sure if my code did what I intended, or just simply fill each tile with the color picked up from the center (x, y) of the tile. I copied the convolution function from Daniel Shiffman's book.
Please see my code here:
PImage mao;
int cols = 20;
int rows = 20;
int cellwidth;
int cellheight;
int matrixsize;
float[][] matrix;
void setup() {
size(500, 500);
mao = loadImage("Mao_Bear_MoMA_517x517.png");
matrixsize = 25;
// fill up the convolution matrix
matrix = new float[matrixsize][matrixsize];
for (int i = 0; i < matrixsize; i++) {
for (int j = 0; j < matrixsize; j++) {
matrix[i][j] = 1/matrixsize;
matrix[matrixsize/2][matrixsize/2] = 1; // for no reason, if I comment out this line, I get a dark background.
Now, here is another way I found someone writing the same class:
class MyClass() {
float property1;
float property2;
float property3;
void MyClass() {
}
void init() {
}
void update() {
}
void render() {
}
}
Where is the constructor of the latter class? Is it MyClass() method or init() method? Since we can choose to instantiate an object in any method, not just in the constructor, can I assume that a constructor is in fact just another method in a class exclusively used to create starting objects? And if so, why do I need MyClass() method when I can always use init() method (or any methods for that matter) as a constructor?
With garbage collector I assume there's no way to allocate computer's memory manually in Processing (or Java). This prevents processing software from running heavy-duty. When dealing with numerous generatively created objects, Processing sketches always slow down to an end (crash). Not to mention if a single object has some elaborate details of its own.
In such case, is designing an object as a seperate PGraphic sprite (say, with transparent background) the only way to deal with this matter?
I used the function contactStarted() to add FCircle objects at the point where a glyph "touch" the world's edge or one another. When it does, the FCircle objects keep being created until it crashes, sending message:
AssertionError: Too many pairs (16384 shape AABB overlaps) - this usually means you have too many bodies, or you need to increase Settings.maxPairs.
Here is my code, adapted from Ricard Marxer's
Letters and also using the geomerative library to create the fonts. (a .ttf font file is needed in a data folder for it to work and change the name in red according to the font's name.)
I tried to reset the frameCount and hence setting the FCircle objects' lifetime and remove them after but it didn't work.
Hi there, it's me again Nokjao! Today I wanna ask a simple questions:
How to loop all (or partial) characters from my computer system into an array without explicitly typing all of them into a bracket or into an external text editor?
As a non-programmer playing around with Processing for less than a year, I find most of you here highly experienced and discussing/asking about complicated stuff. It is great because I always get cool advices from you guys, but it would be nice if there is a dedicated forum just for starters to exchange ideas and, well, for the sake of not feeling lonely. Just an idea.
I have tried several ways to prototype an Invader object which basically needs to update itself in two recursive actions. Let me describe it in this diagram:
Yes, what came to my mind was 2D array! So I assigned each cell a boolean variable and a startup value. It all went fine, and I was able to draw the first (static) frame, but had no idea how to update and animate the second frame.
And here is my code. I address the problems in red letters:
Bit[][] bitsy; int cols = 11; int rows = 11; boolean a = true; boolean b = true; boolean c = false; boolean d = false; boolean[][] grid = { {d,d,d,d,d,d,d,d,d,d,d}, {d,d,b,d,d,d,d,d,b,d,d}, {c,d,d,b,d,d,d,b,d,d,c}, {c,d,b,b,b,b,b,b,b,d,c}, {c,b,b,d,b,b,b,d,b,b,c}, {b,b,b,b,b,b,b,b,b,b,b}, {a,b,b,b,b,b,b,b,b,b,a}, {a,d,b,a,a,a,a,a,b,d,a}, {a,c,a,d,d,d,d,d,a,c,a}, {d,d,d,a,a,d,a,a,d,d,d}, {d,d,d,d,d,d,d,d,d,d,d} };
void setup() { size(110, 110); background(125); smooth(); bitsy = new Bit[cols][rows]; // Initialize each object for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { bitsy[j][i] = new Bit(); // bitsy[i][j] = new Bit(); will result in a 90-degree rotated image } } }
void draw() { a = false; c = true; background(125); for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { if (grid[j][i] == true) { bitsy[j][i].display(i*10, j*10, 10, 10, #FFFF00); // bitsy[i][j] will result in 90-degree rotated image } } } }
class Bit { float x, y; // x, y location float w, h; // width and height color c; // fill color Bit() {} void display(float xp, float yp, float wt, float ht, color ct) { x = xp; y = yp; w = wt; h = ht; c = ct; noStroke(); fill(c); rect(x, y, w, h); }
Questions:
1. At the point where I assign a boolean 2D array named grid. Could you pls suggest a tidier way of assigning values (in this case, selectively) to a 2D array without doing it in one-go, matrix style like that? (A more algorithmic way, whether through subset(), append(), splice() or other array methods)
2. When I go through a for loop to assign objects to array, int i is a counter variable for cols, and int j for rows. But when I go bitsy[i][j]....I got a 90-degree rotation.
3. Lastly, please advice how to add an update method so that the frame two play in draw() and loop over and over. Thanks a whole lot.
I am just another designer getting up to speed with computing, and here is another question I need to know for the sake of advancing further.
Considering a super-simple class:
class Simple {
// param float x, y; color c; float d;
// ctor Simple(float tempX, float tempY, color tempC, float tempD) { x = tempX; y = tempY; c = tempC; d = tempD; }
// methods void setMe() {}
void move() {}
void update() {} }
Main Question: I noticed that in many cases, I do not need a constructor at all (blank ctor), since I can "construct" an object from a method (i.e. setMe() ). Can I assume that constructors are a kind of in-built overloaded methods to "construct" any first instance of a class?
void setMe(float tempX, float tempY, color tempC, float tempD) { x = tempX; y = tempY; c = tempC; d = tempD; }
A Bonus Question: I don't mean to sound like Neo (the Matrix) but "Is everything a method afterall?" I mean, looking at programming in a naive way of mine, everything looks more or less a class, say a so-called library is a class composed of many pre-built functions and methods, and so is the Processing IDE I am using. Can I look at it that way?
Currently, I have been editing the editor's font in the preference.txt. My current setting is:
editor.font=Courier New,Regular,13
Well, the editor font isn't really Courier New.
So, I'd like to know how I can restore to the default preference (everything including editor font) and also how to make set the editor's font correctly.
void draw() { for (int i = 0; i < 20; i++) { drawLine(int(random(width)), int(random(height)), int(random(7)), int(random(255))); } }
drawLine() is a function for drawing a line. I'm just wondering why once in this for() Loop it draws
20 random lines in correspondence to the i variable in the loop, since I see no relationship between the int i and the function at all. (The i variable is not operated or even visible in any way in the argument of the function)
// Hi y'all, it's me Nokjao again. Please take a look at my code here:
//// The code starts here ////
GumBall[] balls = new GumBall[100];
void setup() { size(480, 480); smooth(); colorMode(RGB); randomSeed(2); for (int i = 0; i < balls.length; i++) { float x = random(width); float y = random(height); float d = random(10, width/3); color c = color(random(0, 255), random(40, 255), random(70, 255), random(30, 100)); balls[i] = new GumBall(x, y, d, c); } }
void draw() { background(255); for (int i = 0; i < balls.length; i++) { balls[i].display(); balls[i].jitter(); balls[i].scatter(); } }
//// class GumBall ////
class GumBall { float x; float y; float d; float homeX; float homeY; color c; float linger = 0.4; float speed = 3; Fur furs = new Fur(x, y, d, c); GumBall(float xi, float yi, float di, color ci) { x = homeX = xi; y = homeY = yi; d = di; c = ci; furs.start(); } void display() { noStroke(); fill(c); ellipseMode(CENTER); ellipse(x, y, d, d); fill(alpha(c)); ellipse(x, y, d/75, d/75); } void jitter() { if ((mouseX < x+100) && (mouseX > x-100)) { if ((mouseY < y+100) && (mouseY > y-100)) { x += (noise(-speed, speed))*3; y += (noise(-speed, speed))*3; } } else { x += random(-linger, linger); y += random(-linger, linger); } } void scatter() { float easing = 0.05; float targetX = x; float targetY = y; if (mousePressed) { x += (targetX - (random(-d, width+d))) * easing; y += (targetY - (random(-d, height+d))) * easing; } else { float easingBack = 0.08; x += (homeX - x) * easingBack; y += (homeY - y) * easingBack; } } }
//// subclass Fur, which inherits GumBall ////
class Fur extends GumBall { // Constructor for Fur class inheriting variables from GumBall superclass Fur(float x, float y, float d, color c) { super(x, y, d, c); } void start() { strokeWeight(0); stroke(alpha(c)); pushMatrix(); translate(x, y); for (int deg = 0; deg < 360; deg += 10) { line(0, 0, cos(radians(deg)) * (d/2), sin(radians(deg)) * (d/2)); } popMatrix(); } }
/*
What I'm trying to do here is to "embed" the Fur objects inside the GumBall objects so that when GumBall objects
are called, the Fur objects are contained inside them and inherit their behaviors (or methods).
I've tried several methods and in one method the processing rendered erratically, while with this code it just did not run at all with the following error message:
"StackOverflowError: This sketch is attempting too many recursions"
I'm coding a bunch of Pacmen which are supposed to "munch" while bouncing back and forth in the display window. The problem is most of them munch way to fast, while a few munch slower to very slow. Here's my code:
// Code starts here
Pacman[] pac = new Pacman[50];
void setup() {
size(400, 200);
smooth();
for(int i = 0; i < pac.length; i++) {
pac[i] = new Pacman();
}
}
void draw() {
background(0);
for(int i = 0; i < pac.length; i++) {
pac[i].display();
pac[i].go();
pac[i].munch();
}
}
// Pacman class block starts here
class Pacman {
float x;
float y;
float radius;
float speed;
color col;
int direction;
Pacman() {
radius = random(10, 30);
x = random(radius, width-radius);
y = random(height);
speed = random(1.0, 4.0);
colorMode(HSB, 360, 100, 100);
col = color(random(20, 120), 100, random(80, 100));
direction = 1;
}
void go() {
x += speed * direction;
if ((x > width - radius) || (x < radius)) {
direction = -direction;
}
}
// I know the problem lies in here, just what did I miss?
void munch() {
int n = int(x);
// Cast float x to int n if (direction == 1) {
// If pacman is going to the right, if (n%2 == 0) {
// and that n%2 is 0, ellipse(x, y, radius, radius);
// draw a pacman with mouth closed }
else {
arc(x, y, radius, radius, radians(35), radians(325));
// Else, draw a pacman with mouth open to the right. }
}
if (direction == -1) {
// If pacman is going back to the left, if (n%2 == 0) {
// and that n%2 == 0, ellipse(x, y, radius, radius);
// draw a pacman with mouth closed. }
else {
arc(x, y, radius, radius, radians(215), radians(505));
// Else, draw a pacman with mouth open to the left. }
}
}
}
// This code ends here
Your kind help would be very much appreciated! Thanks in advance.
I created the font using Helvetica-Bold-48 type. When run, the time display hour:minute:second and follows mouseX and mouseY loosely with easing, but the time does not "tick". It just freezes like a normal line of typefaces.