pw00
December 7, 2019, 12:26pm
1
I’m trying make it seem like a certain portion of an image “rots” (by using tint) after a certain time to show the decomposition rates of different types of recyclables and what not, but I can’t seem to find any tutorials or anything on the reference pages to get me started. So what I’m asking is 1) Is it even possible to do that in Processing? and 2) If so, how do you do it?
Also p.s. I’m going to use millis to time events since seconds just feels a little too long for me.
1 Like
pw00:
after a certain time
use a timer using millis() (see reference)
glv
December 7, 2019, 1:44pm
3
A very quick and simple example I whipped up from scratch that may help:
int timeZero;
int timeNow;
int alpha = 0;
int sec;
void setup()
{
size(500, 500);
timeZero = millis();
}
void draw()
{
background(0);
timeNow = millis();
if (timeNow > (timeZero + 2000) && timeNow < (timeZero + 2000 + 4251))
{
// Do something cool here like change tint or alpha for a shape or just count!
stroke(255, 0, 0);
strokeWeight(2);
line(0, 0, alpha, alpha);
alpha++;
if (alpha >= 255) alpha = 255;
println(alpha);
}
if (timeNow > 2000 + 4250)
{
strokeWeight(2);
fill(255, 255, 0, alpha);
circle(width/2, height/2, 50);
}
}
Can you tell me why I chose 4251 as my time offset?
2 Likes
noel
December 7, 2019, 1:56pm
4
Or if you want like you said use tint.
PImage pi1, pi2;
int tnt = 255;
int start_time;
void setup() {
size(500, 500);
background(255);
stroke(255, 0, 0);
strokeWeight(20);
fill(0, 0, 255);
ellipse(250, 250, 400, 400);
pi1 = get(0, 0, width, height);
image(pi1, 0, 0);
pi2 = get(0, 0, width/2, height/2);
start_time = millis();
noStroke();
fill(255);
}
void draw() {
if (millis()-start_time > 200) {
tint(255, 255);
image(pi1, 0, 0);
rect(0, 0, width/2, height/2);
tint(255, tnt);
image(pi2, 0, 0);
tnt -= 20;
start_time = millis();
}
}
1 Like
noel
December 7, 2019, 2:05pm
5
Does circle still work on PC?
noel
December 7, 2019, 2:14pm
6
Good one, I had to think about it.
1 Like
Lexyth
December 7, 2019, 2:15pm
7
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
This file has been truncated. show original
Line 12298. (Took a looong time to find that…)
Edit… i still can‘t figure it out… i even googled the numbers …
glv
December 7, 2019, 2:39pm
8
Yes it does.
On this page:
Processing is open source and is available for macOS, Windows, and Linux. Projects created with Processing are also cross-platform, and can be used on macOS, Windows, Android, Raspberry Pi, and many o…
in the “list of revisions”:
1 Like
noel
December 7, 2019, 3:28pm
9
I had to ask. What are you looking for in this file?
Lexyth
December 7, 2019, 4:03pm
10
No, i meant i still didn‘t figure out the 4251… as for the file, that‘s where the Circle method is in the PApplet. Idk how to do a link that directly goes to the line as for why it took a Long Time, cause “search on Page” doesn‘t find anything in the PApplet… it‘s just way too long…
noel
December 7, 2019, 4:14pm
11
Ah, I see… I think you are looking too far, it’s not that difficult, it’s just about cycles.