I have this code on ContentView
#State var animation: Bool = false
MyControl()
.scaleEffect(animation ? 1.3 : 1)
.animation(Animation.default.repeatCount(4, autoreverses: true))
Later on the code a button toggles the variable animation.
The result is
The end is abrupt and the final state is not the initial.
I want the view to scale up and down fast. Start with scale 1, scales up to 1.3 and back to 1, four times and ends with 1.
How do I do that?
Set autoreverses to false. It will keep the view at its last stopping point .
Related
When I execute the code below in an iPhone Simulator w/Xcode 14, I see double the print statements. I had only expected to see one for each rectangle. The executing code only creates one indigo rectangle unit the available space is filled (7 in all on an iPhone 14 Pro). Am wondering why I get a 2x print statement (unexpected) but only one rect (expected)
ScrollView {
LazyVStack {
ForEach(0..<1000) { i in
let _ = print("Dang \(i)")
Rectangle().fill(.indigo)
.frame(width: 100, height: 100)
}
}
}
.padding()
And here's what the output to the console looks like:
Dang 0
Dang 0
Dang 1
Dang 1
...
Dang 6
Dang 6
Also - curiously, if I change the LazyVStack to just a VStack, then I see one line for each Rectangle created (1000 Dangs, which is expected). Not sure why I see the double with the LazyVStack.
And more curious - if I use a LazyVGrid rather than LazyVStack, I only see one print statement, as expected. Is this a bug or is there something happening with statement execution that I'm not understanding.
I want to draw a specific curve line to Photoshop or to mspaint. This drawing action should be saved for the possibility to redraw that curve in the exact same way. How can I do it with Autoit? Is there a recording and play mechanism? As far as I read, the AU3 recorder is not available anymore.
Photoshop is just an example. I want to be able to do that kind of drawing record for different purposes and programs. Maybe also for online image editors or something.
I am not that familiar with Autoit yet. I do not expect a full code example, maybe you can give me an idea - that would be very helpful.
Currently I tried a bit with mouse functions like MouseDown, MouseMove etc. and it is quite funny, but i do not really have a concept to record and redraw these mouse actions.
If I have to clarify more please let me know - i will do my best to be precise.
I recommend using two scripts, one for recording and the second to replay recorded actions.
Code for the recording:
; declaration
Global $sFileCoordinates = #ScriptDir & '\RecordedMouseMoveCoordinates.txt'
Global $iRecordingDurationInSeconds = 10
Global $iXSave, $iYSave
; functions
Func _recordMouseMoveCoordinatesToFile()
Local $aPos = MouseGetPos()
If $aPos[0] <> $iXSave Or $aPos[1] <> $iYSave Then
FileWrite($hFile, $aPos[0] & ',' & $aPos[1] & #CRLF)
Local $aPos = MouseGetPos()
$iXSave = $aPos[0]
$iYSave = $aPos[1]
EndIf
Sleep(80)
EndFunc
; processing
Sleep(4000) ; wait 4 seconds to place your mouse to the start position
Global $hFile = FileOpen($sFileCoordinates, 1 + 256)
Global $hTimer = TimerInit()
While Round((TimerDiff($hTimer) / 1000), 1) <= $iRecordingDurationInSeconds
ToolTip(Round((TimerDiff($hTimer) / 1000), 1))
_recordMouseMoveCoordinatesToFile()
WEnd
FileClose($hFile)
Recording will start after a 4 second delay. This should allow to move your mouse to the start point of your drawing action.
Global $iRecordingDurationInSeconds = 10 means your drawing action should be finished in 10 seconds (a tooltip displays remaining seconds). And here the seconds script.
Code to redraw curve:
; declaration
Global $sFileCoordinates = #ScriptDir & '\RecordedMouseMoveCoordinates.txt'
; functions
Func _getFileContent($sFile)
Local $hFile = FileOpen($sFile, 256)
Local $sFileContent = FileRead($hFile)
FileClose($hFile)
Return $sFileContent
EndFunc
Func _drawRecordedMouseMoveCoordinatesFromFile($sContent)
Local $aFileContent = StringSplit($sContent, #CRLF, 1)
Local $iX = StringSplit($aFileContent[1], ',')[1]
Local $iY = StringSplit($aFileContent[1], ',')[2]
MouseMove($iX, $iY, 4)
MouseDown('left')
For $i = 1 To $aFileContent[0] Step 1
If $aFileContent[$i] <> '' Then
Local $iX = StringSplit($aFileContent[$i], ',')[1]
Local $iY = StringSplit($aFileContent[$i], ',')[2]
MouseMove($iX, $iY, 4)
EndIf
Next
MouseUp('left')
EndFunc
; processing
Sleep(2000) ; wait 2 seconds till start
Global $sFileContent = _getFileContent($sFileCoordinates)
_drawRecordedMouseMoveCoordinatesFromFile($sFileContent)
There is a start delay of 2 seconds. All saved coordinates will be executed in the same way recorded. It starts with MouseDown('left'), then the mouse movements to MouseUp('left').
Notice:
This approach isn't really robust because of the coordinates which aren't relative to your window. Please see Opt('MouseCoordMode', 0|1|2) in the help file for more information. If you want to draw more than just one line or curve this approach isn't the best. But as your question describes only that requirement it should be fine.
Can I change the scrollregion on a Python turtle canvas? I want the drawing to move with it, not just the coordinates to shift. The appearance I'm going for is side-scroller like, where the screen's display region moves to center the turtle onscreen.
I've tried using turtle.setworldcoordinates(llx, lly, urx, ury), but, from the documentation, "This performs a screen.reset()". I've also looked at this SO question , but this involves scroll bars, will not center the turtle easily, and has a limited canvas space. What I'm looking for is something that:
Moves the display region to center the turtle
Also moves the drawing
Has an infinite scroll region
does not display scroll bars
can be called quickly with a function
My best guess would be to be able to have an infinite scrolled canvas somehow, then hide the scroll bars and set them according to turtle position.
Is this possible in Python 2.7? I don't mind if it uses tkinter as well.
EDIT: 6-3-15
I found the canvas.xview and canvas.yview functions, but they don't seem to work once I define screen = turtle.TurtleScreen(canvas), and TurtleScreen has no xview or yview functions. I can't seem to make this work.
Then I found turtle.ScrolledCanvas(). This seems ideal except it has no methods for setting scroll manually from the program. Can I set the scroll manually on a turtle.ScrolledCanvas()???
The position of a canvas can be changed without a reset using canvas.place() method. It will move the turtle and the drawings too, so the turtle needs to be relocated after every move.
The next code moves the canvas with Left and Right arrows and draws a circle with Space, while keeping the turtle in the center. No ScrolledCanvas needed, just a very large standard canvas:
import turtle
import Tkinter as tk
def keypress(event):
global xx, canvas, t, speed
ev = event.keysym
if ev == 'Left':
xx += speed
else:
xx -= speed
canvas.place(x=xx)
t.setposition((-canvas.winfo_width() / 4) - (xx + 250), 0)
return None
def drawCircle(_):
global t
t.pendown()
t.fillcolor(0, 0, 1.0)
t.fill(True)
t.circle(100)
t.fill(False)
t.fillcolor(0, 1, 0)
t.penup()
# Set the main window
window = tk.Tk()
window.geometry('500x500')
window.resizable(False, False)
# Create the canvas. Width is larger than window
canvas = turtle.Canvas(window, width=2000, height=500)
xx = -500
canvas.place(x=xx, y=0)
# Bring the turtle
t = turtle.RawTurtle(canvas)
t.shape('turtle') # nicer look
t.speed(0)
t.penup()
t.setposition((-canvas.winfo_width() / 4) - (xx + 250), 0)
# key binding
window.bind('<KeyPress-Left>', keypress)
window.bind('<KeyPress-Right>', keypress)
window.bind('<KeyPress-space>', drawCircle)
drawCircle(None)
speed = 3 # scrolling speed
window.mainloop()
Having a real infinite scrolling would require to redraw every item in the canvas every time with the required offset, instead of actually moving or scrolling the canvas. Functions like create_image() can give the illusion of movement with static backgrounds, but it resets the drawings.
I'm trying to draw machinery from the bird's eye perspective.
Therefore, I draw rectangles. Theese rectangles may have angles (e.g. 90°, 270°). So i apply rotation transformation onto them. This way i can draw the whole plant.
Now if I apply scaling transformation onto the set, the elements are scaling. But the rotation transformations I previously applied, is running backwards.
Copy this to raphael's playground to see what i mean.
var rect1 = paper.rect(50,50,200,100).attr({fill: "green"});
var rect2 = paper.rect(250,50,200,100).attr({fill: "green"});
var rect3 = paper.rect(550,50,200,100).attr({fill: "green"});
rect3.transform("r90,550,50");
var set = paper.set();
set.push(rect1,rect2,rect3);
set.animate({'transform':"S0.5,0.5,50,50"}, 2000);
What I want now, is to prevent reversing the rotation and that the third elements alignment to second one stays as it is after rotation (some kind of "L").
Thanks in advance!
Allright, got it myself. Using "..." solved my problem.
var rect1 = paper.rect(50,50,200,100).attr({fill: "green"});
var rect2 = paper.rect(250,50,200,100).attr({fill: "green"});
var rect3 = paper.rect(550,50,200,100).attr({fill: "green"});
rect3.transform("r90,550,50...");
var set = paper.set();
set.push(rect1,rect2,rect3);
set.animate({'transform':"...S0.5,0.5,50,50"}, 2000);
Tried it this way yesterday, but somehow it didnt work. Today, its working just fine =)
I am try to introduce a Second CursorX at AxisX Primary if this is possible some how?
I did try to activate a second CursorX at Secondary but that one did not work as expected,
I also readed about Line Annotation and Vertical Line Annotation and created some kind of line but a Second set of CursorX CursorY would be far nicer
I did try to create and as much as empty as possible and Transparant Second ChartArea which i try to overlay on top of the ChartArea1, i noticed InnerPlotPosition and Postion of both ChartArea should stay in track to get a full aligned Overlay, and next the CursorX of second ChartArea should be displayed on top of ChartArea1
This is what i think how it could be done but don't have a clue if it sounda for a good way to create a second CursorX maybe Line Annotation is an easier road to rome
Any help suggestion are welcome
Thanks in advance
Suppose your chart contains multiple chart areas aligned vertically, below code allows you set CursorX in each chart area:
Dim c1 As New Chart
'...here code block to build each chart area ...
'...then use below sample code to align each chart area vertically:
'c1.ChartAreas(i).AlignmentOrientation = AreaAlignmentOrientations.Vertical
'c1.ChartAreas(i).AlignWithChartArea = c1.ChartAreas(0).Name
'below set horizontal cursor (it is a gold vertical bar in each chart area):
For Each area As ChartArea In c1.ChartAreas
area.CursorX.LineColor = Color.Gold
area.CursorX.LineWidth = 3
area.CursorX.IsUserEnabled = True
area.CursorX.IsUserSelectionEnabled = True
area.CursorX.SelectionColor = System.Drawing.Color.PaleGoldenrod
Next