We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all Is it possible to update the screen only when an event occurs (like a key is pressed), instead of at a specified framerate?
You can use noLoop() and then redraw()
noLoop()
redraw()
PVector pos; void setup() { size(300, 300); pos = new PVector(random(width), random(height)); background(255); // no loop ... noLoop(); } void draw() { //if looping color would change each frame, but not : ) fill(color(random(255))); rect(width/2, height/2, 40, 40); fill(200, 30, 200); ellipse( pos.x, pos.y, 30, 30); // frame we currently are frame.setTitle(nf(frameCount,4)); } void keyPressed() { pos = new PVector(random(width), random(height)); background(255); // draw once again... redraw(); }
A big bunch of online examples which uses noLoop() & redraw() couple in order to react only when an event triggers:
http://studio.processingtogether.com/sp/pad/export/ro.9jCT0UHalHCI3/latest http://studio.processingtogether.com/sp/pad/export/ro.9eDRvB4LRmLrr/latest http://studio.processingtogether.com/sp/pad/export/ro.9ozYNbweyOpjT/latest http://studio.processingtogether.com/sp/pad/export/ro.9PDcp7xMBknWz/latest http://studio.processingtogether.com/sp/pad/export/ro.9ZSvPnI4AVjwR/latest http://studio.processingtogether.com/sp/pad/export/ro.9L5jAtga7SpyF/latest http://studio.processingtogether.com/sp/pad/export/ro.9sMuvRRTXcVG-/latest http://studio.processingtogether.com/sp/pad/export/ro.9c9DCUznTwot6/latest http://studio.processingtogether.com/sp/pad/export/ro.9Iaf6privOouM/latest http://studio.processingtogether.com/sp/pad/export/ro.9WgKFjA6WFscW/latest
Answers
You can use
noLoop()
and thenredraw()
A big bunch of online examples which uses noLoop() & redraw() couple in order to react only when an event triggers:
http://studio.processingtogether.com/sp/pad/export/ro.9jCT0UHalHCI3/latest
http://studio.processingtogether.com/sp/pad/export/ro.9eDRvB4LRmLrr/latest
http://studio.processingtogether.com/sp/pad/export/ro.9ozYNbweyOpjT/latest
http://studio.processingtogether.com/sp/pad/export/ro.9PDcp7xMBknWz/latest
http://studio.processingtogether.com/sp/pad/export/ro.9ZSvPnI4AVjwR/latest
http://studio.processingtogether.com/sp/pad/export/ro.9L5jAtga7SpyF/latest
http://studio.processingtogether.com/sp/pad/export/ro.9sMuvRRTXcVG-/latest
http://studio.processingtogether.com/sp/pad/export/ro.9c9DCUznTwot6/latest
http://studio.processingtogether.com/sp/pad/export/ro.9Iaf6privOouM/latest
http://studio.processingtogether.com/sp/pad/export/ro.9WgKFjA6WFscW/latest