We are about to switch to a new forum software. Until then we have removed the registration on this forum.
//I'm currently trying to create a typeface which will change when using a weighing scale. Right now, I've created the basis for what I believe will work and I'm using mouseY to simulate the use of a weighing scale. But of course, when it's in KeyReleased it doesn't change as key release practically snapshots it. What is the method for getting around this? Many thanks!
void setup(){
size(600,650);
}
void draw(){
fill(0,0,0);
}
void keyReleased(){
//LETTERS
if(key == 'a' || key == 'A'){
//X1
ellipse(200,200,mouseY,mouseY);
}else{
//nothing
}
}
Answers
Can you please post a shorter example? All you really need is a single ellipse to show what you're having trouble with, right?
Apologies,
Above is the more basic example of the code. I'd like the mouseY to still work once the keys been pressed.
Thank you!
Please edit your post to fix your formatting by highlighting your code and pressing the code button.
What do you mean when you want the
mouseY
to still work? What exactly do you expect this code to do? What does it do instead?I'd like the ellipse to be able to grow and shrink using the mouseY value in real time. I'm hoping this will lead me to eventually linking a load cell and an Arduino instead.
Heavier the weight, heavier the typeface.
thank you so much for your patients. I only began learning code two weeks ago.
cheers again,
Why do you need the
keyReleased()
function at all here?Create a small sketch that just shows a single ellipse whose size changes based on the mouse position.
Yeah, i've done that. Thats my backup.
The reason for using keyReleased is so the user can type their own words. I understand it's complex but it's something i'd love to try.
Is there not a simple way to allow the ellipse pasted during the keyReleased to continue to change size according to mouseY?
Yeah, split your logic up. Don't put drawing code inside the
keyReleased()
function. Instead, use thekeyReleased()
function to modify some sketch-level variables that you then use inside thedraw()
function.All that’s necessary here has been said already.
Your architecture is wrong.
Draw everything in draw (). Use mouseY here to define S or whatever.
In keyPressed (or keyReleased) just store the key that has been pressed in a variable and use this variable in draw().
I also hope you can use all letters not only a.
I am on a journey and can’t do the sketch here for you.
Essentially move the content from keyReleased into draw
Really struggling to get my head around this as a beginner. If any reader could create an example I'll be very grateful!
Which functions should I research?
Thank you
??
Do what we told you and post your entire example so that we can correct it
Apologies I'm having an off day and struggling with this. Below I've moved the content to draw with ellipses in two different locations for testing, the mouseY works! The issue is when a second key is pressed it erases the previous.
Thank you for being patient with me,
So you wish no erasing, right?
Then you want to display a word or sentence?
Say wordMy = wordMy+key; in the function (!) keyPressed
Before setup say
String wordMy="";
In draw() use a for loop to loop over wordMy, like
text(wordMy.charAt(i), i*72, 120);
or do the ellipses here instead
read tutorials about string etc.
It looks like you might be unfamiliar with the concept of creating variables. You can create a variable outside of your functions so that they're shared between the functions. Modify the variable inside the
keyReleased()
function, and use that variable inside yourdraw()
function.You should also try to be more specific about exactly what you're trying to do. Break your problem down into smaller steps and take those steps on one at a time. Write down exactly what you want to happen, step-by-step, in English. When you have those steps written out, then you can think about implementing some code.
Instead of key (all of it) in your lines above use variable letter
In first line of draw()
char letter=key;
here is a new version that can receive and store multiple keys (a word) and display it - based on your last code above. It can do only a and b (one ellipse or two).
here is a new version that shows the letters of the entire alphabet if you type them
the ellipses of the letter change their size with
mouseY
it's based on my first sketch in your other discussion
https://forum.processing.org/two/discussion/26229/typeface-which-changes-with-a-kitchen-scale-issues
This version is based on the textual star "
*
" images of each letter in the sketch below.It is based on my sketch on github, see link in your other discussion:
https://forum.processing.org/two/discussion/26229/typeface-which-changes-with-a-kitchen-scale-issues
Wow, just looked back at this. Thank you so much Chrisir. Great work.
Sure!
So, thanks to you Chrisir I have more or less completed my project. I have now attached the typeface to an Arduino and a kitchen scale, it works great! (so instead of the mouseY its the weight placed on the scale).
I added code so it drops down a line when it reaches the edge of the page and starts at the top again when it reaches the bottom. Thank you so much for your help. (I didn't use the buffer because I felt the need to use my own longer technique for grade reasons(hence the partial alphabet on here)) I'll continue to play around but I'm ever so grateful.
Thanks for sharing!
Did you do all letters of the alphabet or just a few (the ones you posted) ?
From a programming point of view: you would make an array to hold x,y pairs (PVector) of all points to represent letters and then use a for loop over it.
Maybe I can make an example of what I mean
Yeah, I've designed and coded all the letters, but it went over the number of characters I could post on here so I cut the code down.
Now I'm just trying to track down how to remove keys such as SHIFT from the string so they aren't recognised as a key pressed.
Then I'll make it aesthetic like any good graphic design student.
IN keyPressed()
@AVRG Check the reference for the keywords key and keyCode. They documented how to do that.
Kf
In my
switch
section: you should make all keys to upper case since you don’t distinguish anywayThen in the default section in switch you can use
if(int(key)>65 && int(key)<100)
or whatever to accept only the letters you wanthere is an example for A and B - I also made a function
ellipse
/ellipse2
which is over shadowing the real ellipse to one time use to convert letters to dataI did that for A and B - see data at the end of the sketch. This gets read in.
that can be further improved when you use the input A B as an index for a bigger array containing all single data (instead of
aTable
for A andbTable
for B and so on)Chrisir ;-)
Not sure if ENTER works correctly in my code
Hello,
I made a new version with replacing
aTable
,bTable
... with one huge table namedtable
for all letters of the alphabet.In turn, the whole
if...else if...
-block for each letter can now be reduced very much, since we use the ascii value of each letter as the index fortable
:Of course you could save and load the data which are now in table in data file on the hard drive. You could also write an font editor to design load and save your letters graphically.
regarding ENTER: I modified it, but you did something strange with your x-position
x
of a new line: Initially it was -85 but then it was 100 because you saidx = start;
.Chrisir
Having backspace is awesome, I was trying to get my head around how to do it. I managed to create the ENTER myself and works perfectly.
Thank you so much for all your help. I'll soon upload images of the final working piece with the scale etc. My deadline is tomorrow