wanna create an always on top fixed position ellipse with createGraphics without being scrolled out of screen, tried position(0,0,'fixed'); but doesn’t work, code below, ideas? thanks.
let dot;
function setup() {
createCanvas(400, 2000);
dot = createGraphics(50,50);
dot.position(0,0);
}
function draw() {
background(220);
dotDisplay();
}
function dotDisplay(){
dot.background(0,255);
fill(255);
dot.ellipse(25,25,50, 50);
image(dot,0,0,50, 50);
dot.position('fixed');
}
Hi @juju
Not sure what you mean by “scrolled out of screen”, but with a canvas height o 2000, it’s very likely that your browser window has to be scrolled. The PGraphics is fixed to the canvas.
I created height of 2000 on purpose to demonstrate when scroll bar appears, I want that PGraphics to always stay at the same position without being affected by the scroll bar.
Thanks for the reply. What if it’s like the animation below? How can I make the dot stay?
let clockAlpha;
function setup() {
createCanvas(400, 2000);
}
function draw() {
background(220);
timeDotDisplay();
}
function timeDotDisplay(){
let s = second();
if (s % 2 === 0) {
clockAlpha = 0;
}
if (s % 2 != 0) {
clockAlpha = 255;
}
fill(0, clockAlpha);
noStroke();
ellipse(25, 100, 50);
}
}
Hi GoToLoop, thanks for pointing the direction. I managed to make the dot stay, but the fill(), noStroke() & flashing animation like the sketch above doesn’t seem to work, any idea? and it seems if I use image() after dot.ellipse(), there will be two circles. Does that mean I can use createGraphics() without using image() to display the ellipse in this case? Thanks.
let dot;
let clockAlpha;
function setup() {
createCanvas(400, 2000);
dot = createGraphics(50,50);
dot.style('display', 'none');
dot.show();
dot.position(0,0,'fixed');
}
function draw() {
background(220);
dotDisplay();
}
function dotDisplay(){
let s = second();
if (s % 2 === 0) {
clockAlpha = 0;
}
if (s % 2 != 0) {
clockAlpha = 255;
}
noStroke();
fill(0, clockAlpha);
dot.ellipse(25,25,50);
// image(dot,0,0,50, 50);
}
Aww! Got it thank you. I feel like switching from Processing to P5 is just like learning another language … it’s all over again… glad this community exists.
One last question, the clockAlpha only works as the first argument in fill() but not the second (as alpha) I checked the log it’s switching between 255 and 0 no problem, know why?
let dot;
let clockAlpha;
function setup() {
createCanvas(400, 2000);
dot = createGraphics(50,50);
dot.style('display', 'none');
dot.show();
dot.position(0,0,'fixed');
}
function draw() {
background(255);
dotDisplay();
}
function dotDisplay(){
let s = second();
if (s % 2 === 0) {
clockAlpha = 0;
}
if (s % 2 != 0) {
clockAlpha = 255;
}
dot.noStroke();
dot.fill(0, clockAlpha); // not working
// dot.fill(clockAlpha); // works
dot.ellipse(25,25,50);
console.log(clockAlpha);
}
Same for me. I’ve fiddled around with Processing.java for some years now, but only recently with P5.js
Although as a library the functions and structure seem similar, they are as language completely different. My posted answer was clearly wrong and I deleted it. But still, as an exercise, I’m trying to do it in html and css.
In this code, the text is fixed, but I would like to link it the same way to an image.
Any idea?